Linking CSS Files

Linking CSS files means connecting an external CSS file to your HTML document so you can apply styles to your webpage.

What is Linking CSS

Instead of writing styles inside HTML, you create a separate .css file and link it to your HTML file. This keeps your code clean and organized.

Using the Link Tag

The <link> tag is used inside the <head> section of your HTML file to connect the CSS file.

Example of Linking CSS File

<head> <link rel=”stylesheet” href=”style.css”> </head>

Understanding Attributes

rel=”stylesheet” tells the browser that it is a CSS file.
href=”style.css” specifies the path to the CSS file.

CSS File Example

Inside the style.css file:

body {
background-color: lightgray;
}

p {
color: blue;
}

File Location

If your CSS file is in the same folder, use just the file name.
If it is in another folder, include the folder path.

Example with Folder

<link rel=”stylesheet” href=”css/style.css”>

Why Use External CSS

Keeps HTML clean and readable.
Allows reuse of styles across multiple pages.
Makes updates easier by changing one file.

Summary

Linking CSS files connects external styles to your HTML page using the <link> tag. It is the best method for managing styles in modern web development.

Home ยป Advanced HTML > HTML + CSS Integration >Linking CSS Files