Adding CSS to HTML
What Is It?
CSS changes how HTML looks: colors, sizes, spacing, and layout.
What the Tags Mean
style: holds CSS rules in head.styleattribute: styles one element.link rel="stylesheet": loads a CSS file.
Example 1
Save each example as index.html and open it in your browser. Each code block is a complete page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Adding CSS to HTML</title>
</head>
<body>
<p style="color: blue">This sentence is blue.</p>
</body>
</html>Browser preview
What you see: The paragraph uses blue text.
Example 2: Another Use
Use a style element when several paragraphs need the same rule.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Adding CSS to HTML</title>
<style>
p { color: green; }
</style>
</head>
<body>
<p>First paragraph</p>
<p>Second paragraph</p>
</body>
</html>Browser preview
Simple Tip
HTML says what the content is. CSS says how it looks.
Try It Yourself
Change blue to purple in the first example.