CSS Syntax

CSS syntax is the set of rules that defines how CSS code is written. Every CSS rule consists of a selector and a declaration block. Understanding CSS syntax is the foundation of styling web pages.

Basic CSS Syntax Structure

A CSS rule is made up of three main parts: a selector, a property, and a value.

Selector
Declaration
Declaration
h1
{ color:red; font-size:15px; }
Property
Value
Property
Value

Example of CSS Syntax

The following example styles all paragraph elements by changing their color and font size.

Example
<!DOCTYPE html>
<html>
<head> 
<style>
p {
  color: green;
  font-size: 22px;
}
</style>
</head>
<body>

<p>This is a CSS example.</p>

</body>
</html>
Try this code

Example Explained

CSS Syntax Rules

Common Mistakes in CSS Syntax

Tip: Always validate your CSS syntax. A single syntax error can break the entire stylesheet.