ID selectors, online
Six activities your students do on their own devices. See who's finished, and their scores.
ID selectors in one minute
What students need to know
Each id value may appear only once per HTML document; this element correctly uses a unique id. The ID selector #box overrides competing class or element rules due to its higher specificity score.
ID selectors start with # followed by the id value. A dot (.) is used for class selectors. An ID selector outweighs any number of class selectors in the cascade.
Mistakes students make
- The selector .hero uses a dot (class selector). To target id="hero" it should be #hero { color: red; }.
- The opening curly brace is missing. It should be #banner { color: gold; }.
- There must be no space between # and the id name. It should be #title { with no gap.
- The selector .main uses a dot (class selector). To target id="main" it should be #main { background: grey; }.
What students will learn in this module
Every question in Module 37
Quick questions
- Which selector correctly targets an element with id="hero"?A#hero { }B.hero { }
- Can two elements on the same page share the same id value?ANo — id values must be uniqueBYes — ids can be reused
- Which has higher CSS specificity?AClass selector (.box)BID selector (#box)
- Is this ID selector written correctly: # title { color: red; }ANo — there should be no space after #BYes — the space is fine
- Which HTML attribute does the # selector match against?AclassBid
Key terms
Students type the meaning of:
#id
Match the pairs
#intro { color: navy; }Match it to what it does<h1 id="title">Hello</h1>Match it to what it doesID values must be unique on a pageMatch it to what it doesID selectors have higher specificity than class selectorsMatch it to what it does# hero { color: red; }Match it to what it does.logo { width: 100px; }Match it to what it doesFill in the blanks
_______ { color: blue; }Hint: Type the ID selector for an element with id="header"
<p id="_____">Hello</p>
Hint: Type the id attribute value that matches the selector #intro
_____ { background: red; }Hint: Type the ID selector for an element with id="main"
#nav { _________: 18px; }Hint: Type the CSS property that controls text size
_______ { margin: 0; }Hint: Type the ID selector for an element with id="footer"
Spot the error
Question 1
A<style>B.hero { color: red; }C</style>
Question 2
A<p id="banner">Sale!</p>B<style>C#banner color: gold; }
Question 3
A# title {B font-size: 24px;C}
Question 4
A<div id="main">Nav</div>B<style>C .main { background: grey; }D</style>
Question 5
A<style>B #intro { color: navy; }C</style>D<p class="intro">Hello</p>
