CSS Global Keywords: Inherit, Initial, Unset, and Revert

Master the CSS keywords that give you precise control over property value resolution, inheritance, and cascade behavior.

Modern CSS provides four powerful global keywords that give developers precise control over property value resolution. These keywords work with any CSS property and offer different strategies for managing the cascade, inheritance, and browser defaults. Understanding when and how to use each keyword is essential for writing maintainable, predictable stylesheets.

The ability to reset properties to their natural values or override inheritance behavior has become increasingly important as web applications grow more sophisticated. Component-based architectures often require fine-grained control over how styles cascade and inherit, making these global keywords indispensable tools for modern web development.

Understanding CSS Inheritance

CSS properties fall into two categories that determine how they behave when not explicitly set on an element. Inherited properties automatically propagate values from parent elements to their children, while non-inherited properties apply only to the element itself unless explicitly set. This distinction is fundamental to understanding how the global keywords behave, as some keywords behave differently depending on which category a property belongs to.

Inherited Properties

These properties automatically pass their values down to child elements:

Property TypeExamples
Typographycolor, font-family, font-size, font-weight, line-height
Texttext-align, letter-spacing, text-indent, text-transform
Listslist-style-type, list-style-position
Othervisibility, opacity, quotes

When you set color on a paragraph, all text inside that paragraph inherits that color automatically. This behavior reduces the amount of CSS you need to write while ensuring visual consistency across related elements.

Non-Inherited Properties

These properties only affect the element they're applied to:

Property TypeExamples
Layoutdisplay, position, z-index, float, clear
Box Modelwidth, height, margin, padding, border
Backgroundbackground-image, background-position, background-size
Otheroverflow, clip, transform, transition

Understanding which properties inherit and which don't is crucial for debugging style issues and making informed decisions about when to use global keywords. For example, setting color on a container will affect all descendant text, but setting display on the same container won't affect how child elements are laid out. If you're working with complex layouts, understanding these CSS fundamentals pairs well with our guide on logic in CSS media queries for responsive design patterns.

Visual Example of Inheritance Behavior

/* Parent sets color - all children inherit this */
.parent {
 color: #0066cc;
}

/* Child elements get blue text automatically */
.child {
 /* No color set, inherits #0066cc */
}

/* Grandchild also inherits */
.grandchild {
 /* Still #0066cc */
}

/* Non-inherited property behaves differently */
.parent {
 margin: 20px;
}

.child {
 /* margin is NOT 20px - non-inherited! */
}

The Inherit Keyword

The inherit keyword explicitly forces a property to take its value from the parent element, even if the property is not normally inherited. This is particularly useful when you want to override a browser default or inherited value in a specific context.

Practical Use Cases

Link colors in navigation: When you want navigation links to match the surrounding text color without explicitly setting the same color value multiple times.

nav {
 color: white;
}

nav a {
 color: inherit; /* Takes white from nav */
}

Form inputs with custom fonts: Making form inputs inherit the font-family from their parent ensures consistent typography across your entire application.

.form-container {
 font-family: 'Inter', sans-serif;
}

.form-container input,
.form-container select {
 font-family: inherit; /* Matches parent */
}

Overriding third-party styles: When integrating components from external libraries, inherit can help blend those elements with your design system.

Why Use Inherit

The primary benefit is maintainability. When you use inherit, the value automatically updates if the parent's value changes. This eliminates the need to track down and update multiple declarations throughout your stylesheet. It's especially valuable in component-based architectures where styles might cascade through multiple layers of nested components, similar to how CSS cascade layers help manage style conflicts.

Inherit Keyword Examples
1/* Example: Footer with inheriting links */2 3footer {4 color: white;5 background: #1a1a2e;6 padding: 24px;7}8 9footer a {10 color: inherit;11 text-decoration: underline;12}13 14/* Without inherit, you'd need: */15footer a {16 color: white; /* Duplicated value */17}18 19/* If footer color changes: */20footer {21 color: #e0e0e0;22}23 24/* inherit auto-updates links25 duplicated value would need manual update */26 27/* Common pattern: Form inputs */28.form-group {29 font-family: system-ui, sans-serif;30}31 32.form-group input,33.form-group textarea {34 font-family: inherit;35 padding: 8px 12px;36}
Initial vs Revert Comparison
1/* Important: initial != browser default */2 3/* CSS specification default */4p {5 display: initial; /* Becomes inline */6}7 8/* Browser default for <p> */9p {10 display: revert; /* Becomes block */11}12 13/* Real-world reset example */14input {15 all: initial;16 font-family: inherit;17 padding: 8px;18}19 20/* This creates a clean slate */

The Initial Keyword

The initial keyword resets a property to its CSS specification default, which may differ from browser defaults. This distinction is crucial for avoiding unexpected behavior.

Key Distinction

Scenariodisplay: initialdisplay: revert
On <p> elementinlineblock
On <div> elementinlineblock
On <span> elementinlineinline

The CSS specification defines display: initial as inline for all elements, regardless of their semantic meaning. Browser defaults, however, respect HTML semantics.

Common Use Cases

Reset form elements: Create a clean slate for custom form styling without fighting browser defaults.

/* Start fresh with form inputs */
input, textarea, select {
 all: initial;
 font-family: inherit;
}

Debug cascade issues: Isolate a single property to understand why a particular value is being applied.

Remove inherited values: Strip away all custom styling and return to the specification baseline.

When to Use Initial

Use initial when you specifically need the CSS specification's defined default value, not the browser's default styling. This is less common in everyday development but valuable when building design systems or debugging complex stylesheets.

For most "reset" scenarios, revert provides more intuitive behavior by respecting browser defaults for semantic HTML elements.

The Unset Keyword

The unset keyword resets a property to its "natural" value, behaving differently based on whether the property inherits:

  • Inherited properties: Acts like inherit
  • Non-inherited properties: Acts like initial
/* For inherited property - inherits from parent */
.child-element {
 color: unset; /* Takes parent's color */
}

/* For non-inherited property - spec default */
.child-element {
 margin: unset; /* Becomes 0 */
}

Understanding Unset Behavior

The unset keyword essentially says "use whatever value this property would have if no styles were applied to it." This makes it a convenient shorthand when you want to "reset" a property without knowing whether it inherits.

PropertyInherits?unset Behavior
colorYesTakes parent value
font-sizeYesTakes parent value
marginNo0 (spec default)
paddingNo0 (spec default)
borderNonone (spec default)

Why Explicit Keywords Are Often Better

The dual behavior of unset can be confusing and may lead to unexpected results if you're not familiar with which properties inherit. Some developers prefer explicit keywords for clarity:

/* Explicit is clearer */
.element {
 color: inherit; /* I want parent value */
 margin: initial; /* I want spec default */
}

/* Unset works but intent is less clear */
.element {
 color: unset; /* Parent? Initial? */
 margin: unset; /* Parent? Initial? */
}

### Best Use Cases for Unset

- **Resetting multiple properties** at once without separate declarations
- **Creating clean styling slates** within encapsulated components
- **Removing inherited styles** from third-party component styles
- **Simplifying CSS** when natural values are genuinely desired

However, if clarity is important in your codebase, consider using [`inherit`](#text-inherit) or [`initial`](#text-initial) explicitly instead.

The Revert Keyword

The revert keyword rolls back values to the previous cascade origin, providing more intuitive reset behavior than initial. This makes it the preferred choice for most "reset" scenarios.

How Revert Works

Property TypeRevert Behavior
InheritedActs like inherit
Non-inheritedReverts to browser defaults

Key Advantage Over Initial

For non-inherited properties like display, revert gives you browser defaults that respect semantic HTML:

Elementdisplay: initialdisplay: revert
<p>inlineblock
<div>inlineblock
<span>inlineinline

This makes revert more useful for truly "resetting" elements to their natural browser-rendered state.

Practical Example

/* Reset third-party component styles */
.third-party-widget {
 all: revert;
 /* Then apply your custom styles */
 font-size: 1rem;
 color: inherit;
}

Accessibility Considerations

The revert keyword respects user stylesheets, allowing accessibility-focused user customizations to take precedence over author styles. This makes revert a good choice for inclusive design, which aligns with our approach to accessibility-first web development.

Browser Support

All four global keywords have excellent support in modern browsers. The revert keyword has been widely available since 2020 and works consistently across Chrome, Firefox, Safari, and Edge.

For most "reset" scenarios, revert (or all: revert) is the most intuitive and practical choice, as it returns elements to their browser-default state rather than specification defaults.

CSS Global Keywords Comparison
Property Typeinheritinitialunsetrevert
Inherited (color)Parent valueSpec defaultParent valueParent value
Non-inherited (margin)Parent valueSpec default (0)Spec default (0)Browser default
Result for <p display>N/Ainlineinlineblock

The All Shorthand Property

The all property is a special CSS shorthand that resets all properties on an element simultaneously. Combined with global keywords, it provides a powerful way to establish a baseline styling state.

/* Reset everything to browser defaults */
.element {
 all: revert;
}

/* Inherit all inheritable properties */
.element {
 all: inherit;
}

/* Reset all to specification defaults */
.element {
 all: initial;
}

/* Natural value for each property */
.element {
 all: unset;
}

Practical Applications

Styling third-party components: When integrating widgets from external libraries, all: revert strips away all author-defined styles and returns the element to its browser-default state. From there, you can apply your own styles without fighting inherited or cascaded values.

Creating scoped styles: Build component systems with predictable starting points by resetting to browser defaults before applying component-specific styles.

Debugging cascade issues: Use all: revert to establish a known baseline and identify where unexpected styles are coming from.

Example: Component Isolation

/* Third-party widget reset */
.external-widget {
 all: revert;
 /* Now styling from scratch */
 font-family: system-ui, sans-serif;
 font-size: 1rem;
 color: #333;
 border: 1px solid #ddd;
 border-radius: 4px;
}

Performance Note

The all property is resolved at computed-value time with no significant rendering overhead. It provides a concise alternative to lengthy CSS reset stylesheets while reducing the potential for style conflicts.

For most use cases, all: revert is recommended as it provides the most intuitive reset behavior, returning elements to their semantic browser-default state while respecting user accessibility preferences.

Best Practices and Performance

Choosing the Right Keyword

ScenarioRecommended KeywordReason
Force element to match parent colorinheritExplicit intent, predictable
Remove all custom stylesall: revertComplete reset to browser defaults
Reset to semantic defaultsrevertBrowser defaults for semantic HTML
Specification behavior neededinitialCSS spec defined value
Unknown inheritance statusunsetNatural value for each property

Performance Considerations

CSS global keywords have minimal performance impact:

  • Computed at style resolution time - No additional rendering work
  • Same as explicit values - Browser treats them as regular property values
  • Use sparingly - For maintainability, not performance

Maintainability Guidelines

  1. Prefer explicit keywords (inherit/initial) over unset for clarity in team environments
  2. Comment unusual uses of global keywords to explain intent
  3. Test across target browsers despite good support, especially for legacy requirements
  4. Use all: revert for third-party component isolation - it's the most intuitive reset
  5. Combine with specific overrides after resetting rather than relying on natural values

Code Organization Tips

/* Group global keyword resets together */
/* Reset third-party components */
.external-component {
 all: revert;
}

/* Make links match parent */
.navigation a {
 color: inherit;
}

/* Form input reset */
.form-input {
 all: initial;
 font-family: inherit;
}

When to Avoid Global Keywords

  • Animations and transitions - Use explicit values for better performance
  • Critical rendering path - Explicit values are slightly clearer
  • Confusing scenarios - When the behavior isn't immediately obvious

Summary

For most web development scenarios, inherit and all: revert will cover your needs. Use inherit when you want explicit parent value inheritance, and revert when you want to reset to browser defaults. Reserve initial and unset for specific cases where their unique behavior is required. For teams looking to level up their CSS architecture, our web development services can help establish consistent styling patterns across your codebase.

Frequently Asked Questions

What's the difference between initial and revert?

`initial` sets a property to its CSS specification default (e.g., `display: inline` for all elements), while `revert` resets to browser defaults for semantic HTML (e.g., `display: block` for paragraphs). Revert is usually what you want for "resetting" elements to their natural browser-rendered state.

When should I use unset instead of inherit?

Use `unset` when you want the "natural" behavior--inheritance for inherited properties, specification initial for non-inherited. Use `inherit` or `initial` explicitly when you want to make the behavior clear to other developers reading your code.

Does all: revert affect user accessibility styles?

Yes, `revert` considers user stylesheets before reaching browser defaults. This means accessibility-focused user customizations will be respected, making it a good choice for inclusive design.

Can I use these keywords with CSS variables?

Yes, global keywords work with CSS custom properties. For example, `color: inherit` will inherit a custom property value, and `all: revert` will reset custom property declarations along with other properties.

Are there browser compatibility concerns?

All four keywords (`inherit`, `initial`, `unset`, `revert`) have excellent support in modern browsers. The `revert` keyword has been widely available since 2020, so it's safe for production use across Chrome, Firefox, Safari, and Edge.

Need Help with Your CSS Architecture?

Our web development team specializes in building maintainable, scalable stylesheets using modern CSS best practices. From component libraries to design systems, we help you create styles that are predictable, performant, and easy to maintain.

Sources

  1. MDN Web Docs - CSS revert - Official CSS specification reference for global keyword values
  2. LogRocket Blog - CSS Inheritance Guide - Comprehensive tutorial covering all four keywords with practical examples
  3. CSS-Tricks - inherit, initial, unset, revert - Practical developer perspective with real-world use cases