Let's say the current URL is example.com/test/example
and let's say I want to link to example.com/test/example/another
<a href="/another">
links me to example.com/another
How can I link to example.com/test/example/another
without having to put the full URL in the a
tag?
To make page links in an HTML page, use the <a> and </a> tags, which are the tags used to define the links. The <a> tag indicates where the link starts and the </a> tag indicates where it ends. Whatever text gets added inside these tags, will work as a link. Add the URL for the link in the <a href=” ”>.
Definition and Usage Tip: You can use href="#top" or href="#" to link to the top of the current page!
<a href="another">
should do it.
EDIT: My bad, it actually is:
<a href="./another">
I'd suggest using root-relative paths, if you'd prefer not to use absolute paths:
<a href="/test/example/another">Link text</a>
Otherwise, for relative paths, itdoesntwork's answer covers the use-case.
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