agyanadda@gmail.com

How to Add CSS

CSS Basics 1 min read Updated Dec 1, 2026 Topic 3 of 39

There are three ways to add CSS to an HTML page.

1. External CSS (best)

Write styles in a separate .css file and link it in the <head>:

<link rel="stylesheet" href="style.css">

One file can style the whole website.

2. Internal CSS

Write styles inside a <style> tag in the <head>. Good for a single page.

3. Inline CSS

Write styles in the style attribute of one element: <p style="color:red">. Use it rarely — it is hard to maintain.

Which one wins?

If the same property is set in many places, inline beats internal and external styles. Between internal and external, the rule written last wins.

Example

Example — Internal and inline CSS HTML
<!DOCTYPE html>
<html>
<head>
<style>
  h2 { color: green; }
</style>
</head>
<body>
  <h2>Styled by internal CSS</h2>
  <h2 style="color: crimson;">Inline CSS wins here</h2>
</body>
</html>

The second heading uses an inline style, which overrides the internal rule.

Try it Now »

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which tag links an external stylesheet?

Exercise 2 True / False

Inline styles override internal and external styles.

Exercise 3 Fill in the Blank

Inline CSS is written in the ___ attribute.

Frequently Asked Questions

Inside the <head> of the page, so styles load before the content is shown.