agyanadda@gmail.com

CSS Syntax

CSS Basics 1 min read Updated Dec 1, 2026 Topic 2 of 39

A CSS rule has two parts: a selector and a declaration block.

h1 { color: blue; font-size: 32px; }
  • h1 is the selector — which elements to style
  • color and font-size are properties
  • blue and 32px are values
  • Each property: value; pair is a declaration, ending with a semicolon
  • Declarations sit inside curly braces { }

Tips

  • You can write one declaration per line to keep code readable.
  • CSS ignores extra spaces and line breaks.
  • Property names are lowercase, with words joined by dashes: background-color.

Example

Example — Rule with several declarations HTML
<style>
  p {
    color: white;
    background-color: #1f386b;
    padding: 12px;
    font-size: 18px;
  }
</style>

<p>One selector, four declarations.</p>

All four declarations apply to every paragraph.

Try it Now »

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which character ends a CSS declaration?

Exercise 2 Fill in the Blank

In color: red; the word color is the ___.

Exercise 3 True / False

Declarations are written inside curly braces { }.

Frequently Asked Questions

The next declaration may be ignored because the browser reads both as one invalid value. Always end each declaration with ;.