NEW
Font size
WorksheetsCode HS 8.13 CSS Select by ID
Total questions: 10
Worksheet time: 8mins
How do you select an element with the ID "main-header" in CSS?
.main-header {}
#main-header {}
main-header {}
<main-header> {}
What symbol is used to target an ID in CSS?
. (dot)
# (hashtag)
@ (at symbol)
* (asterisk)
Which of the following is true about ID selectors in CSS?
An ID can be used for multiple elements in an HTML document.
An ID should be unique within an HTML document.
An ID is the same as a class.
IDs must start with a number.
Given the following HTML, which CSS rule correctly styles the <h1> element?
<h1 id="title">Welcome</h1>
title { color: red; }
.title { color: red; }
#title { color: red; }
<title> { color: red; }
Why would you use an ID selector instead of a class selector?
When you want to style multiple elements the same way.
When you need to apply a unique style to only one specific element.
When you want to apply styles globally.
There is no difference between IDs and classes.
What is wrong with following CSS rule?
#1header { color: blue; }
The ID name should be written in quotes.
IDs cannot start with a number.
The # symbol is incorrect for an ID selector.
The property color is not valid for an ID selector.
If two CSS rules conflict, which one takes precedence?
A class selector
An ID selector
A tag selector
The first rule written in the CSS file
How do you assign an ID to an HTML element?
<p class="header">Hello</p>
<p id="header">Hello</p>
<p #header>Hello</p>
<p .header>Hello</p>
Can multiple elements in an HTML document have the same ID?
Yes, but it is not recommended.
Yes, it works the same as a class.
No, IDs must be unique per document.
No, IDs are not used in HTML.
What is the correct way to change the background color of an element with the ID "banner"?
banner { background-color: yellow; }
.banner { background-color: yellow; }
#banner { background-color: yellow; }
<banner> { background-color: yellow; }
