</> ConvertAtlas Developer Tools
Level 1 · Beginner — CSS Foundations Lesson 2 Beginner 11 min

How CSS Connects to HTML

Three ways to add CSS — inline, internal and external — and why external wins for real projects.

CSS is useless until it reaches your HTML. There are three ways to connect them, and choosing the right one keeps your project clean. Let us look at all three and when to use each.

Three ways to add CSS

MethodHowUse when
External<link> to a .css fileAlmost always — best practice
Internal<style> in the headA single one-off page
Inlinestyle="..." on an elementQuick tests only — avoid

In real projects you keep CSS in a separate file and link it from the HTML head. One file can style your entire site, and the browser caches it for speed.

<link rel="stylesheet" href="styles.css">
  • Element<link>
  • Relationshiprel="stylesheet"
  • Filehref="styles.css"

Internal CSS

For a single page, you can put CSS in a <code>&lt;style&gt;</code> tag inside the head. This is what our live examples use.

HTML
<h1>Hello</h1>
<p>Internal CSS styles this page.</p>
CSS
h1 { color: #2563eb; }
p { color: #555; }
Result
The CSS pane is the equivalent of a <style> block.

Inline CSS (avoid)

You can put styles directly on an element with the <code>style</code> attribute, but avoid it: it cannot be reused, it is hard to maintain, and it has very high specificity that causes problems later.

Common mistake
Don't
<p style="color:red;font-size:18px">Hi</p>
Do
/* in CSS */
.note { color: red; font-size: 18px; }

Inline styles scatter your CSS and are nearly impossible to maintain across a site. Keep styles in one place.

Best practice

Use one external stylesheet for a real site. It is cached, reusable, and keeps your HTML clean and readable.

Try it yourself

In the live example, add a rule that gives the paragraph a background colour and some padding. Notice how the CSS pane behaves like an external stylesheet.

Quick quiz

1. Best way to add CSS to a real site?

2. Where does a <link> to CSS go?

3. Why avoid inline styles?

Key takeaways
  • Three ways to add CSS: external (best), internal, inline (avoid).
  • External stylesheets link via <link rel="stylesheet"> in the head.
  • One external file can style a whole site and is cached.
  • Inline styles hurt reuse and maintainability.