CSS Class Selectors: The '.' Prefix

Learn how to use class selectors to efficiently style multiple HTML elements in CSS.

Styling Groups: Class Selectors

Class selectors are like team jerseys for your HTML elements. You can give a group of elements the same "jersey" (a class) and then style all of them at once!

The Dot '.' Syntax

The basic syntax for selecting a class in CSS is: .class-name { property: value; }. You must always start with the dot (`.`) to tell the browser you're targeting a class.

The Power of Reusability

Class selectors are the workhorses of CSS. Their main advantage is **reusability**. You can apply the same class to any number of elements—paragraphs, divs, spans, etc.—to give them a consistent style. This keeps your code organized and easy to update.

Practice Zone


Interactive Test 1: Drag & Drop

Arrastra en el orden correspondiente.


Arrastra las opciones:

yellow
.highlight
background-color

Completa el código:

/* Rule for all 'highlight' elements */______ {
/* The style to apply */______:
/* The specific style value */______;
}______
Unlock with Premium

Interactive Test 2: Fill in the Blanks

Rellena los huecos en cada casilla.

.important-text {
  color: ;
  font-weight: ;
}
Unlock with Premium

Practice Example: Code Editor

Write a CSS rule to make all elements with the class .important have a font-weight of bold.

* Write the code below. Correct characters will be shown in green and incorrect ones in red.

.important { font-weight: bold; }
Unlock with Premium

Knowledge Check

Which character is used to denote a class selector in CSS?


Unlock with Premium