Adding CSS

Three Ways to Insert CSS

MethodWhereBest for
External<link rel="stylesheet" href="styles.css"> in the headevery real website
Internal<style> element in the headsingle pages, demos
Inlinestyle="..." attribute on one elementquick 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 &lt;style&gt; element</h1>
<h1 style="color:#04AA6D;">Overridden by an inline style</h1>

</body>
</html>

Result