Karan Blogging!

Ids vs. Classes

What are Ids and Classes?

Ids and Classes are attributes we add to HTML elements. Say you wanted to style an element, rather than styling each element in HTML, we add these attributes, which are essentially identifiers. Then we can reference these attributes by using selectors in our css file, and add whatever styling we want from there.

What's the difference between Ids and Classes?

Ids are used when you want to style one particular element only. By adding a unique id attribute to the specific element, you can cite it in your styling by selecting it using the "#" selector.

HTML id attribute example CSS id attribute example

Whereas, Classes are used when you want to style a group of elements the same way. By adding the same class attribute to each element, you can then refer to them all at the same time in your style coding by selecting them using the "." selector.

HTML class attribute example HTML class attribute example