← Back to CSS
03

CSS Syntax: The Structure of a Rule

Learn how CSS rules are written, how comments work and how a stylesheet is linked to HTML.

📘 Theory

The anatomy of a CSS rule

Selector, braces and declarations.

A rule has two main parts: the selector, which decides what elements are targeted, and the declaration block, which defines the visual changes to apply.

Inside the braces, every declaration follows the same pattern: property, colon, value and semicolon. That consistency is part of what makes CSS easy to scan once you get used to it.

  • `selector { property: value; }`
  • Multiple declarations live in the same block.
  • Even though the last semicolon can be omitted, keeping it is a good habit.

Comments in CSS

Useful for notes or temporary experiments.

1

Comments help you document intent or disable a rule briefly while debugging. They are ignored by the browser, so they do not affect the final rendering.

2

A practical rule: keep comments short and purposeful. If a comment repeats what the code already says, it is probably not helping.

How CSS is linked to HTML

External files are the default for real projects.

1

The recommended pattern is an external `.css` file linked from the head with ``. That allows reuse across multiple pages.

2

For quick tests, a `` tag inside the page head is enough, but it should not replace a clean stylesheet structure in a larger project.

Using `url()` in CSS

Connect your styles to images, fonts and other assets.

`url()` appears in properties such as `background-image` and in rules like `@font-face`. The main thing to understand is how the browser resolves the path.

If the URL is relative, it is resolved from the location of the CSS file. If it is absolute, it points to an external resource.

  • Relative path: `url("./img/background.jpg")`
  • Absolute path: `url("https://...")`
  • Using quotes is often clearer and safer.

🧭 Key visuals

Anatomy of a CSS rule

It helps learners read a rule quickly and identify each part.

Visual breakdown of selector, properties and values inside a CSS rule

🧪 Learn by doing

Example Basic rule Edit the selector or its declarations and observe the result.

🏁 Challenges

Challenge Challenge: add a property Add the `font-size` declaration to the `.text` selector.
Challenge Challenge: comment out a rule Turn the `.hidden` rule into a comment so the browser ignores it.

🧰 Resources

Test

Check your knowledge with a test about CSS.

Test for CSS

What is this?

I'm Cristian Eslava and I sometimes build websites so both you and I can learn and experiment. culTest

I made this in February 2026 to make learning easier for my students. The idea is to learn web development by practicing and to keep expanding the project with new topics, tests and challenges.

It draws inspiration from MDN, W3Schools, CodePen, Manz and many other web development references. I wanted to combine useful theory, runnable examples, challenges and the testing system I had already built for culTest. culTest

If you liked it, if you didn't, or if you want to get in touch, write to me at cristianeslava@gmail.com