Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Custom Properties, Cascade and Global Keywords

The unset keyword

Reference for the CSS unset keyword: inherit when the property normally inherits, otherwise use the initial value. Examples and comparison with revert.

The unset keyword picks a sensible reset automatically. If the property is inherited by default (like color or font-family), unset behaves as inherit. If it is not inherited (like margin or border), it behaves as initial.

Think of it as "pretend no author styles were ever set on this property here". It is often used to cancel a declaration from an earlier rule without deciding which of the two behaviors you need.

CSS
.plain { color: unset; margin: unset; }
.plain-button { all: unset; }

Try it

Inherited vs non-inherited

Syntax

CSS
property: unset;
  • Works on: every property, including shorthands
  • Result: inherit for inherited properties, initial for the rest
  • all: unset: applies this to every property at once

Values

Property kind unset acts like
Inherited (color, font-*, line-height, text-align, visibility, cursor) inherit
Not inherited (margin, padding, border, background, display, width) initial
Custom properties (--x) inherit, because they inherit by default

Usage notes

  • Ignores the browser's styles too. Like initial, unset on a non-inherited property goes to the specification value, not the user-agent value. display: unset on a <div> gives inline, not block. Use revert to get the browser default.
  • all: unset on a <button> or <a> strips native appearance, borders, padding and the focus outline's default styling. Always add your own visible focus style for keyboard users.
  • Cancelling a rule. Set unset in a more specific selector to remove a property that a general rule applied, such as clearing margin-top on the first item.
  • Does not remove other rules. It is a value, not a "delete". A later, higher-specificity declaration still overrides it.
  • Choose by intent. Want the parent's value? inherit. Want the spec default? initial. Want the browser default? revert. Want whichever is natural? unset.

Browser support

Supported in all current browsers.