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.
.plain { color: unset; margin: unset; } .plain-button { all: unset; }
Try it
Syntax
property: unset;
- Works on: every property, including shorthands
- Result:
inheritfor inherited properties,initialfor 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,unseton a non-inherited property goes to the specification value, not the user-agent value.display: unseton a<div>givesinline, notblock. Userevertto get the browser default. all: unseton 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
unsetin a more specific selector to remove a property that a general rule applied, such as clearingmargin-topon 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.
Related
initial,inherit,revertandrevert-layerall- Inheritance
- Lessons: Global values, Inheritance