Linking CSS File on a HTML Document In Same Directory On my Hard Disk (Windows)

While the accepted answer is not wrong it's over-complicate things.

If your file is https://www.google.com/b/bananacream/bananas/index.html

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

Will try to get https://www.google.com/style.css

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

Will try to get https://www.google.com/b/bananacream/bananas/style.css as nothing indicate what folder the file is located in it will use the same folder as the requesting file.

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

Will try to get https://www.google.com/b/bananacream/bananas/style.css as ./ tell that the file is located in the same folder as the requesting file.

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

Will try to get https://www.google.com/b/bananacream/style.css as ../ tell that the file is located in the previous folder as the requesting file.

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

Will try to get https://www.google.com/b/style.css as ../../ tell that the file is located in the folder two steps before as the requesting file.


A general complete answer:

to address through existing folder, use:

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

to address through parent folder, use:

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

to address through the internet( CDN ) use:

<link
  rel="stylesheet"
  href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3./css/bootstrap-theme.min.css"
  >

to address through your hard drive use:

<link rel="stylesheet" href='file:///C:/mystyles.css'>

Use <link rel="stylesheet" type="text/css" href="./styles.css" /> instead. Note: href="/styles.css" changed to href="./styles.css", which is current directory of your script.

Tags:

Windows

Html

Css