I see these lines of code in some professional developer's project:
<a href="###">
...
</a>
What is the use of three #
instead of one?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With