From the course: CSS Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Class selectors

Class selectors

- [Presenter] When type selectors are too general but you'd need more flexibility than IDs. There's another option. The class selector, which matches to one or more elements based on the class attribute value. Similar to IDs, to use a class, it must first be added to the HTML tag and just like IDs, the value is defined by you. But when used as a CSS selector, it starts with a period. The same class name can be reused throughout the page by adding the same value to any number of elements. The selector only matches to the class name, so it doesn't even have to be the same type of element. You can also use multiple classes with the same element. The order doesn't matter but each class name must be separated by a space and contained within the quotation marks. For example, any element with either the fancy or highlight class name will have the corresponding styles applied to it. If the element contains both class names then…

Contents