October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Link CSS to HTML: A Step-by-Step Guide

Add a stylesheet link in the HTML head, match its href to the CSS file’s location, then save and reload to verify the styles.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To link an external CSS file to an HTML page, add a <link> element inside the page’s <head>, set rel="stylesheet", and point href to the CSS file. Save both files and reload the page in a browser to check the result.

1. Create the HTML and CSS files

Keep the files in one project folder so their locations are easy to check. For example, the folder might contain index.html and styles.css. Add a simple rule to styles.css so you can tell whether the stylesheet is working:

As an Amazon Associate I earn from qualifying purchases.

h1 {
  color: red;
}

2. Add the stylesheet link in the HTML head

Place this element between the opening and closing <head> tags in your HTML document:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>My page</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <h1>Hello, world!</h1>
</body>
</html>

rel="stylesheet" tells the browser the linked resource is CSS for this page. The href value gives the stylesheet’s location. Putting the link in <head> is the conventional, recommended organization for document links. MDN’s <link> reference explains the element’s attributes and placement.

#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

3. Make the href match the folder structure

The path in href must match where the CSS file actually sits relative to the HTML file. These examples assume the HTML document is in the project’s top-level folder:

CSS file location href value
Beside the HTML file styles.css
In a subfolder named styles styles/style.css
In a styles folder one level above the HTML file’s folder ../styles/style.css

Paths are interpreted from the HTML document’s location. Check each folder name, filename, and capitalization; a path that does not match the actual files will not load the stylesheet. MDN’s CSS getting-started tutorial shows the basic link and relative-path workflow.

4. Save and check the page

  1. Save the HTML file after adding the link.
  2. Save the CSS file after adding the test rule.
  3. Open the HTML file in a browser, or reload it if it is already open.
  4. Check whether the heading appears red. A conspicuous test style makes it easier to tell whether the connection works.

A linked stylesheet is fetched by the browser, parsed, and applied to matching elements in the document. See MDN’s explanation of how browsers load websites.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why use an external stylesheet?

External CSS keeps styling in a separate file that can be linked from multiple HTML pages. Two other methods are available, but they serve different needs:

Method Where the CSS goes Typical scope
External stylesheet A separate CSS file linked with <link rel="stylesheet" href="…"> Can be reused by multiple pages
Internal stylesheet A <style> block in the HTML document’s head That document
Inline style A style attribute on an HTML element The element carrying the attribute

An internal stylesheet can be convenient when keeping styles in a separate file is impractical. External CSS is usually the clearer choice when you want to reuse rules or keep presentation separate from markup. These are distinct ways of applying CSS, not alternate forms of the external link.

What to check if the styles do not appear

  • Confirm the link is in the page you opened. Make sure you edited the same HTML file that the browser is displaying.
  • Check the path and spelling. Compare the href value with the CSS file’s actual folder and filename, including capitalization.
  • Save both files. Unsaved changes are not available for the browser to load.
  • Reload the page. Then check the obvious test rule again.
  • Check the selector and HTML. The test rule applies only if the page contains a matching <h1> element.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Optional link attributes

For an ordinary CSS file, type="text/css" is unnecessary; MDN recommends omitting it. The rel value is important because a <link> element can describe other relationships, such as a site icon. A stylesheet can also use a media condition for a particular context, such as print, but neither attribute is needed for the basic setup. See MDN’s link-element documentation for details.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.