This is a very basic html question, but I can't seem to locate the answer.
I have a local file located here:
/Users/Me/Desktop/Main/June/foo.txt
In an .html document located within the /Main directory, I can link to the foo.txt
file using the full path:
<a href="file:///Users/Me/Desktop/Main/June/foo.txt">Full Path Link</a>
I would like to use relative paths to link to foo.txt
. Does anyone know how to create a relative path link to this foo.txt
file?
I tried the code below and a number of similar permutations, but I can't seem to successfully write the relative path link for this local file.
<a href="file:///../June/foo.txt">Relative path Link</a>
Thanks in advance. Any help is appreciated.
If you're using Windows 10, hold down Shift on your keyboard and right-click on the file, folder, or library for which you want a link. If you're using Windows 11, simply right-click on it. Then, select “Copy as path” in the contextual menu.
Relative pathRelative paths make use of two special symbols, a dot (.) and a double-dot (..), which translate into the current directory and the parent directory. Double dots are used for moving up in the hierarchy. A single dot represents the current directory itself.
To link pages using relative URL in HTML, use the <a> tag with href attribute. Relative URL is used to add a link to a page on the website. For example, /contact, /about_team, etc.
Remove the file:///
part to have just ../June/foo.txt
.
This should help you out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With