The spacing issues arise from the default margin of 8px applied to the body
element, a common setting present in both CSS 2.1 and HTML5 CR specifications.
To address this, you can easily reset the horizontal margins for the body
:
body { margin-left: 0; margin-right: 0 }
While more comprehensive approaches like "CSS resets" exist, they may introduce unexpected layout changes and offer no additional benefit compared to simply adjusting the body
properties.
Removing these margins will cause text to reach all edges, potentially creating unwanted interactions. To seamlessly extend your horizontal rule without impacting other elements, consider applying negative margins. It's advisable to explicitly define the body
margins as a precaution against variations in browser interpretation:
body { margin: 8px }
hr { margin-left: -8px; margin-right: 8px }