CSS Tutorial · CSS Basics · Lesson 1 of 19

CSS Introduction

What CSS is, how rules work and how it separates style from content.

What is CSS?

CSS (Cascading Style Sheets) describes how HTML elements are displayed: colours, fonts, spacing, layout, animation, and how the page adapts to phones and large screens. One stylesheet can style an entire website.

A CSS rule

h1 {
  color: navy;
  font-size: 32px;
}
  • h1 is the selector — which elements to style.
  • color: navy; is a declaration: a property and a value.
  • Declarations go inside { } and end with ;.

Press Run to see the CSS applied:

Your first stylesheetTry it yourself
<style>
  body { font-family: system-ui, sans-serif; background: #f8fafc; }
  h1 { color: #1e3a8a; font-size: 28px; }
  p { color: #334155; line-height: 1.6; }
</style>
<h1>Styled with CSS</h1>
<p>The same HTML can look completely different with another stylesheet.</p>

New to HTML? Start with the HTML tutorial.

Test yourself

In p { color: red; }, what is p?

  1. The property
  2. The value
  3. The selector
  4. The declaration
Show answer

Answer: The selector