CSS Reset: A Modern Reset, Explained Line by Line

Short answer: a CSS reset is a small stylesheet you load first to replace the browser’s default styles with predictable ones. Old resets removed every default. A modern reset is short: it fixes the handful of defaults that cause bugs, like content-box sizing, inconsistent margins, images that overflow, and form fields that ignore your font.

Here’s the whole reset first, then every rule and why it’s there. Copy it as-is, or keep only the lines you agree with.

The reset

It’s wrapped in a cascade layer, so any style you write later wins, whatever its specificity. More on that below.

@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body,
  h1, h2, h3, h4, h5, h6,
  p, figure, blockquote, dl, dd {
    margin: 0;
  }

  body {
    min-height: 100vh;
    line-height: 1.5;
  }

  h1, h2, h3, h4, h5, h6 {
    line-height: 1.2;
    text-wrap: balance;
  }

  p {
    text-wrap: pretty;
  }

  h1, h2, h3, h4, h5, h6, p {
    overflow-wrap: break-word;
  }

  img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
  }

  img, video {
    height: auto;
  }

  input, button, textarea, select {
    font: inherit;
  }

  ul[role="list"],
  ol[role="list"] {
    list-style: none;
    padding: 0;
  }

  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }
}

Every rule, explained

box-sizing: border-box

By default, width sets the content box, and padding and border are added on top. A width: 100% element with padding ends up wider than its parent. With border-box, the width includes padding and border, which is how most people expect sizing to work. The pseudo-elements are included because * doesn’t match them.

text-size-adjust: 100%

Mobile Safari enlarges text on some pages when you rotate the phone to landscape. Setting the adjustment to 100% turns that off, but still lets users zoom. Avoid none: on some browsers, it can stop users from resizing text.

Remove margins from text elements

Browsers give headings, paragraphs, figures and lists top and bottom margins that differ by element and collapse in surprising ways. Removing them lets you add spacing on purpose, for example with gap on the parent or a rule like .flow > * + * { margin-top: 1em; }.

The reset lists the elements instead of using * { margin: 0 }. A blanket rule also removes the automatic margin a <dialog> uses to center itself.

Body: min-height and line-height

min-height: 100vh lets the body fill the window, which helps with sticky footers and full-page backgrounds. The browser’s default line height of about 1.2 is too tight for paragraphs; 1.5 is easier to read. Headings get a tighter 1.2, because big text with loose lines looks disconnected.

text-wrap: balance and pretty

balance evens out the line lengths of short headings, so you don’t get one lonely word on the last line. pretty avoids a single orphaned word at the end of a paragraph. Browsers that don’t support them simply wrap text normally, so they’re safe to include.

overflow-wrap: break-word

A long URL or word with no spaces can push its container wider than the screen and cause horizontal scrolling on mobile. This lets the browser break it when it doesn’t fit. If you need to cut text off instead, see text-overflow: ellipsis.

Images and media: display: block and max-width: 100%

Images are inline by default, so they sit on the text baseline and leave a small gap below them. display: block removes it. max-width: 100% stops large images from overflowing their container, and height: auto keeps their proportions when they shrink, even if the HTML has width and height attributes.

The trade-off: an image inside a line of text now starts on its own line. If you have inline icons, give them display: inline-block in your own styles.

font: inherit on form fields

Inputs, buttons, textareas and selects don’t inherit the page’s font by default. They use a system font at a smaller size, so forms look out of place. font: inherit makes them match the surrounding text. It also helps on iOS, which zooms into inputs with text smaller than 16px.

Lists with role="list"

Navigation and card lists usually don’t need bullets. But in Safari, a list with list-style: none may no longer be announced as a list by VoiceOver. Adding role="list" in the HTML restores that, so the reset only removes the bullets from lists that have it. Your normal content lists keep their bullets.

<ul role="list" class="nav">
  <li><a href="/blog/">Blog</a></li>
  <li><a href="/tools/">Tools</a></li>
</ul>

Respect reduced motion

Some people get dizzy or nauseous from motion and turn on “reduce motion” in their system settings. This rule makes animations and transitions finish almost instantly for them. The duration is 0.01ms rather than 0, so events like animationend and transitionend still fire and code that waits for them doesn’t break.

Why put the reset in a cascade layer?

Styles inside a @layer lose to styles outside any layer, regardless of specificity. So .button { margin: 8px; } in your own CSS beats a reset rule even if the reset’s selector is more specific. You’ll never have to fight your own reset with extra classes or !important.

Cascade layers work in all current browsers. In a browser without support, the whole layer block is ignored, so the page just falls back to the browser defaults.

Load the reset before your other styles:

Load it first

If you use a build tool, import it at the top of your main stylesheet instead.

<link rel="stylesheet" href="/css/reset.css">
<link rel="stylesheet" href="/css/styles.css">

CSS reset vs normalize

  • Classic reset (like Eric Meyer’s): removes almost every default, including heading sizes and list bullets. You rebuild everything yourself.
  • normalize.css: keeps useful defaults and only makes browsers behave the same. Most of the bugs it fixed are gone in current browsers.
  • Modern reset (like the one above): somewhere in between. It keeps sensible defaults and changes the few that cause layout bugs. Tailwind’s Preflight works the same way.

FAQ

Do I still need a CSS reset?

Browsers are far more consistent than they used to be, so you no longer need one to fix browser bugs. A reset is still useful because some defaults, like content-box sizing and form fonts, are simply inconvenient.

Should the reset remove heading sizes?

Not necessarily. Default heading sizes are a reasonable fallback, and you’ll style headings anyway. This reset leaves them alone.

Where should the reset go?

Before all your other CSS. With @layer, the order matters less, but loading it first keeps things clear.

Is box-sizing: border-box on every element bad for performance?

No. The universal selector is cheap, and this rule has been in almost every reset and framework for over a decade.

Next, put the reset to work: these CSS tips cover the layout tricks it makes easier, and CSS line-height explains why unitless values like 1.5 are the right choice.