Home / Learn HTML / HTML Styles and CSS
HTML Styles and CSS
CSS controls colours, spacing and layout. You can add it in three places.
Definition
CSS (Cascading Style Sheets) controls how HTML looks. There are three ways to add it.
| Way | Where | Use when |
|---|---|---|
| Inline | style="..." attribute on an element | A single quick change |
| Internal | <style> in the head | One page only |
| External | A .css file linked with <link rel="stylesheet"> | Whole websites (best) |
When rules compete the more specific wins; with equal strength the later rule wins. Inline styles beat style sheets.
Theory in plain words
What it is
CSS can be added three ways: inline style attribute, a style element, or an external file with link.
Why we use it
HTML gives structure, CSS gives design. Splitting them keeps code clean and lets one file style the whole site.
How it works
The browser matches each CSS rule to elements. If rules conflict, more specific rules and later rules win.
Where it is used
- External style.css for real sites
- Inline styles for emails
- style block for quick demos
Best for real websites because many pages share one file.
Open full screen and make the window narrower.
Quick quiz
1. Which is inline CSS?
style="..." on the element.
2. Best for many pages?
One file shared by all pages.
3. Which is the hover selector?
a:hover styles on mouse over.
Common questions
Which is inline CSS?
style attribute. style="..." on the element.
Best for many pages?
External file. One file shared by all pages.
Which is the hover selector?
:hover. a:hover styles on mouse over.