CSS Reference ยท Practical Pages
CSS reset and normalize
Understand CSS resets and normalize stylesheets: what browsers differ on, a small modern reset you can copy, and when to use less or none at all.
Every browser ships a user-agent stylesheet with default styles: margins around the body, bold headings, blue underlined links. The defaults are similar across browsers today, but not identical, and they are not what most designs want. A reset removes or neutralizes defaults so you start from a known baseline. A normalize stylesheet keeps the useful defaults and only fixes the inconsistencies.
Today you rarely need either in full. A short, modern reset of a dozen lines is enough for most projects.
*, *::before, *::after { box-sizing: border-box; } body { margin: 0; line-height: 1.5; } img, svg, video { display: block; max-width: 100%; }
Try it
The left box uses browser defaults. The right box sits inside a .reset wrapper and receives a small reset (scoped here so both can share one page).
In the default box the blue block overflows its container, because width: 100% plus padding and border adds up to more than 100%. With border-box sizing the same declaration fits exactly. The margins and list bullets disappear in the reset box, so spacing becomes entirely your choice.
Reset versus normalize
| Approach | Idea | Trade-off |
|---|---|---|
| Classic reset | Zero out almost everything | You must restyle headings, lists and emphasis yourself |
| Normalize | Keep defaults, fix bugs and differences | Less control, more default look remains |
| Modern minimal reset | A few rules for sizing, media and typography | Needs you to decide what else to reset |
What a modern reset usually contains
box-sizing: border-boxon everything, so padding and borders stay inside the declared width. Seebox-sizing.margin: 0on the body (and sometimes on headings and paragraphs), then spacing set with a consistent rule such asmargin-block.- Media elements as blocks:
img, picture, svg, video { display: block; max-width: 100%; }removes the gap under inline images and stops overflow. - Form controls that inherit text:
button, input, select, textarea { font: inherit; }, because controls do not inherit fonts by default. - A readable base:
line-height: 1.5on the body, andtext-wrap: balanceon headings if you like it. - Respect for motion preferences: a
prefers-reduced-motionblock that shortens animations.
Usage notes
- Do not reset what you do not restyle. Removing list bullets everywhere breaks real lists in articles. Reset lists only inside navigation, or add the bullets back for content.
- Never remove focus outlines (
outline: none) in a reset. It harms keyboard users; restyle with:focus-visibleinstead. - Layers help. Put the reset in a low-priority cascade layer so your component styles always win without specificity fights.
- Avoid
* { margin: 0; padding: 0; }as your only rule. It is blunt: it also strips defaults from form controls and<dialog>. - Frameworks bring their own. If you use a CSS framework, it already includes a base layer; adding a second reset on top creates conflicts.
Browser support
All the rules in a modern reset use features that every current browser supports; text-wrap: balance is newer, so check a compatibility table if you include it.
Related
- Default browser styles โ what a reset overrides
box-sizingallandrevertโ reset a single element's styles- Lesson: Resets and Base Styles