11 · 30

Removing browser padding!

Both Internet Explorer and Netscape Communicator introduce padding between their edges and contents. Padding is the blank space between the inside edge of the browser window and the actual web page contents. This padding can range from 10 to 12 pixels depending on the browser, platform and version. Here we'll look at a simple HTML trick to remove the padding around web page contents. You would have noticed that this page however, has no such padding and the contents are placed flush against the edges. You can remove the padding either by using frames or using specific attributes to <body> tag and style sheets. This web site employs the latter method. To remove padding you include four attributes in the body tag as: <body marginwidth="0" marginheight="0 leftmargin="0" topmargin="0"> Netscape uses marginwidth and marginheight while Internet Explorer uses leftmargin and topmargin. Since we have set all these attributes to 0, the web page will be displayed without any padding. Internet Explorer follows style sheets better than Netscape. Thus, we can do away with the I.E. specific attributes (leftmargin and topmargin) in the BODY tag by using the margin property in style sheets. body {margin:0} Note: we have set the margin property to 0 and assigned it to the body selector. This style is placed inside the HTML head between <style> - </style> tags or in an external .css file. Since I.E. recognizes this style, we no longer need leftmargin and topmargin and can remove them from the <body> tag. The final document should look like: <html> <head> <title>Some title</title> <style> body {margin:0} <style> </head> <body marginwidth="0" marginheight="0"> ... Contents ... </body> </html>
About the Author Kyle Reddoch is a Web Expert and Internet Guru located in Amarillo, TX. To learn more about him, go to his website at KyleReddoch.com.