CSS .Class Selector: Definition and Usage
CSS .Class Selector: Definition and Usage
class Selector
Example
.intro {
background-color: yellow;
}
To select elements with a specific class, write a period (.) character, followed by the name of the
class.
You can also specify that only specific HTML elements should be affected by a class. To do this,
start with the element name, then write the period (.) character, followed by the name of the class
(look at Example 1 below).
HTML elements can also refer to more than one class (look at Example 2 below).
Version: CSS1
Browser Support
Selector
.class Yes Yes Yes Yes Yes
CSS Syntax
.class {
css declarations;
}
More Examples
Example 1
p.hometown {
background-color: yellow;
}
Example 2