Back to Blogs

Demystifying CSS Specificity and the Future of Nested Styles in CSS

By Gourish10/30/2025

  • CSS specificity is one of the most misunderstood yet fundamental concepts in styling the web. It determines which styles are applied when multiple rules target the same element, based on the types of selectors used: inline styles, IDs, classes, attributes, and elements. The specificity hierarchy—often remembered as 1-0-0-0 for inline, 0-1-0-0 for IDs, 0-0-1-0 for classes/attributes, and 0-0-0-1 for elements—can quickly spiral out of control when using deeply nested selectors, especially in Sass or Less.



    For years, developers relied on preprocessors to write nested CSS for better organization. But this convenience came at a cost: .card { .header { .title { color: red; } } } compiles to .card .header .title, which has higher specificity than a simple class—and makes overrides harder. Enter native CSS nesting, part of the CSS Nesting Module Level 1 (sometimes informally grouped under “CSS4”). With native nesting, you can write:



    .card {
    & .header {
    & .title {
    color: red;
    }
    }

}

Critically, this still compiles to the same selector—but the real shift is in developer discipline and tooling. Modern CSS encourages flatter structures, and with @layer, :where() (which has zero specificity), and native nesting, we can now write maintainable, scoped-like CSS without inflating specificity unintentionally. The future isn’t about deeper nesting—it’s about smarter, flatter, and more intentional styling with predictable cascade behavior.