Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of href="###" in 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

like image 875
Mohamad Shiralizadeh Avatar asked Jan 08 '23 14:01

Mohamad Shiralizadeh


2 Answers

That's usually written when you want your anchor tag to not change the href. For instance if you want to attach an event on it later on.

It doesn't matter how many # you are using. The href='#' will make the page jump to the top of the page if clicked.

My preferred way is doing <a href="javascript:void(0);". That way the click does absolutely nothing, instead of jumping the page up.

like image 172
Omri Aharon Avatar answered Jan 11 '23 04:01

Omri Aharon


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

like image 40
Eko Junaidi Salam Avatar answered Jan 11 '23 04:01

Eko Junaidi Salam