The revert
CSS keyword reverts the cascaded value of the property from its current value to the value the property would have had if no changes had been made by the current style origin to the current element. Thus, it resets the property to its inherited value if it inherits from its parent or to the default value established by the user agent's stylesheet (or by user styles, if any exist). It can be applied to any CSS property, including the CSS shorthand property all
.
This keyword removes from the cascade all of the styles that have been overridden until the style being rolled back to is reached.
- If used by a site's own styles (the author origin),
revert
rolls back the property's cascaded value to the user's custom style, if one exists; otherwise, it rolls the style back to the user agent's default style. - If used in a user's custom stylesheet, or if the style was applied by the user (the user origin),
revert
rolls back the cascaded value to the user agent's default style. - If used within the user agent's default styles, this keyword is functionally equivalent to
unset
.
The revert
keyword works exactly the same as unset
in many cases. The only difference is for properties that have values set by the browser or by custom stylesheets created by users (set on the browser side).
Revert will not affect rules applied to children of an element you reset (but will remove effects of a parent rule on a child). So if you have a color: green
for all sections and all: revert
on a specific section, the color of the section will be black. But if you have a rule to make all paragraphs red, then all paragraphs will still be red in all sections.
Note: Revert is just a value. It is still possible to override the revert
value using specificity.
Note: The revert
keyword is different from and should not be confused with the initial
keyword, which uses the initial value defined on a per-property basis by the CSS specifications. In contrast, user-agent stylesheets set default values on the basis of CSS selectors.
For example, the initial value for the display
property is inline
, whereas a normal user-agent stylesheet sets the default display
value of <div>
s to block
, of <table>
s to table
, etc.