Episode 6 of 53

External Style Sheets

Learn how to create and link external CSS files — the best practice for real projects.

External stylesheets are the recommended way to add CSS to your projects. You write your CSS in a separate .css file and link it to your HTML.

Creating an External Stylesheet

Create a file called styles.css (or any name with a .css extension):

/* styles.css */
body {
    font-family: Arial, sans-serif;
    background-color: #f5f5f5;
    color: #333;
}

h1 {
    color: #2c3e50;
    text-align: center;
}

p {
    line-height: 1.6;
    margin-bottom: 1rem;
}

Linking to Your HTML

Use the <link> tag in the <head> section of your HTML file:

<head>
    <link rel="stylesheet" href="styles.css">
</head>

Why External Stylesheets?

  • Reusability — one stylesheet can be shared across many HTML pages
  • Caching — the browser downloads the CSS file once and caches it
  • Separation of concerns — HTML for content, CSS for presentation
  • Maintainability — change your site's appearance by editing one file

File Organization

A typical project structure:

project/
├── index.html
├── about.html
├── css/
│   └── styles.css
└── images/
    └── logo.png

For the rest of this course, we will use external stylesheets.