Cyber Code Academy
Tutorials Academy Courses
Home / CSS / CSS Specificity and Cascade

CSS Specificity and Cascade

The cascade

When declarations conflict, CSS considers origin and importance, cascade layers, selector specificity, and source order. The exact cascade includes additional rules for animations, transitions, and user styles.

Specificity basics

p { color: black; }          /* low specificity */
.note { color: green; }      /* class */
#intro { color: blue; }      /* ID */

Among ordinary author rules in the same cascade context, the ID selector generally outranks the class and element selectors shown above.

Best practices

  • Prefer reusable classes.
  • Avoid unnecessary ID selectors for styling.
  • Keep selectors simple and predictable.
  • Use !important sparingly.

Practice

Inspect conflicting declarations with browser developer tools and explain which one wins.

Want to learn this professionally?

Explore practical IT training at Cyber Code Academy.

View Academy Courses