Search code examples
htmlasp.netanchor

What is the use of href="###" in an anchor tag?


I see these lines of code in some professional developer's project:

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

What is the use of three # instead of one?

Code Image


Solution

  • The first thing about "anchor tags"...

    This use of ### in particular is to create a links that don't go anywhere, and to do that the href attribute must have a value. Please read the href W3C spec page for more info about that.

    Browsers render default styles for elements and will change the default style of an anchor tag that doesn't have the href property. Instead, it will be considered like regular text. It even changes the browser's behavior with regard to the element. The status bar (bottom of the screen) will not be displayed when hovering an anchor without the href property. It is most optimal, then, to use a placeholder href value on an anchor to ensure it is treated as a hyperlink.

    I've often seen <a href="#">, and <a href="##"> , a hashtag - # within a hyperlink specifies an html element id to which the window should be scrolled.

    href="#some_id" would scroll to an element on the current page such as <div id="some_id">.

    href="//example.com/#some_id" would go to example.com and scroll to the id on that page. href="#" doesn't specify an id name, but does have a corresponding location - the top of the page. Clicking an anchor with href="#" will move the scroll position to the top.

    So, when you use <a href="###"> this create a links but it doesn't go anywhere. You can use it from "##","###" and more of hashtag to create a links like a "Hyperlinks" but they take you nowhere.

    My Conclusion:

    So, what is the use of it?

    You use it when you need a hyperlink that doesn't go anywhere. It's just to tell the browsers to change the style to an anchor tag.

    Check this JSFiddle demo