Learning how to link CSS to HTML begins with just one line: add <link rel="stylesheet" href="styles.css"> inside your page’s <head>. Next, save your style sheet (styles.css) and the browser will read that file and apply all applicable rules to your HTML.
Most people struggle with the file path. A stylesheet beside your HTML requires a different file path than a stylesheet inside a folder. Below is a step-by-step walkthrough of a functional example, explaining those file paths, and identifying common issues you might experience if your page continues to look plain.

How to link CSS to HTML in three steps
For many websites (especially small ones), an external style sheet is a good place to begin. An external style sheet allows you to keep your code/markup in one file (the html), and your design rules in another. Therefore, multiple pages can utilize the same style sheet.
- Create a file named
styles.cssin your project. - Add the line below to the HTML document’s
<head>, before</head>. - Save both files, open the HTML page, and refresh it.
<link rel="stylesheet" href="styles.css">
The rel="stylesheet" attribute defines the relationship between the HTML and CSS files — specifically that this file contains the design rules. The href attribute specifies the location where the browser should go looking for it. Use href for this address, rather than src.
WHATWG’s definition of the stylesheet link type describes the connection. A typical stylesheet link does not require JavaScript.
There is no need to include type="text/css" in your HTML either. Additionally, since <link> is a void element, there is no closing </link> tag. All of your CSS declarations should remain in your CSS file, outside of any <style> tags.
Try this complete HTML and CSS example
Begin by creating two files in the same directory: index.html and styles.css. Enter the first block of code into the HTML file and enter the second block of code into the style sheet. Be sure to retain the names of these files as they appear above.
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My first styled page</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<main class="card">
<h1>Hello, CSS!</h1>
<p>This page loads its design from another file.</p>
</main>
</body>
</html>
styles.css
body {
margin: 0;
padding: 2rem;
font-family: system-ui, sans-serif;
background: #eef4f8;
color: #172b3a;
}
.card {
max-width: 40rem;
margin: 2rem auto;
padding: 2rem;
background: #ffffff;
border-radius: 1rem;
}
h1 {
color: #0b6371;
}
When you run your code, you should see a white rectangle on a pale background, with a teal heading. After changing the colour of the heading, saving your CSS file, and reloading the page, you should see the new color. If you see the new color, that indicates that your HTML/CSS files are linked properly.
Note that while the paragraph remained unchanged, i.e., it was simply a standard paragraph (HTML), the CSS controlled its visual display — thus, it remained a paragraph describing content, whereas the HTML controlled its semantic meaning. For further assistance with determining between paragraphs and forced breaks, refer to our guide to adding an HTML new line.
How to link CSS to HTML in another folder
A browser will resolve a relative path for a style sheet based upon the base URL of the HTML document. Without a <base> element present in a basic page structure, the base URL will simply be that of the page itself. Before you determine how to construct your path, determine where your HTML file resides.

| HTML file | CSS file | Use this href |
|---|---|---|
/index.html |
/styles.css |
styles.css |
/index.html |
/css/styles.css |
css/styles.css |
/pages/about.html |
/css/styles.css |
../css/styles.css |
| Any page on the same site | /css/styles.css at the site root |
/css/styles.css |
As indicated previously, ../ refers to moving back up one directory level. Anytime you use a leading slash (/), it denotes the beginning of the website root. There is a significant difference in terms of deployment to a subdirectory versus deploying directly under the website root. While /css/styles.css references the domain root, it would not necessarily reference your project directory.
Always use forward slashes (/) regardless of whether you are running on Windows or Mac. A local path to your computer (such as a drive letter path) will not be recognized by users who access your site via their browsers. Always double-check your capitalization as well; Styles.css and styles.css could represent two completely different files depending upon how they were named on your web server.
Paths for background images within CSS start from the stylesheet’s URL, rather than the HTML page’s URL. For example, url("../images/banner.webp") uses that starting point. Based on where your external style sheet resides, a browser will resolve paths to background images from the URL of that style sheet. As a result, moving your external style sheet around could potentially cause problems with accessing its associated background images regardless of how accurate your HTML link tag is constructed.
External, internal, or inline CSS?
An external file is not the only method for applying styles to elements. Once you’ve determined whether you’re going to reuse site-wide styles or perform some small experiment that relates to specific pages, you’ll want to consider how to link CSS to HTML.
| Method | Where it goes | Useful for |
|---|---|---|
| External CSS | A separate file loaded with <link> |
Shared website styles |
| Internal CSS | A <style> element in the page’s head |
A small standalone example |
| Inline CSS | An element’s style attribute |
A narrow one-off declaration |
Internal CSS example
<style>
h1 { color: #0b6371; }
</style>
Place this style element inside <head>. You don’t need a separate stylesheet for this single rule. However, placing this rule into every page quickly becomes impractical.
Inline CSS example
<h1 style="color: #0b6371;">Hello, CSS!</h1>
The rule directly affects only the heading element. Although possible, maintaining separate class-based rules in an external file makes more sense for larger sites. If every matching heading needs the same new colour, you can modify that one shared rule.
Link multiple CSS files without confusion
You can load multiple style sheets into your HTML document. For example, you can load your generic rules first and then load a secondary style sheet containing page-specific rules.
<link rel="stylesheet" href="css/base.css">
<link rel="stylesheet" href="css/contact.css">
Only later-declared rules “win” when previous cascading criteria “tie”. Those criteria include importance, cascade layers, and selector specificity. The order of the link tags matters; however, download speed does not affect which rule prevails.
You can also limit an externally loaded style sheet to print:
<link rel="stylesheet" href="css/print.css" media="print">
What about @import?
External CSS documents can load additional CSS documents using @import. You can place this statement at the top of any external CSS document prior to other CSS styling statements:
@import url("layout.css");
body { margin: 0; }
The W3C provides the ordering requirements for imported style sheets, including exceptions for @charset and layer-order statements. Direct HTML links make the files easier to find in this beginner project. Imports discovered within another stylesheet can create extra request dependencies.
How to link CSS to HTML when styles will not load
Inspecting an unstyled page does not provide sufficient evidence to conclude why the page looks unstyled. First, verify that the browser successfully retrieved the style sheet referenced in your link element. Next, verify that you inspected the element(s) intended to be styled.

- Open the browser’s developer tools and select the Network panel.
- Reload the page with the panel open, then filter for CSS files.
- Select your stylesheet and inspect its requested URL, status, and response.
- Inspect the heading in the Elements panel and find your rule in Styles.
The Network Reference provided by Chrome DevTools provides guidance regarding how to record requests made during network activity as well as disable caching. To ensure that you receive an updated version of requests from your server while using this option, keep DevTools open.
Common CSS loading problems
| What you find | What to check next |
|---|---|
| No stylesheet request | Check the link element, its rel value, and the page you opened. |
| A 404 response | Correct the path, filename, or letter case. |
| HTML in the CSS response | Check for a login page, fallback route, or error page at that address. |
| A MIME-type error | Serve real CSS with the text/css Content-Type. |
| Your rule is crossed out | Inspect the winning declaration before changing specificity. |
| Only recent edits are missing | Check the browser cache, then any site or CDN cache. |
Additionally, confirm that there isn’t something blocking application of the style sheet (i.e., disabled stylesheet), an unused media query condition or that there wasn’t some error related to Content Security Policy reported in the browser console. Simply receiving an HTTP status indicating success doesn’t mean that the browser actually applied the style sheet.
If you believe you are experiencing problems due to a stale cached version in Edge and wish to clear the Microsoft Edge cache, please visit our guide for steps. Before performing any tests, please save any outstanding work; otherwise, you risk losing modifications. Verify that your editor didn’t rename your file styles.css.txt.
Common questions about linking CSS
How do I link CSS to HTML in Visual Studio Code?
To practise how to link CSS to HTML in VS Code, put the same link element inside the HTML document’s head. VSCode does not require any special commands/linking syntax for establishing connections between CSS and HTML files. Once you’ve saved both files, reload your page within a browser. Utilizing a local development server will assist you with verifying proper website-style paths.
Can several HTML pages use one CSS file?
Yes. Add a link element referencing your CSS file into each HTML document. Modify relative paths for pages located in various directories; alternatively, specify an appropriate root-relative path if you intend to host the entire site from its root.
Can I link a stylesheet hosted on another website?
Yes. Your HTML link can use an absolute HTTPS URL for sourcing a stylesheet (as long as it is hosted on a trusted source). Ensure the source is available online; review any security policies you have implemented regarding data integrity or cross-origin restrictions you have added as well. Since hosting your own design file along with your project grants you complete control over future revisions, we highly recommend doing so.
Do I need JavaScript or a framework?
No. These examples operate strictly on plain HTML & CSS. Depending on how frameworks implement loading stylesheets via build tools may differ from what is demonstrated here.
What is the quickest check before I finish?
Once you learn how to link CSS to HTML, we encourage you to attempt modifying some aspect of the visual representation of one element on your page. Upon making any modification(s), verify that:
- The desired URL loads the proper CSS document.
- The selector(s) included in said CSS document accurately correspond to the elements intended to be modified.
- Said rule(s) prevail over others when viewed in DevTools.
These checks confirm the connection from your file to the rendered page.