Careeroza
Adding CSS
Three Ways to Insert CSS
| Method | Where | Best for |
|---|---|---|
| External | <link rel="stylesheet" href="styles.css"> in the head | every real website |
| Internal | <style> element in the head | single pages, demos |
| Inline | style="..." attribute on one element | quick tests; avoid in production |
External CSS
<!-- index.html -->
<head>
<link rel="stylesheet" href="styles.css">
</head>/* styles.css */
body { background-color: lightblue; }
h1 { color: navy; margin-left: 20px; }Cascading Order
Example
When several styles target the same element, inline styles beat internal/external ones (more on this in the Cascade module):
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
h1 { color: tomato; }
</style>
</head>
<body>
<h1>Styled by the <style> element</h1>
<h1 style="color:#04AA6D;">Overridden by an inline style</h1>
</body>
</html>Result