CSS Class Selector
Description
The class selector is one of the most commonly used selectors in CSS, allowing developers to target and style HTML elements that have a specific class attribute. Unlike element selectors that select all instances of a particular div or p tag, the class selector provides more granular control, enabling styles to be applied only to elements assigned a particular class. This makes it extremely useful for applying the same styles to multiple elements across a page or site without affecting other elements of the same type.
A key advantage of the class selector is its flexibility. Multiple classes can be assigned to a single element, allowing the combination of different style rules. For example, an element can have both a highlight class and a rounded class, and the styles for both classes will apply. This modular approach promotes reusability and cleaner code. The class selector is also frequently used in conjunction with other selectors, such as ID selectors or pseudo-classes like :hover, to target elements more specifically.
In practice, the class selector is applied by prefixing the class name with a dot (.) in CSS. For example, a button element with <code>class="primary-button"</code> can be styled using .primary-button { background-color: blue; color: white; }. This makes it easy to maintain consistent styling for buttons across an entire website while keeping the CSS manageable. Additionally, combining the class selector with descendant or child selectors can provide even finer control over the styling of nested elements.
Syntax
.class { css declarations; }
Example
Browser Support
The following information will show you the current browser support for the CSS Class selector. Hover over a browser icon to see the version that first introduced support for this selector.
This CSS class selector is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 3rd January 2026
