Aral Code

Getting Started Lesson 3 of 33

How to Add CSS — Inline, Internal and External Style Sheets

The three ways to add CSS to an HTML page — inline styles, the style element, and an external .css file — and when to use each one.

There are three places you can write CSS. They all work, but each one fits a different situation. Knowing which to use will keep your projects neat.

1. Inline styles

An inline style goes directly on an element, inside the style attribute:

Example Inline styles
<h1 style="color: #CE1126; text-align: center;">Happy Independence Day!</h1>
<p style="font-size: 20px;">June 12, 1898</p>

Inline styles are quick, but they only affect that one element. If you have twenty buttons, you'd have to copy the same style twenty times, and change all twenty if your design changes.

Use it for: quick tests, or a one-time adjustment. In this course's earliest HTML lessons we used inline styles because you didn't know CSS rules yet.

2. Internal style sheet: the style element

An internal style sheet is a <style> element, usually placed inside the <head>. Its rules apply to the whole page.

Example An internal style sheet
<!DOCTYPE html>
<html>
<head>
  <style>
    body {
      font-family: Arial, sans-serif;
    }
    h1 {
      color: #0038A8;
    }
    .price {
      color: #1d7a43;
      font-weight: bold;
    }
  </style>
</head>
<body>
  <h1>Bigasan sa Palengke</h1>
  <p>Dinorado: <span class="price">₱58/kilo</span></p>
  <p>Sinandomeng: <span class="price">₱52/kilo</span></p>
  <p>NFA rice: <span class="price">₱40/kilo</span></p>
</body>
</html>

One rule (.price) styles all three prices. Much better than three inline styles.

Use it for: single-page projects, quick experiments, and all the examples on this site.

3. External style sheet: a .css file

An external style sheet is a separate file that ends in .css, linked from the HTML with a <link> element in the <head>:

<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <h1>Welcome to our class website</h1>
</body>
</html>
/* style.css — no <style> tags here, just rules */
body {
  font-family: Arial, sans-serif;
  background: #f3f6f4;
}
h1 {
  color: #0f5c4d;
}

Every page that has the same <link> line gets the same design. Change style.css once, and the whole website updates. This is how almost every real website is built.

Use it for: any website with more than one page, including your class project.

A typical project folder

my-website/
├── index.html
├── about.html
├── contact.html
├── css/
│   └── style.css
└── images/
    └── logo.png

All three HTML pages link to the same file with <link rel="stylesheet" href="css/style.css">. Review File Paths in the HTML course if folders confuse you.

When styles disagree: which one wins?

What if the same element gets different instructions from different places? Generally:

  1. Inline styles beat rules in style sheets.
  2. Between internal and external style sheets, the rule that comes later in the page wins (if the selectors are equally specific).
Example Who wins?
<style>
  p { color: blue; }
  p { color: green; }   /* later — this one wins over blue */
</style>
<p>I am green, because the second rule comes later.</p>
<p style="color: red;">I am red, because inline styles beat the style sheet.</p>

This "who wins" system is the cascade in Cascading Style Sheets. There's more to it, and you'll learn it fully in the Specificity and the Cascade lesson.

Quick Quiz

Check what you learned. Walang grade ito, practice lang. 🙂

1. Which line correctly links an external style sheet?
2. Where should the <style> element of an internal style sheet usually go?
3. What should a .css file contain?
4. Your website has 10 pages. Which method is best?

By Sir Reyel · Last updated 2026-12-04