Adding CSS to a Page
There are three ways to add CSS. Inline styles use the style attribute on one element. Internal styles live inside a style element in the page. External styles live in a separate .css file linked with a link element in the head.
External stylesheets are the best choice for real sites: one file can style many pages and the browser caches it. Inline styles are useful for quick tests, but they are hard to override and hard to maintain.
Inline and internal
Example
<style>
.internal { color: royalblue; }
</style>
<p class="internal">Internal style</p>
<p style="color: tomato;">Inline style</p>External (shape only)
Example
<!-- In your page head: -->
<link rel="stylesheet" href="styles.css">
<!-- No network here, so this only shows the shape. -->
<p>The link element loads styles.css.</p>- If the same property is set inline and in a stylesheet, the inline one usually wins because it is more specific.
Exercise
Add an inline style that makes this text red.
<p ="color: red;">Hello</p>
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.