0
0
CSSmarkup~20 mins

ID selectors in CSS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ID Selector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
selector
intermediate
2: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>
ARed
BBlack (default)
CBlue
DGreen
Attempts:
2 left
💡 Hint
Remember that ID selectors have higher specificity than element selectors.
📝 Syntax
intermediate
2:00remaining
Which CSS rule correctly selects the element with id 'main'?
Choose the correct CSS selector to style the element with id="main".
A#main { background: yellow; }
B.main { background: yellow; }
Cmain { background: yellow; }
D*main { background: yellow; }
Attempts:
2 left
💡 Hint
ID selectors start with a special symbol.
rendering
advanced
2: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>
AOrange
BLightgray
CTransparent
DWhite
Attempts:
2 left
💡 Hint
Look at the specificity and the selector that matches the element.
accessibility
advanced
2:00remaining
Why should IDs be unique in HTML?
Select the best reason why each ID attribute value should be unique on a webpage.
ATo make the page look better visually
BTo ensure CSS styles apply only once per page
CTo reduce page load time
DTo allow JavaScript and assistive technologies to identify elements uniquely
Attempts:
2 left
💡 Hint
Think about how scripts and screen readers find elements.
🧠 Conceptual
expert
3: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?
ACSS styles apply only to the first element, and JavaScript throws an error
BCSS styles apply to all elements with that ID, and JavaScript selects only the first element with that ID
CCSS styles apply to none, and JavaScript selects all elements with that ID
DCSS styles apply to all, and JavaScript selects all elements with that ID
Attempts:
2 left
💡 Hint
Consider how browsers handle duplicate IDs in styling and scripting.