CSS Syntax and Selectors

Basic Syntax

A CSS rule consists of a selector and a declaration block.

selector {
  property: value;
}

Common Selectors

Element Selector

p {
  color: blue;
}

This is a paragraph.

Class Selector

.class-name {
  font-size: 16px;
}

This is a paragraph with class.

ID Selector

#id-name {
  margin: 10px;
}

This is a paragraph with ID.

Grouping Selectors

Apply the same styles to multiple elements:

h1, h2, h3 {
  color: red;
}

Heading 1

Heading 2

Heading 3