DEV Community

Max Lockwood
Max Lockwood

Posted on • Originally published at maxlockwood.dev

What is the purpose of hashtag in HTML Links?

What is the purpose of hashtag in HTML Links?

Within a hyperlink, a hash – '#' specifies an HTML element id to which the window should be scrolled.
href="#idname" would scroll to a current page element, such as <p id="idname">.

You might come across a link like this while working on a web page:

<a href="#">Home</a>
Enter fullscreen mode Exit fullscreen mode

href="#" here is a placeholder. 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.

Tip: You can use href="#top" or href="#" to link to the top of the current page!

Sometimes this can also indicate that the app is in development, and we’ll fill that link href attribute later.

Other times you’ll see this below:

<a href="#about">About</a>
Enter fullscreen mode Exit fullscreen mode

In this case the link references a point or section in the same page.

You’ll have an element like this:

<section id="about">About</section>
Enter fullscreen mode Exit fullscreen mode

It can also be an empty element, which will be there, but hidden:

<section id="about"></section>
Enter fullscreen mode Exit fullscreen mode

Notice we used id here.

Clicking the <a href="#about">About</a> element will bring you to the <section> with the id equal to about.

Further Reading

Want to learn more about HTML links? Then go check out HTML Links HyperLinks – W3Schools

See also

What is HTML? Basics Explained
How to Create an HTML Boilerplate
What is an HTML Element? How do you create one?

If you liked this article, then please share. You can also find me on Twitter for more updates.

Top comments (0)