[html] Basic HTML - how to set relative path to current folder?

Lets say I am currently at: http://example.com/folder/page.html

Is it possible to create a relative link on this page that points to http://example.com/folder/ without specifying folder anywhere? (And using only HTML.)

UPDATE: As it turned out ./ works only in non-strict doctype mode, while . works in both modes, so it is still a better answer in my opinion :) Thanks everybody.

This question is related to html path

The answer is


For anyone who has found this thread, addressing relative paths has always created arguments over what is correct or not.

Depending on where you use the path to be addressed, it will depend on how you address the path.

Generally :

. and ./ do the same thing, however you wouldn't use . with a file name. Otherwise you will have the browser requesting .filename.ext as a file from the server. The proper method would be ./filename.ext.

../ addresses the path up one level from the current folder. If you were in the path /cheese/crackers/yummy.html, and your link code asked for ../butter/spread.html in the document yummy.html, then you would be addressing the path /cheese/butter/spread.html, as far as the server was concerned.

/ will always address the root of the site.


You can use

 ../

to mean up one level. If you have a page called page2.html in the same folder as page.html then the relative path is:

 page2.html.

If you have page2.html at the same level with folder then the path is:

  ../page2.html

<a href="./">Folder</a>

The top answer is not clear enough. here is what worked for me: The correct format should look like this if you want to point to the actual file:

 <a href="./page.html">

This will have you point to that file within the same folder if you are on the page http://example.com/folder/index.html


<html>
    <head>
        <title>Page</title>
    </head>
    <body>
       <a href="./">Folder directory</a> 
    </body>
</html>

You can use

 ../

to mean up one level. If you have a page called page2.html in the same folder as page.html then the relative path is:

 page2.html.

If you have page2.html at the same level with folder then the path is:

  ../page2.html

<html>
    <head>
        <title>Page</title>
    </head>
    <body>
       <a href="./">Folder directory</a> 
    </body>
</html>

You can use

 ../

to mean up one level. If you have a page called page2.html in the same folder as page.html then the relative path is:

 page2.html.

If you have page2.html at the same level with folder then the path is:

  ../page2.html

Both of the below seem to work

./

.


<a href="./">Folder</a>

<a href="./">Folder</a>

Both of the below seem to work

./

.


<html>
    <head>
        <title>Page</title>
    </head>
    <body>
       <a href="./">Folder directory</a> 
    </body>
</html>

You can use

 ../

to mean up one level. If you have a page called page2.html in the same folder as page.html then the relative path is:

 page2.html.

If you have page2.html at the same level with folder then the path is:

  ../page2.html

Both of the below seem to work

./

.


The top answer is not clear enough. here is what worked for me: The correct format should look like this if you want to point to the actual file:

 <a href="./page.html">

This will have you point to that file within the same folder if you are on the page http://example.com/folder/index.html


For anyone who has found this thread, addressing relative paths has always created arguments over what is correct or not.

Depending on where you use the path to be addressed, it will depend on how you address the path.

Generally :

. and ./ do the same thing, however you wouldn't use . with a file name. Otherwise you will have the browser requesting .filename.ext as a file from the server. The proper method would be ./filename.ext.

../ addresses the path up one level from the current folder. If you were in the path /cheese/crackers/yummy.html, and your link code asked for ../butter/spread.html in the document yummy.html, then you would be addressing the path /cheese/butter/spread.html, as far as the server was concerned.

/ will always address the root of the site.