CSS Selectors
3.2
Lesson

Class Selectors

An element selector selects all the elements with that tag. But what if we need to give a different color only to the second and third headings?

In such cases, we can use the HTML class attribute to select elements. The . symbol is used before the class name to select the elements.

In the above example, the h2 elements with the class ‘heading’ are affected by the styles applied. Note that the other h2 element without that class remains unchanged.