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

Getting Started with CSS

Read a CSS rule and predict which part of an HTML page will change.

CSS, or Cascading Style Sheets, describes the presentation of an HTML document. A heading stays a heading when you change its size or color. The HTML names the content, and CSS tells the browser how to present it.

Read your first rule

body {
  background-color: lightblue;
}

Read from the outside in. The body selector chooses the body of the page. The braces hold a declaration, background-color: lightblue;. Open a page with this rule and an otherwise unstyled, transparent root: the light blue fills the page canvas.

HTML elements and nesting

HTML gives CSS something to select. Here are the tags for two headings, a paragraph, a link, and an image:

<h1>Main Heading</h1>
<h2>Subheading</h2>
<p>This is a paragraph.</p>
<a href="https://example.com">Visit Example</a>
<img src="image.jpg" alt="Sample Image">

An element can contain other elements. In the HTML tab, the heading and paragraph are both children of the same div. The class attribute gives that parent a name CSS can match.

.container {
  color: blue;
}

The rule matches the parent. Its children also have blue text because color is inherited when the child has no text color of its own. When you read the paired tabs in this course, style.css holds the rules and index.html supplies the elements. The link in the document head connects the two files.

Both arrows lead from the blue div.container to its direct children. The heading and paragraph each inherit blue from the div.

Use classes and IDs

A class can identify several elements, even if they use different tags. An ID identifies one element in the document. Predict which text will have a yellow background and which will be bold.

.highlight {
  background-color: yellow;
}

#main {
  font-weight: bold;
}

The dot in .highlight matches the class on both the first div and the paragraph. The hash in #main matches the ID on the last division. Only that div gets bold text.

Create CSS rules

This pattern shows the three parts you will read in a rule. The names here stand for the selector, property, and value that a real rule needs.

selector {
  property: value;
}
h1 {
  color: blue;
  font-size: 20px;
}

Here h1 selects the top-level headings. The first declaration sets their text color. The second sets their font size to 20 CSS pixels.

Group declarations

.button {
  background-color: green;
  color: white;
  border-radius: 5px;
  padding: 10px;
}

Look at padding: 10px;. It puts ten pixels of space between the button’s content and each inside edge. The green background extends through that space. All four declarations belong to the same class selector.

Write CSS comments

A comment begins with /* and ends with */. The browser skips the text between them, even when it spans several lines.

/* Style a class */
.highlight {
  background-color: yellow;
}

/*
  This is a longer comment
  that spans multiple lines.
*/

The comment labels the rule. The yellow background comes from the declaration inside the braces.

Find and fix syntax mistakes

Read the first rule and predict whether the heading will turn red.

h1 {
  color: red
  font-size: 16px;
}

A line break does not end a declaration. The browser reads the next line as part of the color value and discards that invalid declaration. Restoring the separator lets both changes take effect.

h1 {
  color: red;
  font-size: 16px;
}

Try it yourself

Try it yourself

Color the page canvas

HTML + CSS

Loading code editor…

Live preview

Updating…

Final output

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

Key Takeaways

  • A selector identifies the elements a rule can style. Each declaration changes a property on those elements.
  • A child can inherit text color from a parent even when the selector matches only the parent.
  • Braces group declarations. A semicolon separates one declaration from the next.

How is this lesson?

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

On this page

Read your first ruleHTML elements and nestingUse classes and IDsCreate CSS rulesGroup declarationsWrite CSS commentsFind and fix syntax mistakesTry it yourselfKey Takeaways