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

Origin


The "Origin" in the CSS cascade refers to where a style rule comes from. There are three primary origins that influence a property's final value: user agent stylesheets, user stylesheets, and author stylesheets. Understanding these origins helps in debugging and predicting style outcomes.

Example 1: User Agent Stylesheet (Browser Default)

/* No explicit CSS written here, but browsers apply default styles */
/* For example, a browser's default might be:
   h1 {
     display: block;
     font-size: 2em;
     margin-block-start: 0.67em;
     margin-block-end: 0.67em;
     font-weight: bold;
   }
*/
p {
  /* This rule will override any user agent default for paragraphs */
  line-height: 1.5;
}

Explanation User agent stylesheets are the default styles provided by the browser. They ensure basic readability for unstyled content. Our line-height rule for p demonstrates overriding a browser's default.


Example 2: User Stylesheet (User Customizations)

/* This would be in a user's custom stylesheet (e.g., in browser settings) */
/* It typically has higher specificity than author stylesheets unless !important is used */
body {
  /* A user might set a preferred font family globally */
  font-family: "Open Sans", sans-serif !important; /* User preference, often with !important */
}

Explanation User stylesheets allow users to apply their own styles, often for accessibility or personal preference. These are less common for developers to interact with but can override author styles if marked with !important.


Example 3: Author Stylesheet (Your CSS)

/* This is your standard CSS file */
body {
  background-color: #f0f0f0; /* Sets a light grey background for the page */
  color: #333; /* Sets a dark grey text color for the entire page */
}

a {
  color: #007bff; /* Sets the color of all links to a bright blue */
  text-decoration: none; /* Removes the underline from all links */
}

Explanation Author stylesheets are the CSS files you write and link to your HTML document. These are the primary source of styling for your website, dictating its visual design.


Example 4: Inline Styles (Author Origin with High Specificity)

<p style="color: red; font-size: 18px;">
  This paragraph has inline styles.
</p>

Explanation Inline styles are CSS declarations applied directly within an HTML element's style attribute. They have the highest specificity among author styles and are often used for unique, element-specific adjustments.


Example 5: CSS !important Declaration (Overrides Origin Order)

/* In your author stylesheet */
.critical-message {
  color: red !important; /* This rule takes precedence regardless of specificity or origin */
  font-weight: bold;
}

/* In HTML: <p class="critical-message" style="color: blue;">This is important.</p> */

Explanation The !important declaration gives a style rule extreme precedence, often overriding even inline styles or rules from a more specific selector. Use it sparingly, as it can make debugging difficult.