Elminating Default Page Margins
By George Chiang
Posted Friday, February 6, 2004
Since the inception of the very first HTML document, margins existed that surrounded the document, like in the case with this document. The margins are there to act as a cushion between the edges of the browser and the contents of the page, so it's easier to read this content. As good as margins are, wouldn't it be nice to be able to eliminate them in some cases, where the design of the page calls for their termination? While most developers think it's not possible to "flush out" the default margins of a HTML document, it actually is, although only possible in IE 3+, and NS 4+. In this tutorial, I'll show you how.
-Eliminating the document margin in IE 3+
To get rid of the document margin in IE 3 and above, so content presses right against the edges of the browser, use the IE exclusive "leftmargin" and "topmargin" attributes:
<body leftmargin="0" topmargin="0">
It's as simple as that!
-Eliminating the document margin in NS 4+
To get rid of the document margin in NS 4 and above, use the NS 4 exclusive "marginwidth" and "marginheight" attributes instead:
<body marginwidth="0" marginheight="0">
-Putting it all together
By putting the two techniques together, we can create a document that flushes out its' margins in both IE 3+ and NS 4+:
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
Try out the above declaration on your page, and you'll see what I mean.