About normalize.css

Normalize.css is a small CSS file that provides better cross-browser consistency in the default styling of HTML elements. It’s a modern, HTML5-ready, alternative to the traditional CSS reset.

Normalize.css is currently used in some form by Twitter Bootstrap, HTML5 Boilerplate, GOV.UK, Rdio, CSS Tricks, and many other frameworks, toolkits, and sites.

Overview

Normalize.css is an alternative to CSS resets. The project is the product of 100′s of hours of extensive research by @necolas and @jon_neal on the differences between default browser styles.

The aims of normalize.css are as follows:

  • Preserve useful browser defaults rather than erasing them.
  • Normalize styles for a wide range of HTML elements.
  • Correct bugs and common browser inconsistencies.
  • Improve usability with subtle improvements.
  • Explain the code using comments and detailed documentation.

It supports a wide range of browsers (including mobile browsers) and includes CSS that normalizes HTML5 elements, typography, lists, embedded content, forms, and tables.

Despite the project being based on the principle of normalization, it uses pragmatic defaults where they are preferable.

Normalize vs Reset

It’s worth understanding in greater detail how normalize.css differs from traditional CSS resets.

Normalize.css preserves useful defaults

Resets impose a homogenous visual style by flattening the default styles for almost all elements. In contrast, normalize.css retains many useful default browser styles. This means that you don’t have to redeclare styles for all the common typographic elements.

When an element has different default styles in different browsers, normalize.css aims to make those styles consistent and in line with modern standards when possible.

Normalize.css corrects common bugs

It fixes common desktop and mobile browser bugs that are out of scope for resets. This includes display settings for HTML5 elements, correcting font-size for preformatted text, SVG overflow in IE9, and many form-related bugs across browsers and operating systems.

For example, this is how normalize.css makes the new HTML5 search input type cross-browser consistent and stylable:

/*
 * 1. Addresses appearance set to searchfield in S5, Chrome
 * 2. Addresses box-sizing set to border-box in S5, Chrome (include -moz to future-proof)
 */

input[type="search"] {
    -webkit-appearance: textfield; /* 1 */
    -moz-box-sizing: content-box;
    -webkit-box-sizing: content-box; /* 2 */
    box-sizing: content-box;
}

/*
 * Removes inner padding and search cancel button in S5, Chrome on OS X
 */

input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button {
    -webkit-appearance: none;
}

Resets often fail to bring browsers to a level starting point with regards to how an element is rendered. This is particularly true of forms – an area where normalize.css can provide some significant assistance.

Normalize.css doesn’t clutter your debugging tools

A common irritation when using resets is the large inheritance chain that is displayed in browser CSS debugging tools.

A common sight in browser debugging tools when using a CSS reset

This is not such an issue with normalize.css because of the targeted styles and the conservative use of multiple selectors in rulesets.

Normalize.css is modular

The project is broken down into relatively independent sections, making it easy for you to see exactly which elements need specific styles. Furthermore, it gives you the potential to remove sections (e.g., the form normalizations) if you know they will never be needed by your website.

Normalize.css has extensive documentation

The normalize.css code is based on detailed cross-browser research and methodical testing. The file is heavily documented inline and further expanded upon in the GitHub Wiki. This means that you can find out what each line of code is doing, why it was included, what the differences are between browsers, and more easily run your own tests.

The project aims to help educate people on how browsers render elements by default, and make it easier for them to be involved in submitting improvements.

How to use normalize.css

First, download normalize.css from GitHub. There are then 2 main ways to make use of it.

Approach 1: use normalize.css as a starting point for your own project’s base CSS, customising the values to match the design’s requirements.

Approach 2: include normalize.css untouched and build upon it, overriding the defaults later in your CSS if necessary.

Closing comments

Normalize.css is significantly different in scope and execution to CSS resets. It’s worth trying it out to see if it fits with your development approach and preferences.

The project is developed in the open on GitHub. Anyone can report issues and submit patches. The full history of the project is available for anyone to see, and the context and reasoning for all changes can be found in the commit messages and the issue threads.

Related reading

Detailed information on default UA styles: WHATWG suggestions for rendering HTML documents, Internet Explorer User Agent Style Sheets and CSS2.1 User Agent Style Sheet Defaults.

Translations

Reply on Twitter Retweet on Twitter Favorite on Twitter

13 comments

#

Matt Zimmermann says…

I absolutely love using Normalize. I started incorporating it into site builds before reading up on the HTML5 Boilerplate. When Normalize and Boilerplate came together…it was like when chocolate met peanut butter.

#

fjpoblam says…

I’ve used normalize in all my websites and my clients’ websites. I keep a virgin copy as a template, then work [down] from there. It’s a surely boon to maintenance. I haven’t measured, but I suspect it’s a bandwidth benefit, too.

#

Matt says…

95% of that CSS is to keep various versions of IE behaving, imagine how small the file would be without IE…

#

M Benjamin says…

Nice work. Thanks for doing the work on this. Will be very useful.

#

Phil Wareham says…

I’ve been using Normalize for a while now and it’s great, makes writing CSS much more concise so you can concentrate more on the stuff that really matters – the design.

Takes away some of the nasty surprises that IE throws your way too, which is nice.

#

Dimitar Belchugov says…

I’ve used normalize with html5boilerplate and I think it’s great. Thank you for your work, I’m interested with the development from here.

#

Edson says…

I’ve been using CSS resets (because I think it is easier to understand and apply) and gradualy migrating to Normalize. It is indeed better than the Reset, but a little bit difficult to understand, at least for me. Wondering how it would be possible develop a whole complex website without libraries like Normalize, Formalize, Selectivzr, Modernizr and so on… Thanks for the article! It convinced me to stop using CSS reset.

#

M Benjamin says…

I understand why you disabled the quote property. Your GitHub Wiki is very informative.

But can you offer a solution for a simple way to present short quotations across a site?

Maybe normalize can provide a universally working output (like you do with <b> and <strong>), instead of just turning them off.

Thanks.

#

Vince says…

Hm, that’s really interesting. Though I have really basic skills in CSS, but the idea of normalize.css actually sounds really nice and vital. :) You said that you could either begin from it or change it in the workflow of your development process. Which one would you suggest anyway?

#

Kenneth says…

Well, I can see why you should use normalize.css but I guess we need to spread the word so that more and more developers use the technique. I personally believe that it’s a move to the right direction. In a better world, browsers should just be consistent by default, but again, it’s in a better world. In our world, normalize.css will save our souls. :)

#

Ben says…

Haven’t used this yet but it reads really well, appeals to me much more than a reset (which has been a vital part of my development process for years). I’m taking up a new project in the next few weeks and I’ll definitely be incorporating this – it sounds excellent.

#

Tomás Camusso says…

Thanks for making the web a better place :)

Comment on this post

Please wrap code fragments in <code> tags, wrap blocks of code in <pre><code>, and use JsFiddle to post working examples.