Level The Playing Field: Using A Reset Stylesheet
Dec. 22nd, 2008- Posted in: Design, Resources, Tips, Tutorials
- 0 Comments

I’ve discovered as of late that there are a lot of practices that haven’t been adopted by the web community that have been around for quite some time (meaning a year or two in web terms). This is particularly surprising to me in some cases simply because of the sheer usefulness of the practice(s) in question. A lot of this is simply because of ignorance, and I use that term as it was intended, not with any negative connotation. So, to help correct that, I thought I’d churn out a quick post on one of the biggest time-savers: the reset stylesheet.
If you’re unfamiliar with what a reset stylesheet is, the concept is very simple. So simple, in fact, that once you understand it you’ll wonder why we haven’t been using the idea all along. But to understand why a reset stylesheet is so great, there’s a bit of a back story.
A Brief History of Web Browsers and Why They Suck
The web has been, unbeknownst to most people, a fairly brutal battleground since its inception. The W3C has been the determining body for what standards browsers and other content devices should adhere to, and they have been soundly ignored from the beginning. Things really came to a head in the battles between Microsoft and Netscape, with each racing to develop their own proprietary methods that would make developers want to create sites for their browser specifically.
Eventually things calmed down, mostly because of accessibility concerns. However, the fallout from the earlier battles is apparent in that most browsers still have differing methods of rendering data on the screen. Things like forms having extra spacing inside them, input fields having their own font families different from the surround elements, lists with varying levels of padding, etc. This is a huge headache for design and development, to say the least.
Ok, so what is it?
A reset stylesheet is a specialized CSS file, or a collection of CSS definitions, that override all default styling provided by a browser for HTML tags with a visual output. The practical result of such a sheet is that it removes the ambiguity in display, telling all browsers that this has these types of margins and that has this type of padding.
Exactly what a particular reset stylesheet does is, obviously, based on its contents. Different stylesheets have been developed with varying degrees of specificity as to what styling they apply. The stlyesheet that I’ve found to work best for most situations has been one developed by CSS guru, Eric Meyer. I’ve made a few modifications to his stylesheet and added a few other items:
Download the stylesheet listed below here: Reset Stylesheet (save as…)
html, body, div, span, applet, object, iframe,blockquote, pre,a, abbr, acronym, address, big, cite, code,del, dfn, em, font, img, ins, kbd, q, s, samp,small, strike, strong, sub, sup, tt, var,dl, dt, dd, ol, ul, li,fieldset, form, label, legend,table, caption, tbody, tfoot, thead, tr, th, td {margin: 0;padding: 0;border: 0;outline: 0;font-weight: inherit;font-style: inherit;font-size: 100%;font-family: inherit;vertical-align: baseline;}/* remember to define focus styles! */:focus {outline: 0;}body {line-height: 1;color: black;background: white;/* opacity: .99; text-rendering bug in Fx2/Mac --- doesn't validate */}h1, h2, h3, h4, h5, h6 {margin: 10px 10px 10px 5px;padding: 0;}p {margin: 5px;padding: 0;}ol, ul {list-style: none;}/* tables still need 'cellspacing="0"' in the markup */table {border-collapse: separate;border-spacing: 0;}caption, th, td {text-align: left;font-weight: normal;}blockquote:before, blockquote:after,q:before, q:after {content: "";}blockquote, q {quotes: "" "";}/* CLEAFIX */.clearfix:after {content: ".";display: block;height: 0;clear: both;visibility: hidden;}.clearfix {display: inline-block;}/* Hides from IE-mac \*/* html .clearfix {height: 1%;}.clearfix {display: block;}/* End hide from IE-mac */.clearer {clear: both;}
It’s a bit lengthy, but still a very small overall file as far as size is concerned. It can obviously be condensed and is presented in its current format for readability. The notable changes that I’ve made to Eric’s base stylesheet have been the addition of the “clearfix” methodology (as described at Webtoolkit) to the bottom, as well as a utility clearing class that I found myself using in nearly every site.
Briefly, what the above code does:
- The
<html> <body> <div> <span> <form> <ul> <ol>and other tags are all specifically told to have no margins, no padding, no borders, no outlines, and to inherit their font settings from their parent elements. - The
<body>is given a defaultcolorattribute ofblackand a defaultbackgroundcolor ofwhite, so you don’t have to set these every time you make a new site. - Headings and paragraphs are given a specified set of margins and zero padding.
- List items are set to show no bullet or other notation by default (especially useful since most lists tend to end up as navigation or with custom styling).
- For browsers with better support of CSS2 & 3 standards, other things like defining a default focus state for form elements are added as well.
- The clearfix code snippets allow the application of a
clearfixclass to any element, resulting in that element clearing itself after all floated elements inside it (extremely useful). - The utility
clearerclass can be applied to any element, causing it to clear any floats above it.
And that’s basically it. Here are some important tips and directions:
- Include your reset stylesheet above all other stylesheets. People tend to forget that HTML is read in a procedural manner, and if your reset stylesheet is placed below all other stylesheets, it’s styling will take precendence over the other CSS definitions. “Thou shalt not have other stylesheets before me.”
- To make your life less of a hassle, always include your reset stylesheet from the very start of your design/development. Trying to add a reset stylesheet after the fact can sometimes be more of a headache than starting from scratch.
- Recycle! Save your reset stylesheet code as a snippet or simply as a file located somewhere that you can easily copy and paste into any new projects you begin to work on.
Thanks to all those people who have developed this idea long before I got hold of it, because it has saved me a ton of time and headache. Enjoy!
Image credit: sumeja