CHAPTER 2

CSS Syntax

CSS syntax defines how a CSS rule is written and applied to an HTML element.

01. What is CSS Syntax?

A CSS rule contains a selector and a declaration block.
A declaration contains a property and a value.
The property defines what you want to change.
The value defines how that property should appear.

02. Syntax

selector { property: value; }

03. Example

CSS / HTML Example AIFA Coding Lab
<!DOCTYPE html>
<html>

<head>

    <style>

        p {
            color: red;
            font-size: 20px;
        }

    </style>

</head>

<body>

    <p>
        This paragraph is styled using CSS.
    </p>

</body>

</html>

04. Important Points

✓ The selector identifies the HTML element.
✓ The property is followed by a colon.
✓ The value comes after the colon.
✓ Each declaration normally ends with a semicolon.

05. Common Mistakes

⚠ Using a comma instead of a colon between property and value.
⚠ Forgetting curly braces.
⚠ Forgetting the semicolon between declarations.

06. Real World Use

Understanding CSS syntax is the foundation for writing every CSS rule.

Ready to Practice? 🚀

Open the AIFA CSS Editor and practice this chapter live.

Try It Yourself →
Practice Exercise

Practice CSS Syntax

Create a heading and use CSS syntax to change its color, size and alignment.