Add CSS to HTML
W3C CSS Snapshot 2026
Use a style block for a one-file example, a linked stylesheet for shared styles, or a style attribute for one element.
On this page
Where does <style> go?
For a small example in a single file, put the CSS inside <style> in the document head.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CSS in the head</title>
<style>
p { color: teal; }
</style>
</head>
<body>
<p>Registration is open.</p>
</body>
</html>
Link a separate CSS file
A stylesheet can live in its own .css file. In head, rel="stylesheet" tells the browser what the link is for, and href gives the file location. With both files in the same folder, the file name is enough.
How to try it Save the rule below in style.css beside the previous .html file. Remove its <style> block. In its place, inside <head>, write <link rel="stylesheet" href="style.css">. Save both files and reload.
p { color: purple; }
What to expect The browser reads style.css and makes the paragraphs purple.
If the result differs If the text stays unchanged, check that the link and file use exactly the same name and that both files are saved in the same folder.
Style a single element
The style attribute holds declarations for the element it is written on. Use a class in a stylesheet when several elements need the same styling.
<p style="color: teal;">Workshop check-in</p>
<p>Bring a notebook.</p>
What to expect Only the first paragraph turns teal.