Sam Younes
Sam Younes

Reputation: 11

CSS stylesheet not linking to the HTML

I don't know why my CSS stylesheet and HTML files are not linking.

This is my code in the HTML file.

<head>
    <title>Website Sample</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="viewport" content="width = device-width, initial-scale = 1">
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="C:\Users\Sam\Desktop\web\style.css" />

</head>

This is the CSS

.section2 {
  height: 3000px;
  width: 100px;
  background-color: yellow;
}

Upvotes: 1

Views: 2479

Answers (3)

Falguni Panchal
Falguni Panchal

Reputation: 8981

Check this path,

You can't give the absolute path from your root, you need to pass the

relative path

Please check the link as below:

<link href="web/style.css" rel="stylesheet" />

Upvotes: 2

Amita
Amita

Reputation: 974

Kepp the css file in the same folder as the HTML file and then provide the css file name:

<link rel="stylesheet" type="text/css" href="style.css" />

Or provide relative path, supposing you keep css files in a folder named 'css', like :

<link rel="stylesheet" type="text/css" href="../css/style.css" />

Or like:

<link rel="stylesheet" type="text/css" href="~/css/style.css" />

where '~' symbolizes your root directory.

Upvotes: 2

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167162

You cannot use Windows style links. Change it to file:/// url:

<link rel="stylesheet" type="text/css" href="file:///C:/Users/Sam/Desktop/web/style.css" />

Also it is always better to give relative paths, instead of absolute, as it is flexible wherever it is hosted, plus helps when you want to migrate it.

<link rel="stylesheet" type="text/css" href="./style.css" />

An update to the current HTML Standards, it's not necessary to have type attribute for <link> and <script> tags. So you can further reduce it down to:

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

Upvotes: 4

Related Questions