CSS / LESSON 09

Your first stylesheet

Turn a document into a consistent visual system.

Beginner8 min read · estimateUpdated Nov 1, 2026
In this lessonA rule has two partsClasses are reusableUnderstand the cascadeTry it yourselfFurther reading

01A rule has two parts

A selector chooses elements. Declarations inside braces set properties and values. Keep a shared stylesheet for styles used by several pages.

/* styles.css */
p {
  color: #333;
  line-height: 1.7;
}

/* In your HTML head: */
/* <link rel="stylesheet" href="styles.css"> */

02Classes are reusable

A class can style many elements. Use descriptive names such as .card or .note. Avoid names that only describe a temporary color or position.

<article class="card">A project</article>
<style>
.card { padding: 24px; border: 1px solid #ddd; }
</style>

03Understand the cascade

When rules compete, origin, importance, layers and specificity affect which declaration wins. For otherwise equal rules, the later one wins. Inspect computed styles instead of adding !important everywhere.

.note { color: #555; }
.note { color: #222; } /* wins over the earlier equal rule */

04Try it yourself

Change the border radius and padding. Watch how spacing changes the card.

EDITABLE EXAMPLE

HTML & CSS only. Scripts and form submissions are disabled.

Further reading

Use the MDN learning guides and HTML Living Standard for deeper explanations and current browser guidance.

ONE STEP FURTHER

Small steps. Real understanding.

Try the example in your own project before moving on.

Progress is saved only in this browser.