In CSS, class selector allows you to select and style elements based on class name. It is one of the most commonly used selectors in CSS.
By using a class selector, you can apply a particular style to multiple elements of your HTML document instead of repeating it for each individual element.
.) followed by the class name.
For example, consider the following HTML:
In the above example, we have applied a class
header to the
Then we have created a CSS styling rule for the
The styles defined for
header class will be applied to all elements with the class
On line 11 of index.html there is an
<h1> element with the class
Now, open style.css. On line 14, use the class selector to create a ruleset that selects that HTML element using the class
Inside the curly braces of the .title selector, add the declaration:
This code will change the background color of the h1 with the title class to yellow.
Sign up to start coding
Already have an account?