Home / Snippets / Layout /

Minimal CSS reset

Under 20 lines that fix every cross-browser layout quirk you'll actually encounter — box-sizing, margin collapse, line-height inheritance, and nothing extra.

box-sizing: border-boxpadding and border included in width
margin: 0removes default margins from all elements
line-height: 1.5inherited body line-height, not browser default
-webkit-font-smoothingantialiased text on macOS/iOS
min-height: 100dvhbody fills viewport using dynamic unit
Widely Supported
layoutresetno-js

Quick implementation

/* Minimal modern CSS reset */
*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

body {
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

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

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

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

#root,
#__next {
  isolation: isolate;
}

Prompt this to your LLM

Includes role, constraints, framework variants, and edge cases.

You are a senior frontend engineer writing a minimal CSS reset
for a new project.

Goal: Write a modern CSS reset that fixes cross-browser quirks
without imposing opinionated base styles. Keep it under 40 lines.

Include:
- box-sizing: border-box on *, *::before, *::after
- Global margin: 0 reset
- body: line-height 1.5, -webkit-font-smoothing antialiased,
  min-height 100dvh (dynamic viewport unit, not 100vh)
- Media elements (img, picture, video, canvas, svg): display block,
  max-width 100% to prevent overflow
- Form inputs: font: inherit so they match body font
- Text: overflow-wrap: break-word on headings and paragraphs
- Isolation on #root / #__next for React/Next.js stacking contexts

Explain in a comment why each rule exists.

Framework variant: Show how to integrate this into a Vite + React
project (index.css import order) and a Next.js project (globals.css).

Return only the CSS with inline comments.

Why box-sizing: border-box on everything

The browser default is content-box: if you set width: 200px; padding: 20px, the element is actually 240px wide. This surprises nearly every developer who encounters it. box-sizing: border-box makes width include padding and border — the number you set is the number you get. Applying it universally with *, *::before, *::after means you never have to think about it again, including in pseudo-elements used for decorative content.

dvh vs vh for min-height

On mobile browsers, 100vh includes the browser chrome (address bar) even when the address bar is visible and takes up space — causing content to overflow. The dynamic viewport unit 100dvh adjusts as the chrome shows and hides, so min-height: 100dvh always means "fill the visible viewport." It's supported in all modern browsers since 2022 and is the correct replacement for the old 100vh mobile hack.