Skip to content
Tutorials Center
My learning

Topics

Lesson 117 of 139 ยท Best Practices

Resets and Base Styles

Learn why CSS resets exist, how a reset differs from normalize, and how to write a small modern reset and base styles that suit any new project.

Before you write a single line of CSS, the browser has already styled your page. Headings are big and bold, paragraphs have margins, lists are indented, links are blue and underlined, and the body has an 8px margin around it. These defaults come from the user agent stylesheet, and they make unstyled HTML readable.

They also get in your way. Browsers don't agree on every default, some defaults are awkward for building interfaces, and you end up overriding the same things in every project. A CSS reset is a small stylesheet you put first to smooth all that out. In this lesson you will learn where resets came from, how they differ from "normalize" styles, and how to write a short, modern reset plus a base layer you can reuse.

What the browser gives you

Every browser ships a default stylesheet. Here is a small taste of what it typically contains:

CSS
body { display: block; margin: 8px; }
h1 { font-size: 2em; margin-block: 0.67em; font-weight: bold; }
p { margin-block: 1em; }
ul { padding-inline-start: 40px; list-style-type: disc; }
button, input, select, textarea { font: -webkit-small-control; } /* varies */

Those defaults are in the user agent origin of the cascade, so any author rule beats them. That is why a reset works: it is just ordinary author CSS loaded first.

Default styles vs a reset

With the reset on, every gap disappears, the bullets hang outside the frame, and the form controls finally use the same font as the text. A reset gives you a flat, predictable canvas; your base styles then add back the spacing you actually want.

Reset vs normalize

Two philosophies grew up around browser defaults:

  • Hard resets (popular in the late 2000s) set nearly everything to zero: margins, padding, font sizes, list styles, even font-weight on headings. Every element looks the same until you style it. That is thorough, but you then have to rebuild a lot.
  • Normalize stylesheets kept useful defaults and only fixed the places where browsers disagreed, such as heading sizes in nested sections or form control fonts. The goal was consistency, not a blank slate.

Today, browsers agree on far more than they used to, so the old reasons for both have shrunk. A modern reset is a small middle ground: a handful of rules that fix the defaults nearly everyone overrides anyway, without stripping meaning. You will build one now.

A modern minimal reset

Here is a reset written for this course. Each rule earns its place:

CSS
/* 1. Predictable sizing: width includes padding and border */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* 2. Remove default outer spacing; base styles add it back */
* {
  margin: 0;
}

/* 3. Steady text size on mobile, full-height body, readable lines */
html {
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
}

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

/* 4. Media behaves like a block and never overflows its container */
img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

/* 5. Form controls use the surrounding font */
input,
button,
textarea,
select {
  font: inherit;
}

/* 6. Long words wrap instead of breaking the layout */
p,
h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

/* 7. Nicer line breaks where supported */
h1, h2, h3, h4, h5, h6 {
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

Why these rules?

  1. box-sizing: border-box makes a width: 300px box actually 300px wide, padding and all. This is the most widely used reset rule there is; box-sizing explains it in full.
  2. margin: 0 removes the inconsistent stack of default margins. You will add spacing deliberately in your base layer.
  3. text-size-adjust: none stops some mobile browsers from inflating font sizes on their own after you rotate the phone. min-height: 100svh lets backgrounds fill the screen. A unitless line-height: 1.5 gives readable text everywhere; see Line Height.
  4. display: block removes the mysterious gap under images (they are inline by default, so they sit on the text baseline). max-width: 100% keeps them from overflowing.
  5. font: inherit fixes the oddest default of all: form controls don't inherit fonts. You learned why in Inheritance.
  6. overflow-wrap: break-word keeps long URLs and words from pushing out of narrow containers.
  7. text-wrap improves line breaks in headings and paragraphs. Browsers that don't support it simply ignore it.

Keep list-style alone. Some resets remove bullets from every list with list-style: none. In Safari, a list with no visible markers can lose its "list" meaning for VoiceOver users. Remove bullets per component instead (for example on a navigation menu), as shown in Styling Lists.

Put the reset in a layer

A reset should never win a fight against your real styles. Two tricks guarantee that:

  • Wrap it in the first cascade layer. Every later layer, and all unlayered styles, beat it automatically.
  • Use :where() for anything with a higher specificity. :where() has zero specificity, so :where(ul, ol)[role="list"] is as weak as a rule can be.
A layered reset and base styles

The + * rule in the base layer is a "flow" pattern: any element that follows a heading, paragraph or list gets a top margin. It replaces dozens of separate margin rules with one.

From reset to base styles

A reset removes things. Base styles decide what plain HTML should look like on your site. They are the bridge between the reset and your components, and usually include:

  • The body font family, size, color and background, preferably from design tokens.
  • Heading sizes and line heights.
  • Link colors, underline offset and the hover and focus styles.
  • Spacing between flowing content.
  • Simple defaults for tables, code and quotes if your content uses them.

Keep base styles to type selectors (h1, a, table) and keep them gentle. If a rule needs a class, it belongs in a component.

Base styles for long-form text

There isn't a single class in the HTML, yet the page looks designed. That is the job of base styles. Notice how h2 { margin-top: 1.6em; } beats the flow rule without any tricks: :where() gives the flow rule zero specificity, so even a single type selector overrides it.

Should you use a published reset?

You can, and many good ones exist. But a reset is short enough that it's worth understanding every line, and copying one blindly can bring surprises, such as removed list semantics or form controls with no visible styling. A sensible path:

  • Start with a small reset like the one above.
  • Add a rule only when you find yourself overriding the same default in several projects.
  • Keep it in the first layer and at low specificity.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Why does a reset stylesheet override browser defaults so easily?

    Author styles win over user agent styles in the cascade, so ordinary author rules are enough.
  2. 2. How does a normalize stylesheet differ from a hard reset?

    Normalize aims for consistency across browsers, while a hard reset aims for a blank slate.
  3. 3. Why does a modern reset include font: inherit for inputs and buttons?

    Browsers give form controls their own font settings, so they don't match surrounding text unless you set font: inherit.
  4. 4. What is a good way to make sure the reset never overrides your component styles?

    Earlier layers lose to later layers and to unlayered styles, and :where() has zero specificity.
  5. 5. Why should a reset avoid list-style: none on every list?

    Remove bullets per component, and add role="list" where needed, rather than everywhere.

Summary

  • Browsers apply a user agent stylesheet; a reset is author CSS that smooths it out.
  • Hard resets zero everything, normalize fixes inconsistencies, and modern resets fix only the defaults people always override.
  • Key rules: border-box sizing, zero margins, block-level responsive media, inherited fonts in form controls, sensible line-height and wrapping.
  • Place the reset in the first cascade layer and keep its specificity low with :where().
  • Base styles then define how plain HTML looks on your site, using type selectors and tokens.

Next: CSS Performance, where you will learn how CSS affects page load and rendering speed, and which optimizations actually matter.