CSS id vs class

Published:   June 1, 2020


Simple CSS question while working on resume project, is when to use id and when to use class.

First thing to know about IDs:

IDs are unique

Browser knows a bit about IDs, this ID is what we see in fragment or hash-value. Browser uses this to reach parts various part of repo. So it has to be unique.

For css it doesn’t matter it applies stying if you ask by #id_name or .class_name but browser wants ID to be unique.

So it one style has to be used on multiple elements then use class if yoou want to use it only once them go for id

For more you can read this post: https://web.archive.org/web/20140831165401/http://css-tricks.com/the-difference-between-id-and-class/

< Prev   Further Reading   Next >

For feedbacks: email@murarisumit.in