CSS .class Selector

If this site has been useful, we’d love your support! Running this site takes time and resources, and every small contribution helps us keep creating valuable content. Consider buying us a coffee to keep things going strong!

Description

The CSS class selector is used to select HTML elements with a specific class attribute. To select elements with a specific class, write a period (.) character, followed by the class name.

For example, the following CSS selector will select all div elements with the class my-class:

.my-class {
  /* CSS styles here */
}

You can also use the class selector to select multiple HTML elements of different types. For example, the following CSS selector will select all div and p elements with the class my-class:

.my-class div, .my-class p {
  /* CSS styles here */
}

Class selectors are very useful for styling your web pages, as they allow you to reuse CSS styles for multiple elements. This can save you a lot of time and effort, and make your code more maintainable.

Syntax

.class {
    css declarations;
}

Example

.intro {
   color: #3366ff;
   background: #ffff99;
}

In this example, the elements with the class .intro will have their color and background styles changed.

Give it a Try

Click the button below to experiment with this selector.

Give it a Try!

Browser Support

The following table will show you the current browser support for the CSS class selector.

Desktop
Edge Chrome Firefox Opera Safari
YesYesYesYesYes
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
YesYesYesYesYesYes