HTML Links
Links are the original feature of the web. They're created with the <a> (anchor) element and the href attribute.
Where a link can point
| Kind | Example href | Goes to… |
|---|---|---|
| Absolute URL | https://laravel.com/docs | A specific page on any site. |
| Relative URL | /css/colors | A path on the current site. |
| Fragment | #section-2 | An element on the same page. |
mailto:hi@example.com | Opens the user's mail client. | |
| Telephone | tel:+61400123456 | Starts a call on mobile. |
Where the link opens
target attribute decides where the link opens.Security note: When using
target="_blank", also add rel="noopener". It prevents the new page from being able to control the original tab through window.opener.Tip: Write meaningful link text. "Read the Laravel docs" is far better for accessibility than "click here".
Example
Example
<!DOCTYPE html> <html> <body> <h2>HTML Links</h2> <p><a href="https://laravel.com">Visit Laravel</a></p> </body> </html>Try it Yourself »
Exercise
Open this link in a new browser tab.
<a href="/docs"
="_blank">Docs</a>
The attribute that controls where the link opens.
Discussion
Loading…