skip to content

In CSS, what is the difference between the global keywords inherit, initial, unset, and revert?

level: middleimportance: must knowfreq 60%

answer

  1. four CSS-wide keywords, any property
  2. initial is the spec value, not the browser's
  3. display: initial computes to inline
  4. unset picks inherit or initial per property
  5. revert restores the user-agent stylesheet

basics

~20 s

inherit takes the parent's computed value; initial uses the property's spec-defined initial value; unset means inherit for inherited properties and initial for the rest; revert rolls the property back to the user-agent or user value, discarding author styles.

solid answer

~50 s

All four are CSS-wide keywords that every property accepts. `inherit` takes the parent's computed value, even for a property that normally does not inherit. `initial` applies the property's initial value **from the specification**, which is frequently not the browser default you expect — `display: initial` computes to `inline`, not `block`. `unset` is the neutral choice: it behaves as `inherit` on inherited properties and as `initial` on everything else. `revert` is the one candidates miss: it rolls the property back to the value it would have had with no author styles at all, so you land on the user-agent stylesheet and a button still looks like a button. The short version: `initial` gives you the spec's blank slate, `revert` gives you the browser's default. There is also `revert-layer`, which rolls back only to the previous cascade layer.

code

css · 10 lines
css
.card { color: rebeccapurple; display: flex; }

.card--plain {
  color: unset;   /* inherited property: acts as inherit */
  display: unset; /* not inherited: acts as initial, so inline */
}

.card--native {
  display: revert; /* back to the user-agent value: block */
}

go deeper

for a junior

Be able to name all four keywords and say what each does in one sentence. The safe headline is that initial is the specification's value while revert is the browser's default.

for a middle

Explain the mechanics: unset resolves per property to inherit or initial, and revert steps out of the author origin to the user or user-agent value. Have the display example ready.

for a senior

Demonstrate judgment about which one to use in a reset — why all: revert keeps form controls usable and accessible where all: initial strips them down to inline, unstyled boxes.

for a principal

Own the policy question: whether your codebase resets aggressively or leans on user-agent defaults, and what that choice costs in cross-browser consistency and accessibility of native controls.

## One vocabulary, every property Every CSS property accepts these keywords, no matter what its normal value grammar is. They are handled by the cascade itself, so `border: inherit` and `z-index: revert` are valid even though neither keyword appears in those properties' value definitions. Each must be the sole value of the declaration — `margin: 10px initial` is invalid and the whole declaration is dropped. ## inherit Takes the **computed value of the parent element** for that property, unconditionally. The property's inherited/not-inherited flag only decides what happens when no declaration reaches the element; an explicit `inherit` is a declaration and simply wins. So `inherit` is how you make a normally non-inheriting property inherit: ```css .child { border-color: inherit; padding: inherit; } ``` On the root element, where there is no parent, `inherit` falls back to the initial value. ## initial Applies the property's **initial value as written in the specification**. The trap is that this is not "how the browser normally renders this element" — the browser's look comes from the user-agent stylesheet, which is a set of ordinary declarations layered on top of the initial values. The canonical demonstration is `display`. Its initial value is `inline`; a `<div>` looks like a block only because the UA stylesheet says `div { display: block; }`. So: ```css div { display: initial; } /* the div becomes inline */ ``` Similarly `initial` on a text property does not give you the site's font — it gives you the spec's initial value, which is the UA's default font. ## unset A convenience keyword meaning "erase this declaration's effect and let normal defaulting happen". For an inherited property it acts as `inherit`; for a non-inherited property it acts as `initial`. It is the keyword you want when undoing something in a component override, because it restores the natural behaviour rather than a hard-coded value. Note it still erases **all** author declarations, including the ones your own framework relies on — the element gets the parent's value or the spec initial, not whatever your base stylesheet had set. ## revert Rolls the property back to the value it would have if the current cascade origin had contributed nothing. In an author stylesheet — the origin you normally write in — that means the value from the user origin, or failing that the user-agent stylesheet. This is why `revert` is usually the friendlier reset. `button { all: initial; }` produces something that is inline, unstyled, and no longer looks or behaves like a control to sighted users; `button { all: revert; }` gives you back the browser's own button. Likewise `div { display: revert; }` restores `block`, while `display: initial` gives `inline`. ## revert-layer A fifth keyword, rolling back only as far as the **previous cascade layer** within the same origin rather than out of the origin entirely; used outside any layer it behaves like `revert`. It shipped in Chrome 99, Firefox 97 and Safari 15.4 (2022) and is broadly available now, whereas `inherit`, `initial` and `unset` have been safe for a decade and `revert` since roughly 2020 in Chromium and 2016 in Safari. ## Putting them side by side Take a `<div>` with the author rule `div { display: flex; }` and ask what each keyword yields when it overrides it: ```css div { display: inherit; } /* the parent's computed display */ div { display: initial; } /* inline — the spec initial value */ div { display: unset; } /* inline — display is not inherited */ div { display: revert; } /* block — the UA stylesheet value */ ``` Four keywords, four different outcomes on one property, which is exactly why interviewers like this question. ## Choosing one Use `inherit` to deliberately pull a value down from an ancestor. Use `unset` to neutralise a declaration and let defaulting decide. Use `revert` when you want the browser's native presentation back, especially on form controls and replaced elements. Reach for `initial` only when you genuinely want the specification's blank value and have checked what that value actually is.

  • Why does display: initial on a div make it inline rather than block?
    Because `initial` means the value the *specification* defines for the property, and the initial value of `display` is `inline`. A `<div>` renders as a block only because the user-agent stylesheet contains `div { display: block; }`, which is an ordinary declaration, not part of the property's initial value. Use `display: revert` if you want the browser default back.
  • When would you prefer unset over initial?
    When you are undoing a declaration and want the element to behave naturally afterwards. `unset` restores inheritance for inherited properties, so `color: unset` on a component lets the surrounding text color flow back in, whereas `color: initial` pins it to the specification's initial color and ignores the context entirely. `unset` is context-aware; `initial` is absolute.
  • Can these keywords be combined with other values in one declaration?
    No. A CSS-wide keyword must be the entire value of the declaration. `margin: 0 initial` or `font: inherit bold` is invalid, and an invalid declaration is discarded at parse time, so the previous value stays in effect. Shorthands do accept them alone: `font: inherit` sets every font longhand to `inherit`.

saying these in an interview costs you the question

  • Says initial restores the browser's default appearance
  • Treats unset and initial as interchangeable
  • Thinks inherit only works on inherited properties
  • Cannot state that display: initial yields inline
  • Believes revert undoes only the current rule

context