Why IDs cannot use more than once on a page? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why IDs cannot use more than once on a page?

30th Jan 2016, 10:12 AM
Nuwan Thisara
Nuwan Thisara - avatar
3 Answers
+ 16
because they are unique to the specific element you are styling. Classes are used for groups of elements. Think of like this: if you are a teacher and you want one student to do something, you use that students name(ID) to direct him. If you want all the boys to do something, you direct them by saying all boys(CLASS) do X.
29th Mar 2016, 3:01 PM
Lauren M. Hebert
Lauren M. Hebert - avatar
+ 1
i have been using css for a couple of months now, and i know that you can use an id for more than once on a page but those id can not have the same name. For example if I gave a paragraph element an id called "para" i can not use "para" on any other element on that page, in other words every id on that html document has to have a different name therefore making it unique. As for the class; you can have more than one with the same name. If i gave a paragraph a class called "para", i can use "para" on any other elements on that page.
27th Jun 2016, 7:28 PM
Edmond Habimana
Edmond Habimana - avatar
+ 1
create css file and linking html file <link href="style.css"rel="stylesheet"type="text/css/> id how to use #id{color:red}
30th Jun 2016, 12:17 PM
saiful islam
saiful islam - avatar