SystemTutor
About
Sign in
Loading course documentation…
SystemTutor

COURSES

  • Data Structures & Algorithms
  • CSS MasterclassNew course
  • System DesignNew course

PRACTICE

  • Algorithm practice
  • CSS practice

LEGAL

  • Privacy Policy
  • Terms of Service
  • About

© 2026 SystemTutor. All rights reserved.

Built with 🫶 by Shatlyk

Welcome to CSS
Getting Started with CSSHTML for CSSCSS SyntaxAdding CSSCSS Comments and DebuggingStylesheets and Debugging Reading and debugging a stylesheet
CSS Foundations

CSS Syntax

Read and write selectors, declarations, properties, and values.

A CSS rule chooses elements and sets their styles. In this lesson, you will connect an HTML class to a CSS selector, then add declarations that tell the browser what to change.

Read a style rule

Compare the selector in the stylesheet with the class on the heading in the HTML tab.

.highlight {
  color: green;
  font-size: 18px;
}

The heading’s class value is highlight. A class selector starts with a dot, so .highlight matches this heading. The heading appears green at 18 CSS pixels.

Read the rule as: “Find elements with the class highlight, then apply these declarations.” A declaration sets a CSS property to a value. Here, color: green and font-size: 18px are two declarations.

PartExamplePurpose
Selector.highlightChooses the elements to style.
PropertycolorNames the feature to change.
ValuegreenSpecifies the setting for that feature.
Declaration blockEverything between { and }Groups the declarations for the selector.

The selector and its declaration block form the complete style rule.

The .highlight selector matches the heading's class. Its declaration block sets color to green and font-size to 18px.

Build a rule step by step

Use the HTML hook first, then add the changes inside the block:

  1. Write .highlight because the heading has class="highlight". The dot means “match this class,” rather than every heading.
  2. Add { and } to make a declaration block.
  3. Add color: green;. color is the property to change; green is its value.
  4. Add font-size: 18px;. font-size expects a size, and 18px means 18 pixels.

Each declaration changes one feature. That is why changing green changes the color without changing the text size, and changing 18px changes the size without changing the selector.

Before moving on, check your reasoning: if the HTML were <p class="note">, which selector would match it? The answer is .note, because the class name stays the same and the dot still marks a class selector.

Now complete this rule in your head. The selector and first declaration are already provided; add a declaration that makes the text 18 pixels:

.note {
  color: purple;
  __________________
}

The missing declaration is font-size: 18px;. It goes inside the same braces because it changes another feature of the same matching elements.

Complete a rule

Now use the same process with a new class. The HTML gives the heading a class named notice:

.notice {
  __________________
  __________________
}

Fill the two blanks in the stylesheet to make the heading green with a font size of 18 pixels.

The completed rule is:

.notice {
  color: green;
  font-size: 18px;
}

The tag changed from h1 to h2, but the reasoning did not: .notice matches because the class value is notice. The declarations go inside the braces because both changes apply to the same matching elements.

Use the punctuation correctly

Each symbol has a job:

  • { starts the declaration block, and } ends it.
  • : separates a property from its value.
  • ; separates one declaration from the next.

For example, color = green uses the wrong separator. The declaration must use a colon: color: green;. When a block has more than one declaration, the semicolon keeps the declarations separate. The final semicolon before } is optional, but keeping it makes adding another declaration less error-prone. A line break does not replace a semicolon.

Format rules for reading

These two rules have the same effect:

.highlight{color:green;font-size:18px;}
.highlight {
  color: green;
  font-size: 18px;
}

Use these formatting habits to make rules easier to scan:

  • Put each declaration on its own line and indent the block.
  • Use consistent spacing around colons; those spaces are optional.
  • Keep property names such as font-size together.
  • Write 18px without a space between the number and its unit.

Some spaces change the meaning of CSS. For example, 18px is valid, but 18 px is not: the number and unit must stay together.

Write another rule

A stylesheet can contain several style rules, each with its own selector and block:

h1 {
  color: green;
}

p {
  color: purple;
}

The first rule selects headings; the second selects paragraphs. Their declarations change the text colors of the matching elements.

Try it yourself

Try it yourself

Style the heading

HTML + CSS

Loading code editor…

Live preview

Updating…

Final output

No comparison yetChecks after 3s without edits
Loading your draft…

Key Takeaways

  • Style rule: A selector connects matching elements to a declaration block.
  • Declaration: A property names what to change, and its value supplies the setting.
  • Punctuation: Braces enclose the block, a colon separates property and value, and semicolons separate declarations.
  • Formatting: One declaration per line makes rules easier to read without changing their meaning.

How is this lesson?

Previous lessonHTML for CSSNext lessonAdding CSS
Edit on GitHubReport on GitHub
On this page
%

On this page

Read a style ruleBuild a rule step by stepComplete a ruleUse the punctuation correctlyFormat rules for readingWrite another ruleTry it yourselfKey Takeaways