How can I link to html pages if they are in same or different folders without writing full path?
14 Answers
Within the same folder, just use the file name:
<a href="thefile.html">my link</a>
Within the parent folder's directory:
<a href="../thefile.html">my link</a>
Within a sub-directory:
<a href="subdir/thefile.html">my link</a>
-
1Add to that the addition of joeylange and you've got yourself the answer. :) – Kriem May 26 '09 at 13:24
-
1@AkshayVijayJain Yes and no. Super directory is "up one level". Sub directory is "down one level" – TylerH Aug 10 '18 at 19:45
-
The first one is not working on GitHub pages. Many years later – mLstudent33 Aug 04 '23 at 00:37
Also, this will go up a directory and then back down to another subfolder.
<a href = "../subfolder/page.html">link</a>
To go up multiple directories you can do this.
<a href = "../../page.html">link</a>
To go the root, I use this
<a href = "~/page.html">link</a>

- 538
- 3
- 10
In addition, if you want to refer to the root directory, you can use:
/
Which will refer to the root. So, let's say we're in a file that's nested within a few levels of folders and you want to go back to the main index.html:
<a href="/index.html">My Index Page</a>
Robert is spot-on with further relative path explanations.

- 2,873
- 2
- 17
- 7
You can go up a folder in the hierarchy by using
../
So to get to folder /webroot/site/pages/folder2/mypage.htm from /webroot/site/pages/folder1/myotherpage.htm your link would look like this:
<a href="../folder2/mypage.htm">Link to My Page</a>

- 178,213
- 47
- 333
- 501
use the relative path
main page might be: /index.html
secondary page: /otherFolder/otherpage.html
link would be like so:
<a href="/otherFolder/otherpage.html">otherpage</a>

- 33,810
- 26
- 104
- 151
If you'd like to link to the root directory you can use
/
, or /index.html
If you'd like to link to a file in the same directory, simply put the file name
<a href="/employees.html">Employees Click Here</a>
To move back a folder, you can use
../
To link to the index page in the employees directory from the root directory, you'd do this
<a href="../employees/index.html">Employees Directory Index Page</a>

- 94
- 1
- 4
I would caution you: if you are using absolute paths, then your application cannot be installed in a "subdirectory" of the server!
eg, http://yourserver.com/yourapp may work, but http://myserver.com/apps/yourapp will not!

- 25,975
- 33
- 97
- 127
Short answer:
. is for current directory
.. is for upper directory as in cd ..
command on shell.
Simple yet tricky, I write this answer primarily for myself not to forget next time.
ademSite/
├── index.html
└── style.css
The link to CSS in index.html
:
<link rel="stylesheet" href="style.css">
or
<link rel="stylesheet" href="./style.css">
ademSite/
├── index.html
└── stylefiles
└── style.css
This case it should be:
<link rel="stylesheet" href="stylefiles/style.css">
or <link rel="stylesheet" href="./stylefiles/style.css">
├── html
│ └── index.html
└── stylefiles
└── style.css
In this case path must be:
<link rel="stylesheet" href="../stylefiles/style.css">
Use
../
For example if your file, lets say image is in folder1
in folder2
you locate it this way
../folder1/folder2/image

- 3,541
- 3
- 38
- 67

- 57
- 3
href="./page.htm" for the same directory
href="../page.htm" parent directory
href="~/page.htm" root directory or the upper most dir.

- 1,170
- 14
- 16
Answer below is what I created to link html contents from another shared drive to the html page I would send out to managers. Of course, the path is relative to your using, but in my case, I would just send them the html, and everything else that is updated from load runner dynamically would be updated for me. Saves tons of paper, and they can play with the numbers as they see fit instead of just a hard copy this way.
SRC="file://///shareddrive/shareddrive-folder/username/scripting/testReport\contents.html" NAME="contents_frame" title="Table of Contents"

- 13,485
- 8
- 55
- 61
For ASP.NET, this worked for me on development and deployment:
<a runat="server" href="~/Subfolder/TargetPage">TargetPage</a>
Using runat="server"
and the href="~/"
are the keys for going to the root.

- 70
- 1
- 8
This worked for me <a href="preferedfile name.html">to be clicked <a/>

- 27,856
- 27
- 95
- 103

- 9
- 1
When I Was creating a webpage, I found out that With moving Html files to different Folders, It changes the paths of the images, videos, music, PDF files, etc. With them, you have to go out of the file the HTML is located in, with the
../HTML
. Then when your out, depending on where your page content is, insert,
<a href="Meme/WP/Chipmunk.html">Chipmunk Memes</a>
*/ This is where the HTML is located ^^^^^^ */
<img class="demo cursor" src="../6.png" width="100" height="50" onclick="currentSlide(6)" alt="Sasha Having Some Fun">
*/ This is where the images are located. The "../6.png" is the image file, and it is located one directory back. */
-
As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 27 '22 at 01:23