Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

The Cascade & Specificity | CSS Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. CSS Course

Lesson 4 of 50

·css

The Cascade & Specificity

12 mins

Course progress8%

What you'll learn

Keep these ideas in mind as you work through the lesson.

3 points
  • The cascade follows origin → importance → specificity → source order.
  • `!important` should be used sparingly.
  • Understanding specificity prevents unexpected style overrides.

When several rules match the same element the cascade decides which wins.

  • Origin – user agent → user → author → inline.
  • Importance – !important overrides normal rules.
  • Specificity – calculated from ID, class/attribute/pseudo‑class, element selectors.

Specificity score: inline(1,0,0,0) > id(0,1,0,0) > class(0,0,1,0) > element(0,0,0,1).


Example: Specificity battle

/* lowest */ p { color:gray; }
/* higher */ .note { color:blue; }
/* highest */ #important { color:red; }
Make it stickPractice what you've learned1 quiz · 6 practical tests · Optional activities from CSS CourseBrowse activities
Previous lessonBasic SelectorsContinue to lesson 5The Box ModelBack to CSS Course curriculum