ID Selector
Another selector is the ID selector. Similar to classes, let's look at the following code:
<h1 id="identifier">Title</h1>
This code contains an h1
element with the id
attribute set to identifier
. We say that this element has the ID identifier
.
In HTML, multiple elements cannot have the same ID. To select an element with a specific ID in CSS, we use the selector #identifier
as follows:
#identifier {
background-color: blue;
}
Similar to class selectors, the ID selector starts with a symbol, in this case, #
. It indicates that we want to select an HTML element with a specific ID, in this case, the ID identifier
.
Instructions
On line 31
in the file index.html
, you can see a div
element with the id
breeds
.
Create a rule for this id
with the following declaration border: 1px solid green
(1px thick, solid, green border).
Start programming for free
5/12