What is the difference between href="", href="#" and href="javascript:void(0)"?

Viewed 12884

What is the difference between href="", href="#" and href="javascript:void(0)"?
What are the different uses for them and when is one better than another?

6 Answers

The href attribute defines the URL of the resource of a link. If the anchor tag does not have href tag then it will not become hyperlink. The href attribute have the following values:

1. Absolute path: move to another site like href="http://www.google.com"
2. Relative path: move to another page within the site like herf ="defaultpage.aspx"
3. Move to an element with a specified id within the page like href="#bottom"
4. href="javascript:void(0)", it does not move anywhere.
5. href="#" , it does not move anywhere but scroll on the top of the current page.
6. href= "" , it will load the current page but some browsers causes forbidden errors.

Note: When we do not need to specified any url inside a anchor tag then use

<a href="javascript:void(0)">Test1</a>
Related