Understanding "Revert" in CSS: Resetting and Undoing Styles


  1. Initial Values
    In CSS, you can reset a property to its initial value using the keyword initial. This essentially "reverts" the property back to its default state defined by the browser or the element's type. It's a common technique to achieve a baseline style before applying further customizations.

  2. inherit Keyword
    Another way to potentially achieve a "revert" effect is by using the inherit keyword for a property. This makes the element inherit the value of that property from its parent element. This can be helpful to reset styles influenced by parent elements and establish a new starting point for the current element.



  1. Resetting a Property to Initial Value with initial
/* Assuming a base style sets font-size to 16px globally */

.my-element {
  font-size: initial; /* Resets font-size back to browser default (e.g., 16px) */
  color: blue; /* Applies a new color style */
}
  1. Inheriting Style from Parent with inherit
/* Assuming a parent element has a margin: 10px; style */

.my-element {
  margin: inherit; /* Inherits margin style from parent element (10px) */
  border: 1px solid black; /* Applies a new border style */
}


  1. initial Keyword
    As mentioned before, initial is a powerful tool to reset a property to its default browser or element type value. This can be helpful for establishing a clean slate before applying your styles.

  2. unset Keyword
    The unset keyword removes a property declaration entirely from the cascade. This essentially "unsets" any previously defined styles for that property, potentially reverting it back to the inherited value or browser default. It's important to note that unset behaves slightly differently than initial for some properties on some elements.

  3. Overriding Styles with Specificity
    CSS cascade determines which style applies based on specificity. You can override existing styles by writing a new rule with higher specificity targeting the same element and property. This effectively "reverts" the previous style and applies your new one.

  4. Reset Stylesheets
    There are popular CSS reset stylesheets available online that aim to normalize browser defaults across different browsers. This can be a good starting point to ensure a consistent baseline before applying your own styles.

TechniqueEffectUse Case
initialResets property to default browser or element valueEstablishing a clean slate for specific properties
unsetRemoves property declaration entirelyCompletely undoing styles for a property
Specificity OverrideOverrides existing styles with a more specific ruleTargeting specific elements and properties for style changes
Reset StylesheetsNormalizes browser defaults across different browsersCreating a consistent foundation for all styles