Difference between "class" ad an "ID"

I need some help understanding the difference between a “class” and an “id” I know what class is.

What is the difference between the two, you can style them both. Can someone help me underatand this please?

Tthank you!

Good to see your learning,

Both are ways to select a element and apply styles however there is some minute differences which mosh will discuss in detail.

Once an ID is named it can only work on one element and the name can’t be used again, nor can you give an element multiple ID’s. An ID style will override class styles.

You can repeat classes for example i can create a class = button and put that class on every button on my app and it would apply to each button and make them look the same. I can also give multiple classes like class = button blue-button

button makes it look a certain way, and blue applies the color. i can have red-button ect .

try to use classes more than Id’s for style cause they create less code when you don’t have to repeat things. Id’s are for when you need a distinct style or to override a style, also easier for applying functions in JavaScript later.

1 Like