views:

54

answers:

7

we can give the href like the following

<a href="images\image.png">

<a href="images/image.png">

<a href=".\images\image.png">

<a href="./images/image.png">

which is the recommended method... which doesnot have problem on any browser and on any web server....

leave the image type... consider the link\paths

and PLEASE explain why the specific one

+5  A: 

second and last one are correct. Backslash is not a good idea on the web. The ./ is nice but if you're using url rewrites your images won't play along nice.

I would personally prefer the second method, because you drop useless code (the ./), so saving a few bits ;-)

joggink
+2  A: 

These should do just fine:

<a href="images/image.png">...</a>
<a href="http://yourdomain.com/images/image.png"&gt;...&lt;/a&gt;

You could even use relative paths, like:

<a href="../images/image.png">...</a>
<a href="/images/image.png">...</a>
Druid
Seems like OP is asking about linking to images in the same directory structure, including the hostname is never a good idea in such cases.
teukkam
+2  A: 

Backslash character is not allowed in URL's except when URL encoded, so always use forward slashes (/). Also, the second and last example are identical, both point to files relative to the current directory. Use whichever you like.

Tatu Ulmanen
A: 

like joggink said, first one and last one is correct. Why? there is no why, it's just the way the link path should look like. not only for links put for other paths like the img tag

krike
A: 

The forward slash is used for file paths in Unix & Linux, whilst the backward slash is used for file hierachy on windows. For internet URLS forward slash is used.

So it depends on what the URL is pointing to and what server your running on.

Raynos
A: 

Use the following if possible:

<a href="/images/image.png" />

The reason being that using \ is not legitimate for directories and using relative paths (images/image.png) could cause issues if you are using a template and the URL for the loaded page is in a subfolder (or the CMS/framework you are using makes it appear to be in a subfolder). For example, if you are at the following URL:

/content/index.php

The browser will attempt to find the image in the following location:

/content/images/image.png

Cody Snider
+1  A: 

Its a common error to use backslash (\) instead of slash (/). Some browsers can understand backslash wrong way (e.g. Netscape).

Its not a secret, that most web servers work under UNIX-based systems, where slash is used as delimiter in file-paths, thats why it is "more friendly" to use slash instead of backslash.

Dot before slash (./ and .\) means, that its relative (to current directory) link. Links like /some/path/ (begin with slash without dot) mean, that your link is relative too, but this case to your website's root.

Konstantin Likhter