Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære ID Selectors | Selecting and Targeting Elements
CSS Foundations

bookID Selectors

index.html

index.html

style.css

style.css

copy

An ID selector in CSS allows you to target a single, unique element on your page. To use an ID selector, add an id attribute to an HTML element, then reference that ID in your CSS by prefixing it with a hash (#). For example, if an element has id="main-title", you select it in CSS with #main-title.

Each ID value must be unique within a page—no two elements should share the same ID. This uniqueness helps ensure that the styles you apply with an ID selector affect only the intended element. ID selectors are commonly used for elements that need a specific, one-off style or for elements you want to reference directly in scripts or navigation.

question mark

Which of the following is the correct syntax for selecting an element with the ID "header" in CSS?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 3

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Suggested prompts:

Can you give an example of how to use an ID selector in HTML and CSS?

What is the difference between an ID selector and a class selector in CSS?

When should I use an ID selector instead of a class selector?

Awesome!

Completion rate improved to 6.67

bookID Selectors

Sveip for å vise menyen

index.html

index.html

style.css

style.css

copy

An ID selector in CSS allows you to target a single, unique element on your page. To use an ID selector, add an id attribute to an HTML element, then reference that ID in your CSS by prefixing it with a hash (#). For example, if an element has id="main-title", you select it in CSS with #main-title.

Each ID value must be unique within a page—no two elements should share the same ID. This uniqueness helps ensure that the styles you apply with an ID selector affect only the intended element. ID selectors are commonly used for elements that need a specific, one-off style or for elements you want to reference directly in scripts or navigation.

question mark

Which of the following is the correct syntax for selecting an element with the ID "header" in CSS?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 3
some-alt