Module 1 · Getting Started · Lesson 3 of 5

How to Add CSS

Beginner ⏱ 15 min2 sections · 1 exercise · 4-question quiz

There are three ways to attach CSS to a page — inline, internal, and external — and one of them is right 95% of the time. Learn all three, and why external stylesheets win.

1. Three ways in

HTML — inline, internal, external
<!-- 1. Inline: style attribute (avoid) -->
<p style="color: red;">Urgent note</p>

<!-- 2. Internal: a <style> block in <head> -->
<style>
  p { color: #3E6787; }
</style>

<!-- 3. External: a linked .css file (best) -->
<link rel="stylesheet" href="styles.css">

2. Load order matters

Stylesheets apply in the order they load, so a later <link> can override an earlier one at equal specificity. Teams exploit this deliberately: a base sheet first, a theme sheet after. Put your <link> tags in <head> so the page never renders unstyled.

💡 Shipping to production? Run your file through the CSS Minifier to strip whitespace and comments before upload.

3. Try it yourself

This page's paragraph is styled inline. Move the styling into the internal <style> block instead (delete the style attribute, add a rule), and make it #2FAF71.

exercise.html — editable

4. Quiz — check your understanding

How to Add CSS Quiz

4 questions · pass at 60%

Q1. Which method is recommended for styling a multi-page site?

External files are cacheable, reusable across every page, and keep markup clean.

Q2. Where should the <link rel="stylesheet"> tag go?

In <head>, so styles load before content renders and users never see an unstyled flash.

Q3. Why are inline styles discouraged?

They defeat reuse, bloat HTML, and their high precedence makes later overrides painful.

Q4. Two linked stylesheets set the same property with equal specificity. Which applies?

Later sources win at equal specificity — the second stylesheet overrides the first.
🏆
Quiz passed? You're one step closer to your certificate.

Every lesson quiz you pass (60%+) is saved in your browser and counts toward the CSSmatic Certificate of Completion.

Track my progress →