Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Connecting CSS to HTML | Getting Started with CSS
CSS Fundamentals

bookConnecting CSS to HTML

Swipe to show menu

How CSS Is Added to HTML

There are three ways to apply CSS to an HTML document:

  1. Inline styles;
  2. Embedded style sheets;
  3. External style sheets.

Each method works differently and is used in different situations.

Inline Styles

Inline styles are written directly inside an HTML element using the style attribute.
Example:

index.html

index.html

copy

This style applies only to this specific element.

Inline styles are quick to use, but they are not reusable and are difficult to manage in larger projects.

Embedded Style Sheet

An embedded style sheet is written inside <style> tags in the <head> section of an HTML document.
Example:

index.html

index.html

copy

This method applies styles to the entire page, but only within this single HTML file.

It is useful for small or standalone pages.

External Style Sheet

External CSS stores styles in a separate .css file and connects it to HTML using the <link> tag.
Example:

index.html

index.html

styles.css

styles.css

copy

This method allows styles to be reused across multiple pages.

It is the preferred and most scalable approach for real projects.

Note
Summary

Inline styles: applied directly to elements, but not reusable.

Embedded style sheet: applied inside the <head>, affects only one page.

External style sheet: stored in a separate .css file, reusable and recommended for most projects.

In this course, we will primarily use external style sheets.

question mark

What ways of adding styles to the HTML document exist?

Select all correct answers

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 2

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Section 1. Chapter 2
some-alt