A Few Things About the Anchor Element's Href You Might Not Have Known
9 months ago
- #Anchor Element
- #HTML
- #Web Development
- Anchor element's href attribute can use various protocols like mailto:, tel:, sms:, and javascript:.
- Protocol-relative links can be used with href="//".
- Text fragments allow linking to specific text on a page using href="#:~:text=foo".
- href="#" or href="#top" scrolls to the top of a document.
- href="" reloads the current page, preserving the search string but removing the hash.
- href="." reloads the current page, removing both search and hash strings, but requires trailing slashes for correct behavior.
- href="?" reloads the current page, removing search parameters and hash but preserves the ? character.
- Data URLs can be used with href="data:text/plain,hello%20world" to navigate to plain text.
- Media fragments like href="video.mp4#t=10,20" allow linking to specific parts of media files.
- JavaScript's URL constructor can be used to test how different href values resolve.