Links in HTML
Links are created using the <a> (anchor) tag. The destination URL is specified using the href attribute.
Basic Example:
Code Block Loading...
- The text between the opening and closing
<a>tags is what users click. - This example uses an absolute URL, pointing to a full web address.
Relative URLs
You can also use relative URLs to link within the same site:
Code Block Loading...
- The leading
/means the path starts from the site’s root. - If you omit the
/, the browser appends the path to the current page’s URL.
Example:
If you're on https://learncode.live/html/:
/html→ navigates tohttps://learncode.live/html/- links → navigates to
https://learncode.live/html/links
Link Content
Anchor tags can contain more than just text—such as images or other inline elements:
Code Block Loading...
- You can nest most elements inside
<a>, except another<a>tag.
Opening Links in a New Tab
To open a link in a new browser tab, use the target="_blank" attribute:
Code Block Loading...