revert - CSS: Cascading Style Sheets | MDN (2024)

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 either to user agent set value, to user set value, to its inherited value (if it is inheritable), or to initial value. 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.

Examples

Revert vs. unset

Although revert and unset are similar, they differ for some properties for some elements.

So in the below example, we set custom font-weight, but then try to revert and unset it inline in the HTML document. The revert keyword will revert the text to bold because that is the default value for headers in most browsers. The unset keyword will keep the text normal because, as an inherited property, the font-weight would then inherit its value from the body.

HTML

html

<h3 style="font-weight: revert; color: revert;"> This should have its original font-weight (bold) and color: black</h3><p>Just some text</p><h3 style="font-weight: unset; color: unset;"> This will still have font-weight: normal, but color: black</h3><p>Just some text</p>

CSS

css

h3 { font-weight: normal; color: blue;}

Result

Revert all

Reverting all values is useful in a situation where you've made several style changes and then you want to revert to the browser default values. So in the above example, instead of reverting font-weight and color separately, you could just revert all of them at once - by applying the revert keyword on all.

HTML

html

<h3>This will have custom styles</h3><p>Just some text</p><h3 style="all: revert">This should be reverted to browser/user defaults.</h3><p>Just some text</p>

CSS

css

h3 { font-weight: normal; color: blue; border-bottom: 1px solid grey;}

Result

Revert on a parent

Reverting effectively removes the value for the element you select with some rule and this happens only for that element. To illustrate this, we will set a green color on a section and red color on a paragraph.

HTML

html

<main> <section> <h3>This h3 will be dark green</h3> <p>Text in paragraph will be red.</p> This stray text will also be dark green. </section> <section class="with-revert"> <h3>This h3 will be steelblue</h3> <p>Text in paragraph will be red.</p> This stray text will also be steelblue. </section></main>

CSS

main { border: 3px solid steelblue;}section { margin: 0.5rem; border: 2px dashed darkgreen;}

css

main { color: steelblue;}section { color: darkgreen;}p { color: red;}section.with-revert { color: revert;}

Result

Notice how the paragraph is still red even though a color property for the section was reverted. Also, note that both the header and plain text node are steelblue. The result of reverting makes it as if section { color: darkgreen; } did not exist for the section with color: revert applied.

Also, if neither the user agent nor the user override the <h3> or <section> color values, then the steelblue color is inherited from <main>, as the color property is an inherited property.

Specifications

Specification
CSS Cascading and Inheritance Level 4
# default

Browser compatibility

BCD tables only load in the browser

See also

  • Use the initial keyword to set a property to its initial value.
  • Use the inherit keyword to make an element's property the same as its parent.
  • Use the revert-layer keyword to reset a property to the value established in a previous cascade layer.
  • Use the unset keyword to set a property to its inherited value if it inherits or to its initial value if not.
  • The all property lets you reset all properties to their initial, inherited, reverted, or unset state at once.
revert - CSS: Cascading Style Sheets | MDN (2024)
Top Articles
The 23 Most Profitable Metals to Scrap | American Bullion
Pros and Cons of Cold Backup and Hot Backup. Comparison | Storware BLOG
Thor Majestic 23A Floor Plan
Urist Mcenforcer
فیلم رهگیر دوبله فارسی بدون سانسور نماشا
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Don Wallence Auto Sales Vehicles
Wmu Course Offerings
Hotels Near 500 W Sunshine St Springfield Mo 65807
craigslist: south coast jobs, apartments, for sale, services, community, and events
Mail Healthcare Uiowa
Encore Atlanta Cheer Competition
Cape Cod | P Town beach
Craigslist/Phx
Builders Best Do It Center
Flights To Frankfort Kentucky
U/Apprenhensive_You8924
Money blog: Domino's withdraws popular dips; 'we got our dream £30k kitchen for £1,000'
Craiglist Tulsa Ok
Spergo Net Worth 2022
PowerXL Smokeless Grill- Elektrische Grill - Rookloos & geurloos grillplezier - met... | bol
Craigslist Clinton Ar
Georgia Cash 3 Midday-Lottery Results & Winning Numbers
Drift Hunters - Play Unblocked Game Online
Parkeren Emmen | Reserveren vanaf €9,25 per dag | Q-Park
Nk 1399
The Eight of Cups Tarot Card Meaning - The Ultimate Guide
Weather Underground Durham
How rich were the McCallisters in 'Home Alone'? Family's income unveiled
1964 Impala For Sale Craigslist
Vlacs Maestro Login
Isablove
Dailymotion
Dtlr On 87Th Cottage Grove
Mobile Maher Terminal
Newsday Brains Only
Truckers Report Forums
1-800-308-1977
The Minneapolis Journal from Minneapolis, Minnesota
Invalleerkracht [Gratis] voorbeelden van sollicitatiebrieven & expert tips
Jamesbonchai
Pickwick Electric Power Outage
Value Village Silver Spring Photos
Market Place Tulsa Ok
Leland Westerlund
Bank Of America Appointments Near Me
Naomi Soraya Zelda
Slug Menace Rs3
Nfhs Network On Direct Tv
Scholar Dollar Nmsu
Latest Posts
Article information

Author: Geoffrey Lueilwitz

Last Updated:

Views: 6024

Rating: 5 / 5 (80 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Geoffrey Lueilwitz

Birthday: 1997-03-23

Address: 74183 Thomas Course, Port Micheal, OK 55446-1529

Phone: +13408645881558

Job: Global Representative

Hobby: Sailing, Vehicle restoration, Rowing, Ghost hunting, Scrapbooking, Rugby, Board sports

Introduction: My name is Geoffrey Lueilwitz, I am a zealous, encouraging, sparkling, enchanting, graceful, faithful, nice person who loves writing and wants to share my knowledge and understanding with you.