Home > Web Front-end > CSS Tutorial > How to Properly Link a CSS File to an HTML File?

How to Properly Link a CSS File to an HTML File?

Mary-Kate Olsen
Release: 2024-12-02 01:48:09
Original
689 people have browsed it

How to Properly Link a CSS File to an HTML File?

How to Link a CSS File from an HTML File

You encounter an issue when linking a CSS file from an HTML file. The issue can be resolved by ensuring the following:

Set the Correct Attribute Value

In the HTML file, the rel attribute's value should be set to "stylesheet" instead of "Hope this works." The corrected code would be:

<link rel="stylesheet" href="newcssstyle.css" type="text/css">
Copy after login

Ensure File Placement

The "newcssstyle.css" file must be in the same directory as the HTML file it references. If it's in a subfolder, adjust the href attribute path accordingly.

Example Directory Structures and Relative File Paths

Case 1: CSS file is in a subfolder named "Stylesheets."

Parent Directory Name
   index.html
   Stylesheets
      newcssstyle.css
Copy after login

HTML:

<link rel="stylesheet" href="Stylesheets/newcssstyle.css">
Copy after login

Case 2: CSS file is in a different subfolder named "Html_files."

Parent Directory Name
   Html_files
      index.html
   Stylesheets
      newcssstyle.css
Copy after login

HTML:

<link rel="stylesheet" href="../Stylesheets/newcssstyle.css">
Copy after login

Case 3: CSS file is in the same directory as the HTML file.

Parent Directory Name
   index.html
   newcssstyle.css
Copy after login

HTML:

<link rel="stylesheet" href="./newcssstyle.css">
Copy after login

The above is the detailed content of How to Properly Link a CSS File to an HTML File?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template