The Basic Method: Using the Link Tag
To link a stylesheet to an HTML page, place a <link> tag in the <head> section of your HTML document. The tag tells the browser where to find your CSS file and how to use it. Here is the exact syntax:
<link rel="stylesheet" href="styles.css">
The rel attribute tells the browser this is a stylesheet. The href attribute points to the location of your CSS file. If your stylesheet is in the same folder as your HTML file, you only need the filename. If it is in a subfolder called css, write href="css/styles.css". If it is on another website, write the full web address: href="https://example.com/styles.css".
Place the link tag between your opening and closing <head> tags, usually near the top, after the <title> tag. The browser reads the head section before displaying the page, so your styles load before the content appears.
Key Takeaways
- The <link> tag goes in the <head> section, not the body, and uses rel="stylesheet" and href to point to your CSS file.
- Relative paths like href="styles.css" work when the CSS file is in the same folder as your HTML file, while href="css/styles.css" works for subfolders.
- You can link multiple stylesheets to one HTML page by using multiple <link> tags, and the browser applies them in the order they appear.
- External stylesheets are preferred over inline styles because they keep your HTML clean, make updates easier, and let you reuse the same stylesheet across many pages.
Where to Place the Link Tag in Your HTML
The <link> tag must go inside the <head> section of your HTML document, not in the body. The head section is where you put information about the page that does not display as visible content — things like the page title, character encoding, and stylesheets.
A typical HTML structure looks like this:
<!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>
The browser reads the head section first, loads your stylesheet, and then displays the body content. If you put the link tag in the body by mistake, the browser may still load the stylesheet, but it is not may provide to work correctly in all situations. Always place it in the head.
Relative Paths vs. Absolute Paths
A relative path describes where your CSS file is located relative to your HTML file. If both files are in the same folder, use just the filename: href="styles.css". If your CSS file is in a subfolder, include the folder name: href="css/styles.css" or href="assets/stylesheets/main.css".
An absolute path is the complete web address of the file. Use this when linking to a stylesheet hosted on a different website or a content delivery network (CDN). For example: href="https://cdn.example.com/bootstrap.css". Absolute paths always start with http:// or https://.
For most projects, relative paths are simpler and more portable. If you move your project folder to a different location, relative paths still work. Absolute paths break if the server or domain changes. Use absolute paths only when you intentionally want to load a stylesheet from an external source that you do not control.
Linking Multiple Stylesheets
You can link as many stylesheets as you need by adding multiple <link> tags. The browser applies them in the order they appear in your HTML. If two stylesheets define the same style, the one that appears later in the head wins.
A common pattern is to link a reset stylesheet first, then a framework stylesheet, then your own custom styles:
<link rel="stylesheet" href="reset.css"><link rel="stylesheet" href="bootstrap.css"><link rel="stylesheet" href="styles.css">
This order matters. The reset stylesheet removes default browser styling, the framework provides common components, and your custom stylesheet overrides both with your own rules. If you reversed the order, your custom styles would be overridden by the framework, which is usually not what you want.
External Stylesheets vs. Inline Styles
An external stylesheet is a separate CSS file linked with the <link> tag. An inline style is CSS written directly in an HTML tag using the style attribute, like <p style="color: red;">. External stylesheets are almost always the better choice.
External stylesheets keep your HTML file clean and readable. They let you update the look of your entire website by editing one CSS file instead of changing dozens of HTML files. They also let the browser cache the stylesheet, so repeat visitors do not have to download it again. Inline styles do none of these things and make your HTML harder to maintain.
You can also write CSS directly in your HTML file using a <style> tag in the head section, but this is also less flexible than an external stylesheet. Use external stylesheets for any project larger than a single test page.
Checking If Your Stylesheet Linked Correctly
Open your HTML page in a browser and right-click anywhere on the page. Select Inspect or Inspect Element to open the browser's developer tools. Click the Elements or Inspector tab and look at the <head> section. You should see your <link> tag there.
If your styles are not showing up, check the Network tab in developer tools. Reload the page and look for your CSS file in the list. If it shows a red X or a 404 error, the browser could not find the file. Check that the filename and path in your href attribute are spelled correctly and match the actual location of your CSS file. File paths are case-sensitive on most servers, so styles.css is different from Styles.css.
If the file loads but your styles still do not appear, the problem is usually in your CSS rules, not the link tag. Check your CSS file for syntax errors or rules that conflict with other stylesheets.
Frequently Asked Questions
Can I link a stylesheet from a different website?
Yes. Use the full web address in the href attribute, starting with https://. Many popular libraries like Bootstrap and Google Fonts are hosted on CDNs specifically so you can link them this way. However, if that website goes down, your stylesheet will not load.
What is the difference between rel="stylesheet" and other rel values?
The rel attribute tells the browser what kind of relationship the linked file has to your page. rel="stylesheet" means it is a CSS file that should be applied to the page. Other values like rel="icon" or rel="alternate" describe different types of linked resources. For stylesheets, always use rel="stylesheet".
Do I need to close the link tag with </link>?
No. The <link> tag is a self-closing tag, meaning it does not have a closing tag. You can optionally write it as <link ... /> with a forward slash at the end, but modern HTML does not require it. Both <link rel="stylesheet" href="styles.css"> and <link rel="stylesheet" href="styles.css" /> are correct.
What happens if I link a stylesheet that does not exist?
The browser will try to load it, fail silently, and continue displaying your page without those styles. Your HTML will still work, but it will look unstyled. The browser will not show an error message on the page itself, though you can see the 404 error in the developer tools Network tab.
Can I link stylesheets in the body section?
Technically the browser may load it, but it is not correct HTML and can cause unexpected behavior. The <link> tag belongs in the <head> section. If you put it in the body, the browser might not apply the styles consistently, and the page may flicker as styles load late. Always put stylesheet links in the head.