VOOZH about

URL: https://www.geeksforgeeks.org/css/css-class-selector/

⇱ CSS Class Selector - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

CSS Class Selector

Last Updated : 11 Jul, 2025

CSS class selectors are one of the most versatile tools in your front-end development toolkit. They allow you to apply styles to multiple elements on a webpage, ensuring your design remains consistent and easily maintainable.

Syntax

.class-name{
property: value;
}

1. Basic class selector

The basic class selector applies styles to all elements with a specified class name. Use a period (.) before the class name in the CSS.

2. Multiple Class Selectors

Multiple class selectors apply styles only to elements that have all the specified classes. Separate the class names with a dot.

3. Chaining Class Selectors with Other Selectors

You can combine class selectors with element or pseudo-class selectors for more specific targeting.

4. Global Class Application

The universal selector with a class allows you to target all elements with the specified class.

5. Combining Multiple Class Names

An element can have multiple class names, and each class's styles will combine.

6. Targeting Nested Elements with Class Selectors

You can apply styles to elements within a parent class using descendant selectors.

7. Overriding Class Styles

Use multiple classes on an element to override specific styles defined in earlier classes.

8. Using Class Selectors with Media Queries

Class selectors can be used within media queries to make styles responsive.

Comment
Article Tags: