Skip to content
Tutorials Center
My learning

Topics

Lesson 19 of 139 ยท The Cascade

Global Values: initial, inherit, unset, revert

Learn the CSS keywords every property accepts (initial, inherit, unset, revert and revert-layer) and how the all property resets an element in one line.

Most CSS values only make sense for certain properties. bold works for font-weight but not for width, and 20px works for width but not for display. A small group of keywords is different: every property accepts them. They are called the CSS-wide keywords, or global values, and instead of describing a look, they tell the cascade where to get the value from.

You met them briefly in Inheritance. This lesson goes deeper. You will see exactly what each keyword computes to, where the traps are, and how the all property lets you apply one of them to every property at once, which is the cleanest way to strip an element back to a blank slate.

The five keywords at a glance

Keyword What it means Typical use
inherit Use the parent's computed value Make a non-inherited property follow its parent
initial Use the property's initial value from the spec Rarely what you want; see the traps below
unset inherit if the property inherits, otherwise initial "Act as if nothing had set this"
revert Roll back to the browser's (or user's) styles Undo your own styles but keep sensible defaults
revert-layer Roll back to the previous cascade layer Let a later layer opt out of its own rule

They follow a few rules that apply to all five:

  • A global keyword must be the whole value. margin: 10px inherit is invalid, and the declaration is thrown away.
  • On a shorthand, the keyword applies to every longhand it covers. border: inherit inherits all the widths, styles and colors.
  • They are case-insensitive, though everyone writes them in lowercase.

inherit: copy the parent

inherit takes the parent's computed value for that property. For properties that already inherit, like color or font-family, it changes nothing in normal use. Its power shows on properties that do not inherit, such as border, background or padding.

A common real use: buttons and inputs don't inherit fonts by default, so many resets write font: inherit on form controls. Another is a link that should match the text around it:

inherit on links and buttons

Delete the font: inherit line and watch the button snap back to the browser's small sans-serif font.

initial: the spec default, not the browser default

Every property has an initial value written in the CSS specification. initial jumps straight to it, ignoring the parent and the browser's stylesheet. The trouble is that the spec's initial value often differs from what you expect:

Property Initial value What surprises people
display inline div { display: initial } makes a div inline, not block
color CanvasText (usually black) Not your site's text color
font-family depends on the browser Often a serif font, not your site font
margin 0 Removes the browser's default margins on <p> and headings
list-style-type disc An <ol> loses its numbers
initial is not the browser default

That's why initial is rarely the right reset. It is useful when you truly want the spec value, for example max-width: initial (which is none) to cancel a limit set earlier.

unset: pretend nothing was declared

unset asks, "what would this property be if no rule had set it?" For an inherited property that means the parent's value; for a non-inherited one it means the initial value. It is inherit and initial combined, picking the natural behavior of each property.

CSS
.plain {
  color: unset;    /* inherited property โ†’ acts like inherit */
  border: unset;   /* not inherited โ†’ acts like initial (no border) */
}

unset is most useful with all, which you will see in a moment.

revert: back to the browser's stylesheet

revert rolls the cascade back past your styles (the author origin) to whatever the user's stylesheet or the browser's built-in stylesheet would have given. For a <div>, display: revert is block. For an <h2>, margin: revert restores the default heading margins. For a <ul>, list-style: revert brings the bullets back.

In other words, revert means "the default for this element", which is what most people expect initial to do. Use it when a broad rule removed something and one element needs it back:

CSS
ul { list-style: none; padding: 0; }   /* reset for menus */
.prose ul { list-style: revert; padding: revert; }  /* real lists get bullets back */

If no browser or user style exists for that property, revert behaves like unset.

revert-layer: back to the previous layer

revert-layer is the layer-aware version. Inside a cascade layer, it throws away the value from the current layer and lets the cascade use whatever earlier layers (or the browser) decided. Outside any layer, it acts like revert.

revert-layer lets a component opt out

The help link skips the components rule and lands on the base layer's blue link style. With revert instead, it would skip every author layer and get the browser's default link color.

revert-layer is supported in all major browsers since 2022. Very old browsers ignore the declaration, so the element simply keeps its current value.

The all property

all is a shorthand for every CSS property at once (except direction and unicode-bidi, and custom properties are not affected either). It only accepts the global keywords, which makes it a one-line reset:

  • all: unset removes everything: inherited properties come from the parent, everything else goes to its initial value. A <button> becomes plain inline text that still behaves like a button.
  • all: revert undoes your own styles and returns the element to the browser's look.
  • all: initial is rarely useful, because it also resets inherited properties like color and font.
Comparing all: unset, revert and initial

all: unset also removes the focus outline. If you use it on anything interactive, add a :focus-visible style back, as the last example does, so keyboard users can still see where they are.

Global keywords and custom properties

The keywords also work on custom properties, with one twist. --accent: initial sets the variable to its "guaranteed-invalid" initial value, so any var(--accent) that reads it uses its fallback, as if the variable were never defined. --accent: inherit copies the parent's value, which is already what custom properties do by default.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. A rule sets display: initial on a <div>. What does the div become?

    The spec's initial value of display is inline. initial ignores the browser's default of block; use revert for that.
  2. 2. What does border: unset do on an element whose parent has a border?

    unset acts like inherit only for inherited properties. border isn't inherited, so it falls back to its initial value: no border.
  3. 3. Which keyword restores the bullets on a list after a reset removed them?

    revert returns to the browser's default for that element: numbers on an <ol>, bullets on a <ul>. initial always gives disc, even on a numbered list.
  4. 4. Which declaration is invalid and gets thrown away?

    A global keyword has to be the entire value. It can't be mixed with other values.
  5. 5. Inside @layer components, a rule says color: revert-layer. Where does the color come from?

    revert-layer discards the current layer's value and lets the cascade fall back to earlier layers, and past them to the browser's styles.

Summary

  • Every property accepts inherit, initial, unset, revert and revert-layer, and each must be the whole value.
  • inherit copies the parent; it's most useful on non-inherited properties and form controls (font: inherit).
  • initial is the spec's default, which often surprises (display: initial is inline).
  • unset means "as if nothing set it": inherit for inherited properties, initial for the rest.
  • revert returns to the browser's default for that element; revert-layer returns to the previous cascade layer.
  • all: unset or all: revert resets every property in one line; add focus styles back on interactive elements.

Next: Units: px, em, rem and More โ€” how to choose the right unit for every length.