CSS Worksheet: Selectors Class and Id
Code tip (Dot for class, hash for id): p matches every <p>; .note matches class="note"; #top matches id="top". A dot means class, a hash means id — mixing them up matches nothing. Many elements can share a class; an id belongs to only one element.
NameDateTime takenScore ___ / 40
- 1.True or false: .star is an id selector. (a) True (b) False
-
2.🎯 Which CSS selector matches this element?
<div class="red" id="hero">Hello</div> (a) .hero (b) #red (c) div (d) #top - 3.🎯 Which element does the selector #top style? (a) <h2 class="top"> (b) <h2 id="intro"> (c) <li class="red"> (d) <h2 id="top">
- 4.🎯 Which sign starts a class selector? (a) @ (b) # (c) & (d) .
- 5.🎯 What kind of selector is .note? (a) an element selector (b) an id selector (c) a class selector
- 6.🎯 Which element does the selector h2 style? (a) <h2 class="big"> (b) <li> (c) <div class="big"> (d) <span id="intro">
- 7.🎯 Which element does the selector .box style? (a) <span class="box"> (b) <span class="star"> (c) <p class="menu"> (d) <span id="box">
-
8.🎯 Which CSS selector matches this element?
<div class="star" id="top">Hello</div> (a) #star (b) .star (c) #intro (d) span -
9.🎯 Which CSS selector matches this element?
<div class="big" id="logo">Hello</div> (a) #logo (b) #end (c) .logo (d) .red - 10.🎯 How many elements on a page should have the same id? (a) 5 (b) 1 (c) 2 (d) any number
-
11.🎯 Which CSS selector matches this element?
<h2 class="menu" id="top">Hello</h2> (a) #menu (b) li (c) .note (d) .menu - 12.True or false: body is an element selector. (a) False (b) True
- 13.True or false: #hero is an id selector. (a) False (b) True
- 14.True or false: .big is a class selector. (a) False (b) True
- 15.🎯 What kind of selector is #end? (a) an element selector (b) an id selector (c) a class selector
- 16.🎯 Which element does the selector #top style? (a) <h1 class="menu"> (b) <p id="intro"> (c) <p id="top"> (d) <p class="top">
- 17.🎯 What kind of selector is .card? (a) an id selector (b) an element selector (c) a class selector
-
18.🎯 Which CSS selector matches this element?
<p class="box" id="top">Hello</p> (a) #intro (b) .top (c) .box (d) .star - 19.🎯 Which element does the selector .red style? (a) <h2 class="star"> (b) <h1 class="red"> (c) <h1 class="box"> (d) <h1 id="red">
- 20.🎯 Which element does the selector #end style? (a) <h1 class="menu"> (b) <p id="end"> (c) <p class="end"> (d) <p id="hero">
- 21.🎯 Which element does the selector span style? (a) <h1 class="note"> (b) <span class="note"> (c) <p> (d) <h2 id="intro">
- 22.🎯 Which element does the selector #main style? (a) <h2 class="box"> (b) <h1 id="logo"> (c) <h1 id="main"> (d) <h1 class="main">
- 23.🎯 What kind of selector is li? (a) a class selector (b) an element selector (c) an id selector
- 24.🎯 Which sign starts an id selector? (a) & (b) @ (c) # (d) .
-
25.🎯 Which CSS selector matches this element?
<p class="red" id="logo">Hello</p> (a) p (b) #red (c) .logo (d) .box - 26.🎯 What kind of selector is #main? (a) an id selector (b) a class selector (c) an element selector
-
27.🎯 Which CSS selector matches this element?
<h2 class="red" id="top">Hello</h2> (a) .box (b) li (c) .top (d) h2 - 28.🎯 Can many elements share the same class? (a) Yes (b) No
- 29.🎯 What kind of selector is .big? (a) an id selector (b) a class selector (c) an element selector
-
30.🎯 Which CSS selector matches this element?
<span class="star" id="top">Hello</span> (a) #top (b) p (c) .top (d) #intro - 31.🎯 What kind of selector is h1? (a) an element selector (b) a class selector (c) an id selector
-
32.🎯 Which CSS selector matches this element?
<div class="big" id="end">Hello</div> (a) div (b) #big (c) span (d) .red - 33.True or false: #top is an id selector. (a) False (b) True
-
34.🎯 Which CSS selector matches this element?
<span class="star" id="hero">Hello</span> (a) .menu (b) #hero (c) #top (d) .hero -
35.🎯 Which CSS selector matches this element?
<h2 class="red" id="intro">Hello</h2> (a) li (b) #red (c) #main (d) .red -
36.🎯 Which CSS selector matches this element?
<span class="menu" id="end">Hello</span> (a) #end (b) .end (c) .note (d) #menu - 37.🎯 Which element does the selector #hero style? (a) <span class="red"> (b) <div id="top"> (c) <div class="hero"> (d) <div id="hero">
-
38.🎯 Which CSS selector matches this element?
<li class="menu" id="logo">Hello</li> (a) .note (b) #menu (c) li (d) #end -
39.🎯 Which CSS selector matches this element?
<div class="red" id="top">Hello</div> (a) .top (b) span (c) #top (d) #intro - 40.🎯 What kind of selector is #top? (a) an element selector (b) a class selector (c) an id selector
Answer key
- False
- div
- <h2 id="top">
- .
- a class selector
- <h2 class="big">
- <span class="box">
- .star
- #logo
- 1
- .menu
- True
- True
- True
- an id selector
- <p id="top">
- a class selector
- .box
- <h1 class="red">
- <p id="end">
- <span class="note">
- <h1 id="main">
- an element selector
- #
- p
- an id selector
- h2
- Yes
- a class selector
- #top
- an element selector
- div
- True
- #hero
- .red
- #end
- <div id="hero">
- li
- #top
- an id selector
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids