Challenge - 5 Problems
ID Selector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ selector
intermediate2:00remaining
What color will the text be?
Given the following HTML and CSS, what color will the text inside the <h1> tag appear as in the browser?
CSS
/* CSS */ #title { color: blue; } h1 { color: red; } /* HTML */ <h1 id="title">Hello World</h1>
Attempts:
2 left
💡 Hint
Remember that ID selectors have higher specificity than element selectors.
✗ Incorrect
The ID selector (#title) has higher specificity than the element selector (h1), so the color blue from #title applies.
📝 Syntax
intermediate2:00remaining
Which CSS rule correctly selects the element with id 'main'?
Choose the correct CSS selector to style the element with id="main".
Attempts:
2 left
💡 Hint
ID selectors start with a special symbol.
✗ Incorrect
The # symbol is used to select elements by their id attribute in CSS.
❓ rendering
advanced2:00remaining
What is the background color of the div?
Given this HTML and CSS, what background color will the <div> have when rendered?
CSS
/* CSS */ #box { background-color: lightgray; } .container #box { background-color: orange; } /* HTML */ <div class="container"> <div id="box">Content</div> </div>
Attempts:
2 left
💡 Hint
Look at the specificity and the selector that matches the element.
✗ Incorrect
The selector '.container #box' is more specific than just '#box', so the background color orange applies.
❓ accessibility
advanced2:00remaining
Why should IDs be unique in HTML?
Select the best reason why each ID attribute value should be unique on a webpage.
Attempts:
2 left
💡 Hint
Think about how scripts and screen readers find elements.
✗ Incorrect
Unique IDs let JavaScript and assistive tools find and interact with the exact element reliably.
🧠 Conceptual
expert3:00remaining
What happens if multiple elements share the same ID?
If two or more elements have the same id attribute value, what is the most likely effect in CSS and JavaScript?
Attempts:
2 left
💡 Hint
Consider how browsers handle duplicate IDs in styling and scripting.
✗ Incorrect
CSS applies styles to all elements matching the selector, even if IDs are duplicated (though invalid). JavaScript's getElementById returns only the first matching element.