Working with Links
Last updated
Last updated
HTML links allow users to navigate between pages, download files, or open external resources. Links are created using the <a>
tag (anchor tag).
A basic link uses the <a>
tag, where the href
attribute defines the destination URL.
Syntax:
Example:
In this example, clicking "Visit Example" will take the user to "".
You can create links to internal pages of your website or external websites.
Internal Link Example:
External Link Example:
To open a link in a new tab, use the target="_blank"
attribute. This is often used for external websites.
Example:
You can create a link that opens the user’s default email client to send an email.
Syntax:
Example:
Clicking the link will open the default email client and prefill the "To" field.
You can create links that allow users to call a phone number directly if they're using a mobile device or an app that supports calling.
Syntax:
Example:
You can add the download
attribute to make a link download a file instead of navigating to it.
Syntax:
Example:
When the link is clicked, the browser will download the report.pdf
file.
You can link to a specific part of the same page or another page using id
attributes and anchor links.
Example of Linking to a Section on the Same Page:
Create an id
in the section you want to link to:
Then create a link to that section:
Example of Linking to a Section on Another Page:
By default, links are blue and underlined, but you can style them using CSS. Common states of a link are:
Normal (unvisited): This is the default look of a link.
Hover: What happens when a user hovers the mouse over the link.
Visited: The appearance of a link after it’s been clicked.
Active: The appearance of the link when it’s clicked and held.
Example:
This guide covers everything you need to know to start working with links in HTML, from simple links to anchor links and downloadable files.
HTML
, Hypertext Markup Language
, Tags
, Elements
, Attributes
, Head
, Body
, Paragraph
, Heading
, Title
, Meta
, Link
, Image
, Anchor
, Hyperlink
, List
, Table
, Form
, Input
, Button
, CSS
, Class
, ID
, Inline
, Block
, Div
, Span
, Script
, Styles
, Font
, Color
, Background
, Margin
, Padding
, Border
, Doctype
, HTML5
, Video
, Audio
, Canvas
, SVG