HTML Multiple IDs
We can add multiple ids in one HTML element. IDs must be unique, so you should only use a particular ID once on an element. Instead of ID attributes, we can create multiple classes. If we create two IDs for one element, see what happens in the example code below:
HTML:
<h1 id="id1 id2">WELCOME TO WONDERDEVELOP</h1>
CSS:
#id1{
background-color: pink;
}
#id2{
color: red;
}
Output:
- Here, we have created <h1> tag with two id names called id1, and id2.
- Then we tried to apply styles for <h1> using both ID names. So, we set “background-color” to “pink” for the id1 name and “color” to “red” for the id2 name
- See the output, the <h1> tag does not apply the styles of both IDs, because we should not give more than one identity name.