Inline, Internal and External CSS
What Is It?
You can add CSS through a style attribute, a style element, or a linked stylesheet. External CSS lets many pages share one design.
Properties, Tags and Attributes Explained
style attribute: Inline CSS belongs directly to one HTML element.style element: Contains stylesheet rules in the document head. The examples place the editable rules here.link: A void HTML element in head. rel="stylesheet" and href="styles.css" load an external stylesheet.
Each example is a complete HTML page. The CSS is inside the head's style element. Use Try in new tab to edit the CSS or HTML, run your changes, and reset the example.
Example 1: Internal stylesheet
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inline, Internal and External CSS</title>
<style>
p { color: #7c3aed; }
</style>
</head>
<body>
<p>The rule in the head styles this paragraph.</p>
</body>
</html>What you see: The internal stylesheet makes the paragraph purple.
Example 2: Inline style
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inline, Internal and External CSS</title>
<style>
p { padding: 12px; }
</style>
</head>
<body>
<p style="color: #b91c1c; background: #fee2e2">This element has inline colors.</p>
</body>
</html>What you see: The style attribute sets colors; the stylesheet adds padding.
When and Where to Use It
Use an external stylesheet for a multi-page site, internal CSS for a standalone demo, and inline CSS sparingly for one-off generated values.
Common Mistake or Useful Tip
To move example 1 to an external file, save its CSS as styles.css and replace the style element with <link rel="stylesheet" href="styles.css">. The playground keeps examples in one document so they run immediately.
Try It Yourself
Style two paragraphs with one internal rule.