A Few Things About the Anchor Element’s href You Might Not Have Known

It’s easy to take URL superpowers for granted, even if you already have these patterns under your belt.


A Few Things About the Anchor Element’s href You Might Not Have Known originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.


This content originally appeared on CSS-Tricks and was authored by Geoff Graham

I love “re-learning” things I thought I knew. HTML is full of those opportunities (case in point, like today) since it’s where you typically start learning about web development. And in those early days, you don’t know what you don’t know.

So, thanks Jim Nielsen for giving me a reason to give URL patterns another look. It’s easy to take URL superpowers for granted, even if you already have these patterns under your belt.

The patterns:

<a href="#"> <!-- Scrolls to the top of a document -->
<a href=""> <!-- Reloads the current page, preserving the search string but removing the hash string (if present). -->
<a href="."> <!-- Reloads the current page, removing both the search and hash strings -->
<a href="?"> <!-- Reloads the current page, removing both the search and hash strings (keeps `?`) -->
<a href="data:"> <!-- Link to data URLs, like text fragments -->
<a href="video.mp4#t=10,20">  <!-- Links to specific parts of a media file -->

But do yourself a favor and read Jim’s full post. He gets way more into the weeds, referencing the specification and stress testing different configurations. I mean, this is gold:

But I’m writing because #top will also scroll to the top if there isn’t another element with id="top" in the document. I didn’t know that.

Me neither.


A Few Things About the Anchor Element’s href You Might Not Have Known originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.


This content originally appeared on CSS-Tricks and was authored by Geoff Graham


Print Share Comment Cite Upload Translate Updates
APA

Geoff Graham | Sciencx (2025-08-15T12:26:00+00:00) A Few Things About the Anchor Element’s href You Might Not Have Known. Retrieved from https://www.scien.cx/2025/08/15/a-few-things-about-the-anchor-elements-href-you-might-not-have-known/

MLA
" » A Few Things About the Anchor Element’s href You Might Not Have Known." Geoff Graham | Sciencx - Friday August 15, 2025, https://www.scien.cx/2025/08/15/a-few-things-about-the-anchor-elements-href-you-might-not-have-known/
HARVARD
Geoff Graham | Sciencx Friday August 15, 2025 » A Few Things About the Anchor Element’s href You Might Not Have Known., viewed ,<https://www.scien.cx/2025/08/15/a-few-things-about-the-anchor-elements-href-you-might-not-have-known/>
VANCOUVER
Geoff Graham | Sciencx - » A Few Things About the Anchor Element’s href You Might Not Have Known. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/08/15/a-few-things-about-the-anchor-elements-href-you-might-not-have-known/
CHICAGO
" » A Few Things About the Anchor Element’s href You Might Not Have Known." Geoff Graham | Sciencx - Accessed . https://www.scien.cx/2025/08/15/a-few-things-about-the-anchor-elements-href-you-might-not-have-known/
IEEE
" » A Few Things About the Anchor Element’s href You Might Not Have Known." Geoff Graham | Sciencx [Online]. Available: https://www.scien.cx/2025/08/15/a-few-things-about-the-anchor-elements-href-you-might-not-have-known/. [Accessed: ]
rf:citation
» A Few Things About the Anchor Element’s href You Might Not Have Known | Geoff Graham | Sciencx | https://www.scien.cx/2025/08/15/a-few-things-about-the-anchor-elements-href-you-might-not-have-known/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.