Skip to content

CSS Tutorial Getting Started

Three Ways to Add CSS to a Page

Lesson 5 of 182 2 min read By Deepak Paswan Updated Oct 4, 2026

There are three places you can put CSS. They all work. They are not equally good.

1. Inline CSS

You write the styles inside an element’s style attribute.

index.html
HTML
<p style="color: green; font-size: 20px;">Styled with an inline style.</p>

It only affects that one element and it beats most other rules. It is handy for a quick test or for a value that is set by code, and awkward for everything else.

2. Internal CSS

You put a <style> element inside the page, normally in the <head>.

index.html
HTML
<style>
  p { color: green; font-size: 20px; }
</style>
<p>Styled with an internal stylesheet.</p>
<p>Every paragraph on this page is affected.</p>

This is good for a single page or a demo. Every example in this course uses it so you can see the HTML and the CSS together.

3. External CSS

You write the CSS in its own file, for example style.css, and link to it from each page.

index.html
HTML
<head>
  <link rel="stylesheet" href="style.css">
</head>
style.css
CSS
p {
  color: green;
  font-size: 20px;
}

One file can style every page of a website. The browser also downloads it once and reuses it, which makes later pages load faster.

Which one should you use?

MethodGood forWatch out for
InlineQuick tests, values set by codeHard to maintain, hard to override
InternalOne page, demos, small experimentsRepeated on every page
ExternalReal websitesOne extra file to load
info
Rule of thumb
Use an external stylesheet for a real site. Reach for the other two only when you have a reason.
warning
Wrong file path
If the page is unstyled, open the browser’s developer tools and check the Network tab. A red style.css means the href does not point to the file.

Exercise: move a style out

Take <p style="color: green;">Hello</p> and rewrite it so the color comes from a <style> element instead of the attribute.

Show a possible solution
index.html
HTML
<style>
  p { color: green; }
</style>
<p>Hello</p>