Zero out padding and margin of all elements on a page

January 17, 2007

This is a helpful CSS trick to use when creating pixel-perfect layouts. Start with a global white space reset – this rule zeros out the padding and margin of every single element on the page. After adding this rule, you must specify margins and padding for each element in the layout unless you want them to remain at zero.

* {
margin: 0;
padding: 0;
}

Avoid (or use caution when) applying this rule to pages that contain forms as it may interfere with usability.