The basic way to connect CSS to HTML

You connect a CSS file to an HTML document by adding a single line inside the <head> section of your HTML file. That line tells the browser where to find your CSS file and what to do with it. Without this link, your HTML file won't know the CSS file exists, and your page will display with no styling — just plain text and default browser formatting.

The line you add looks like this:

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

This tells the browser three things: that you're linking to a stylesheet, what kind of relationship that is, and where the file is located. The href attribute is the path to your CSS file — it can be a filename if the CSS file is in the same folder as your HTML file, or a full path if it's in a different location.

Key Takeaways

  • The <link> tag goes inside the <head> section of your HTML file, not in the body.
  • The href attribute tells the browser where to find your CSS file — use just the filename if both files are in the same folder.
  • If your CSS file is in a subfolder, use a path like href="css/styles.css" or href="./css/styles.css".
  • You can link multiple CSS files to one HTML document by adding multiple <link> tags.

Where the link tag goes in your HTML

The <link> tag must be placed between the opening <head> tag and the closing </head> tag. The head section is where you put information about the page that isn't displayed as content — things like the page title, character encoding, and links to external files.

Here's what a basic HTML structure looks like with the CSS link in the right place:

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>My Page</title> <link rel="stylesheet" href="styles.css"> </head> <body> <h1>Hello World</h1> </body> </html>

Notice that the <link> tag comes after the <meta> and <title> tags but before the closing </head>. The order of multiple <link> tags matters if your CSS files have conflicting rules — the browser applies them in the order it reads them, so the last one wins.

Using the correct file path

The href attribute needs to point to where your CSS file actually is. If you put the wrong path, the browser won't find the file and your styles won't load.

If your HTML file and CSS file are in the same folder, use just the filename:

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

If your CSS file is in a subfolder called css, use a relative path:

<link rel="stylesheet" href="css/styles.css">

If your CSS file is in a parent folder (one level up), use two dots and a slash:

<link rel="stylesheet" href="../styles.css">

You can also use an absolute path if your CSS file is hosted on the web — for example, a font stylesheet from Google Fonts:

<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto">

Linking multiple CSS files

You can link as many CSS files as you need to a single HTML document. Add a separate <link> tag for each file, all in the <head> section.

<link rel="stylesheet" href="reset.css"> <link rel="stylesheet" href="styles.css"> <link rel="stylesheet" href="responsive.css">

The order matters. If two CSS files contain rules for the same element, the browser uses the rule from whichever file is linked last. Many developers link a reset file first (which removes default browser styling), then their main stylesheet, then any specialized stylesheets for specific features.

Checking if your CSS file is actually loading

If you've added the link but your styles still aren't showing up, open your browser's developer tools to see what's happening. In most browsers, press F12 or right-click on the page and select "Inspect" or "Inspect Element."

Look at the Network tab to see if the CSS file loaded successfully. If it shows a red X or a 404 error next to your CSS filename, the browser couldn't find the file — which means your path is wrong. Double-check that the filename and folder structure match exactly. Paths are case-sensitive on some servers, so Styles.css is different from styles.css.

You can also look at the Elements or Inspector tab and click on an element on the page. The Styles panel will show you which CSS rules are being applied to that element and which file they came from. If your CSS file isn't listed at all, the link tag isn't working.

Common mistakes to avoid

Putting the <link> tag in the wrong place is the most common error. It must go in the <head>, not in the <body>. If you put it in the body, the browser may still load the CSS, but it can cause the page to flicker or render slowly because the styles load after some content has already been displayed.

Misspelling the filename or using the wrong path is the second most common problem. If your file is named style.css but you link to styles.css, it won't load. Check that uppercase and lowercase letters match, and that folder names are spelled correctly.

Forgetting the rel="stylesheet" attribute will also break the link. The browser needs to know that this is a stylesheet, not some other kind of resource. Without it, the CSS file won't be treated as styling information.

Frequently Asked Questions

Can I put the link tag in the body instead of the head?

Technically the browser will still load the CSS, but it's not the right place and can cause problems. The head is where the browser expects to find information about the page before it starts rendering content. Putting the link in the body can make the page flicker or display unstyled content briefly before the CSS loads.

What's the difference between href="styles.css" and href="./styles.css"?

They do the same thing when the files are in the same folder. The dot-slash notation ./ explicitly means "in the current folder," while leaving it out is assumed to mean the same thing. Use whichever one your team prefers — both work.

Do I need to add anything else to make the CSS link work?

No. The <link> tag is all you need. Make sure the CSS file actually exists at the path you specified, and make sure your HTML file is saved. After that, refresh your browser to see the styles load.

Can I link to a CSS file on another website?

Yes, you can use a full URL in the href attribute, like href="https://example.com/styles.css". This is common for fonts and icon libraries. However, if that website goes down or changes the file, your page will lose those styles, so it's usually better to host CSS files on your own server.

What if I have multiple CSS files and they conflict with each other?

The CSS file linked last wins. If reset.css sets all text to black and styles.css sets headings to blue, the heading will be blue because styles.css is linked after reset.css. This is called the cascade, and it's a core feature of CSS. You can also use specificity and the !important flag to control which rules take priority.