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