CSS

CSS Overview Selectors Declarations Rule Sets Comments Reset/Normalize Origin Importance Order Specificity Inheritance Cascade Layers Inline Styles Internal Styles External Styles @import Absolute Units Relative Units Dynamic Viewport Angle Units Time Units Frequency Units: Resolution Units Keywords Color Formats Color Functions & Spaces Background Color Background Image Background Repeat Background Position Background Size Background Attachment Background Shorthand Multiple Backgrounds Linear Gradients Radial Gradients Conic Gradients Font Family Font Size Font Weight Font Style Line Height Text Align Text Decoration Text Transform Letter Spacing Word Spacing Text Shadow Text Wrap Variable Fonts Content Box Padding Box Border Box Margin Box Box Sizing Property Margin Padding Border Outline Box Shadow Block Display Inline Display Inline Block Display Static Position Relative Position Absolute Position Fixed Position Sticky Position Top Element Position Right Element Position Bottom Element Position Left Element Position Z Index Flexbox Box Layout Display Flex Flex Direction Flex Wrap Justify Content Align Items Align Content Gap, Row Gap & Column Gap Flex Grow Flex Shrink Flex Basis Flex Shorthand Order Property Align Self Practical Applications CSS Grid Layout Grid Display Grid Template Columns Grid Template Rows Grid Template Areas Justify Items Grid Auto Columns Justify Self Nested Grids Responsive Web Design Min Width Max Width Orientation Logical Operators Pointer Hover Prefers Color Scheme Fluid Images Flexible Typography Viewport Width Advanced CSS Features Defining variables Using variables Scope & Inheritance of CSS Variables Property Value Fallback Practical Applications :Hover :Active :Focus :Focus Visible :Visited :Link :First Child :Last Child :Nth Child :Nth of Type :Empty :Checked :Disabled :Enabled :Valid :Invalid :Required :Has :Not :Is :Where ::Before Pseudo Element ::After Pseudo Element ::First Letter ::First Line ::Selection ::Marker CSS 2D Transformations CSS 3D Transformations Transform Origin Transform Style Backface Visibility Transition Property Transition Duration Transition Timing Function Transition Delay Transition Shorthand Ease Timing Function Linear Timing Function Ease In Timing Function Ease Out Timing Function Ease In Out Timing Function Cubic Bezier Function Animations (@keyframes) Defining @keyframes Animation Name CSS Animation Duration Animation Timing Function CSS Animation Delay CSS Animation Iteration Count Animations Direction CSS Animation Fill Mode CSS Animation Play State CSS Filter Blur CSS Filter Brightness CSS Filter Contrast() CSS Drop Shadow CSS Grayscale CSS Hue Rotate CSS Invert CSS Opacity CSS Saturate CSS Sepia Mix Blend Mode Background Blend Mode Object Fit & Object Position Scroll Snap Type Scroll Snap Align Scroll Padding Scroll Margin Scroll Triggered Animations JS Variables

Importance


The "Importance" aspect of the CSS cascade dictates the hierarchy of style origins. Rules marked !important from user stylesheets take precedence over author !important rules, which in turn override normal author rules, user agent rules, and finally user agent !important rules. This hierarchy ensures a predictable order of application.

Example 1: User Agent vs. Author Normal

/* Browser's default stylesheet might have: */
/* h2 { font-weight: bold; } */

/* Your author stylesheet: */
h2 {
  font-weight: normal; /* Author's normal rule overrides browser default */
  color: green;
}

Explanation Your author's normal CSS rules (font-weight: normal;) will always override the browser's default (user agent) styles for the same property, as author styles have higher importance.


Example 2: Author Normal vs. Author !important

p {
  color: blue; /* Normal author rule */
}

.special-paragraph {
  color: orange !important; /* Author rule with !important */
}
/* HTML: <p class="special-paragraph">This text will be orange.</p> */

Explanation An !important declaration in your author stylesheet overrides any other normal declaration from your author stylesheet, even if the normal declaration has higher specificity.


Example 3: Inline Style vs. Author !important

<div style="background-color: yellow;">
  <p class="highlight">This text will be red.</p>
</div>

 

/* Your author stylesheet */
.highlight {
  background-color: red !important; /* This !important rule will override the inline style */
}

Explanation An author's !important rule overrides an inline style. This demonstrates the power of !important to force a style, but it should be used judiciously to avoid style conflicts.


Example 4: User !important vs. Author !important (Rare but possible)

/* Assumed user stylesheet rule (highly unlikely to be written by dev) */
/* body { font-family: 'Comic Sans MS' !important; } */

/* Your author stylesheet */
body {
  font-family: Arial, sans-serif !important; /* This would be overridden by user !important */
}

Explanation In rare cases, a user's !important rule (e.g., from an accessibility extension) can override an author's !important rule. This prioritization is for user control over their Browse experience.


Example 5: Specificity within !important Rules

#unique-element {
  background-color: blue !important; /* ID selector with !important */
}

.common-class {
  background-color: green !important; /* Class selector with !important */
}
/* HTML: <div id="unique-element" class="common-class"></div> */

Explanation When multiple !important rules conflict, specificity still plays a role. The !important rule with the highest specificity (e.g., ID selector over class selector) will win.