1. Home
  2. Computing & Technology
  3. Web Design / HTML

Use CSS to Zero Out Your Margins and Borders for Consistent Results in Browsers

CSS Margins, Padding, and Borders Make a Consistent Page

By Jennifer Kyrnin, About.com

Most Web browsers have different default settings for the base margins and padding. This means that if you don't set a margin and padding on your body and html tags, you could get inconsistent results on the page depending upon which browser you're using to view the page.

The best way to solve this is to set all the margins and paddings on the html and body tags to 0:
html, body {
  margin: 0px;
  padding: 0px;
}

This will start your design in the same place on all browsers.

Borders

You may be thinking "but no browsers have a border around the body element by default". This is not strictly true. Internet Explorer has a transparent or invisible border around elements. Unless you set the border to 0, that border will mess up your page layouts. So add the following to your body and html styles:
html, body {
  margin: 0px;
  padding: 0px;
  border: 0px;
}

More Web Design / HTML Quick Tips

Explore Web Design / HTML

More from About.com

  1. Home
  2. Computing & Technology
  3. Web Design / HTML

©2008 About.com, a part of The New York Times Company.

All rights reserved.