Adding CSS
4 min read Quiz at the end
Link CSS with a link tag in the head: <link rel='stylesheet' href='styles.css'>. You can also use a style tag or inline styles. External stylesheets are best — browsers cache them for reuse across multiple pages.
Three Ways to Add CSS <!-- 1. External (best practice) -->
<link rel="stylesheet" href="style.css">
<!-- 2. Internal -->
<style>
h1 { color: red; }
</style>
<!-- 3. Inline (avoid for reusable styles) -->
<p style="color: red; font-size: 18px;">Text</p>
Topic Quiz · 5 questions
Test your understanding before moving on
1. Which attribute links a CSS file?
A. src
B. href
C. rel
D. link
💡 <link rel="stylesheet" href="style.css"> links an external stylesheet.
2. Which has the highest specificity?
A. External CSS
B. Internal <style>
C. Inline style=""
D. Inherited style
💡 Inline styles have the highest specificity (except !important).
3. Why prefer external CSS over inline?
A. External is faster
B. External is reusable and keeps HTML clean
C. Inline doesn't work
D. Browsers require external
💡 External CSS separates concerns, is reusable across pages, and can be cached.
4. Can you link multiple CSS files?
A. No
B. Yes
C. Only with JavaScript
D. Only 2
💡 You can link as many CSS files as needed with multiple <link> tags.
5. Which should be added inside <head>?
A. <script>
B. <link rel="stylesheet">
C. Both
D. Neither
💡 CSS <link> tags go in <head> to prevent unstyled content flash.
Submit answers