As a web developer or any other type of programmer working in one of the top tech jobs, you’re going to have to deal with HTML/XHTML documents pretty freakin’ often. To adequately describe the content in your page beyond simple tags like <h1> and <ul>, you need to work with classes and IDs. Knowing how to distinguish CSS class vs. ID and understanding the situations in which you’ll use either one will make you a more successful developer and set you up for success.
Classes are Generic, and IDs are Unique
- Speak to a career coach to get guidance
- Coaching sessions are free and always will be
Perhaps the biggest and most obvious difference between ID and class is how you can apply them to elements. CSS can be confusing to beginners, but you’ll find out very quickly when you try to validate your code that you’re perfectly welcome to apply the same class to multiple elements. The reverse works as well—you can apply multiple classes to the same element. Pretty neat, huh?
IDs, on the other hand, are unique. When you apply an ID to an element, you’ve used up that ID and can’t reapply it to another element. Think of the ID and Class like a sort of given name and surname. If your name is Clodpuddle Frogsnatcher Smith, you’re gonna have a lot of other people with the same class names of Smith, U.S. Resident, Adult, and more. But your full name is all your own. (I realize there can be many people with the same name, so the analogy isn’t perfect. Shut up, smarty pants.)
Do you have any thoughts or tips about CSS class vs. ID? Let us know in our comments section below.
If you’re interested in finding out more about CSS class and ID, download the free Career Karma app!