Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is CSS specificity?
CSS specificity is a set of rules browsers use to decide which CSS rule applies when multiple rules target the same element. It works like a score system to pick the strongest rule.
Click to reveal answer
beginner
Which selector has higher specificity: an ID selector or a class selector?
An ID selector has higher specificity than a class selector. For example, <code>#header</code> beats <code>.menu</code> when both style the same element.
Click to reveal answer
intermediate
How do inline styles affect specificity?
Inline styles (styles written directly in the HTML element using the style attribute) have the highest specificity and override most other CSS rules.
Click to reveal answer
intermediate
Order these selectors from lowest to highest specificity: element selector, class selector, ID selector, inline style.
Lowest to highest specificity: element selector (e.g., <code>p</code>), class selector (e.g., <code>.box</code>), ID selector (e.g., <code>#main</code>), inline style (e.g., <code>style="color:red;"</code>).
Click to reveal answer
beginner
What happens if two selectors have the same specificity?
If two selectors have the same specificity, the one that appears later in the CSS file wins and is applied to the element.
Click to reveal answer
Which selector has the highest specificity?
Astyle attribute
B.container
Cp
D#header
✗ Incorrect
Inline styles (style attribute) have the highest specificity, even higher than ID selectors.
If two CSS rules have the same specificity, which one applies?
AThe one written first in the CSS file
BThe one with fewer selectors
CThe one with more selectors
DThe one written last in the CSS file
✗ Incorrect
When specificity is equal, the rule that appears later in the CSS file overrides earlier ones.
What is the specificity score of the selector div#main.content?
A1 ID, 2 classes
B2 IDs, 1 class
C1 ID, 1 class, 1 element
D3 elements
✗ Incorrect
The selector has 1 ID (#main), 1 class (.content), and 1 element (div).
Which selector has the lowest specificity?
A.nav
Bbody
C#footer
Dstyle attribute
✗ Incorrect
Element selectors like body have the lowest specificity.
Why should you avoid using too many ID selectors for styling?
ABecause IDs have high specificity making overrides difficult
BBecause IDs are slow to load
CBecause IDs are deprecated in CSS
DBecause IDs do not work in modern browsers
✗ Incorrect
High specificity of IDs can make it hard to override styles later, reducing flexibility.
Explain CSS specificity and how it affects which styles are applied to an element.
Think of specificity as a score that decides which CSS rule wins.
You got /4 concepts.
List the order of CSS selectors from lowest to highest specificity and give an example of each.
Remember inline styles are strongest, elements are weakest.
You got /5 concepts.
Practice
(1/5)
1. Which CSS selector has the highest specificity?
easy
A. An ID selector like #header
B. A class selector like .menu
C. An element selector like div
D. A universal selector like *
Solution
Step 1: Understand selector types and specificity
ID selectors have the highest specificity, followed by class selectors, then element selectors.
Step 2: Compare given selectors
#header is an ID selector, which beats class .menu and element div selectors.
Final Answer:
An ID selector like #header -> Option A
Quick Check:
ID selector > class selector > element selector [OK]
Hint: ID selectors always outrank classes and elements [OK]
Common Mistakes:
Thinking class selectors have higher specificity than IDs
Confusing element selectors with class selectors
Ignoring the universal selector has lowest specificity
2. Which of the following CSS selectors is written with correct syntax?
easy
A. .container > #main .item
B. #main .container > .item#
C. .container #main .item#
D. #main > .container .item#
Solution
Step 1: Check each selector for valid CSS syntax
Valid selectors use IDs with # before the name, classes with ., and combinators like > properly placed.
Step 2: Identify invalid parts
Options A, B, and D end with # which is invalid syntax. .container > #main .item is correctly formed.