HTML Link Code: How to Create Hyperlinks with HTML (+ 9 Examples) (2024)

HTML link code lets you turn elements on your website—like text and images—into clickable hyperlinks.

These hyperlinks help users navigate the web.

And when you use them correctly for internal links—links from one page on your site to another page on your site—they can provide SEO benefits, too.

This guide shows you how to code a variety of HTML links. And how to style your links with simple CSS.

Let’s get started.

What Is a Hyperlink?

A hyperlink, often called a link, is a reference linking one resource to another. It includes a clickable element like a word, phrase, image, or icon.

Clicking a hyperlink initiates an action. Like taking users to a different webpage. Or launching a phone call.

And coding your own hyperlinks is easy. As long as you understand the syntax of an anchor element (also known as an <a> tag).

Anchor Element Syntax

Anchor elements have four components:

  1. An opening tag: This is the start of the anchor element and signifies the beginning of the link element
  2. Tag attributes + attribute values: Within the opening tag, you can include different attributes. Attributes provide extra information, like how the link should behave or where it should take users. (We’ll dive into different attributes later on.)
  3. Anchor text or other content: This is the content users click
  4. A closing tag: This signifies the end of the link element

Let’s tie all four points together with a simple example. The below example uses an href attribute. It specifies the destination of the link—in this case, Semrush’s homepage.

HTML Link Code: How to Create Hyperlinks with HTML (+ 9 Examples) (1)

The destination can also be a specific place on a webpage or a downloadable document.

Note: You can use one or more attributes in your anchor elements.

How to Code a Link in HTML

Let’s walk through how to code a simple link to your website’s homepage in HTML.

First, start with your anchor tag:

<a></a>

Next, add your homepage’s URL using the href attribute:

<ahref="https://www.yourhomepage.com"></a>

Now, add the anchor text people will click to go to your link:

<ahref="https://www.homepage.com>Visitourhomepage</a>

Your anchor text should be descriptive. So users will know where they’ll end up when they click your link.

Search engines also use anchor text to understand the page you’re linking to. So good anchor text can improve your SEO.

Take the below anchor text of “newsletter best practice” from ConvertKit. Readers and search engines know that if they visit the link, they’ll end up on a page about newsletter best practices.

HTML Link Code: How to Create Hyperlinks with HTML (+ 9 Examples) (2)

Something non-descriptive like “click here” doesn’t give enough context. Making it confusing to people and search engines.

Semrush’s Site Audit tool can check your website for links with non-descriptive anchor text.

First, set up your site audit by clicking the “+ Create project” button.

HTML Link Code: How to Create Hyperlinks with HTML (+ 9 Examples) (3)

Enter your domain and give your project a name. Then click “Create project.”

HTML Link Code: How to Create Hyperlinks with HTML (+ 9 Examples) (4)

Next, configure your settings. This Site Audit configuration guide gives you a detailed walkthrough if you need help.

HTML Link Code: How to Create Hyperlinks with HTML (+ 9 Examples) (5)

Then, click “Issues” and search “descriptive.” This shows a report for links with non-descriptive anchor text:

HTML Link Code: How to Create Hyperlinks with HTML (+ 9 Examples) (6)

Click the links to review a list of non-descriptive links and links with no anchor text.

Then, update the anchor text of the links listed to help users and search engines better understand what the linked pages are about.

Now that you know how to code a basic link, let’s dive into additional attributes and values you can add to your HTML link code.

You can make media like images or GIFs clickable by adding a source to your anchor tag:

<ahref="https://www.example.com"><imgsrc="https://www.example.com/filename.jpg"alt="adescriptionofthemedia"></a>

Here, you include a link to the media (an image in this case) instead of anchor text.

In the above code:

  • src stands for “source” and specifies the location/URL of your media
  • alt contains the alt text—descriptive text used by screen readers and displayed when an image doesn’t load—if using an image as a link (below)
HTML Link Code: How to Create Hyperlinks with HTML (+ 9 Examples) (7)

2. Linking to Specific Page Sections (Anchor Links)

Anchor links—also called jump links—take users to a specific place on the page with this code:

<ahref="https://www.example.com/blog/#seo-tips">SEOtips</a>

They help readers navigate the page better to find what they need (like a table of contents).

To start, label the anchor—the place the link will take the reader—by giving it an ID in the opening tag. Like this:

<h2id="seo-tips">

You can assign an ID to any HTML element. In the example above, we assigned it to an <h2> heading tag.

Now, test the ID to make sure it works. Add the ID to the end of your URL with a hash like this:

HTML Link Code: How to Create Hyperlinks with HTML (+ 9 Examples) (8)

Paste the link in your browser's address bar. Press enter to ensure it directs you to the assigned ID location on the page.

If it works, you can add the link to the href attribute.

3. Opening Links in New Windows/Tabs

You can choose whether your links open in the same window or a new tab with the target attribute.

For the same window, use the target=”_self” attribute value like this:

<ahref="https://www.example.com"target="_self">Anchortext</a>

Links open in the same window by default. So, using “_self” isn’t necessary. But it can help you clarify the intent of specific hyperlinks.

To open links in a new tab, replace “_self” with “_blank”:

<ahref="https://www.example.com"target="_blank">Anchortext</a>

It’s usually best for links to open in the same tab for accessibility reasons.

4. Linking to Email Addresses

Adding the mailto value opens your user’s email provider when they click your link:

<ahref="mailto:[email protected]">EmailUs</a>

For example, link to your support email so customers can easily submit their questions.

HTML Link Code: How to Create Hyperlinks with HTML (+ 9 Examples) (9)

Just make sure your anchor text indicates an email application will open from clicking the link. Something like “Email us” or “Send an email” conveys the message clearly.

This way, users won’t be caught off guard when an unexpected application opens.

5. Linking to Phone Numbers

Initiate a Call

Linking a phone number initiates a call. You can link to a phone number using the tel value:

<ahref="tel:+1-123-456-7890">CallUs</a>

Initiate a Text Message

You can also initiate a text message by using the “sms” value:

<ahref="sms:123-456-7890">SendSMS</a>

As with the email attribute, make sure the user knows a phone call or text message will initiate when clicked.

6. Creating Download Links

The HTML code for creating downloads is similar to linking to a URL and looks like this:

<ahref="https://www.example.com/path/to/file.pdf"download>DownloadthePDF(175kB)now</a>

When users click the link, their device will automatically download the file.

When choosing which files to use for your links, keep a few things in mind:

  • Include the file type in the anchor text so users know what they’re downloading
  • Use file types that are widely supported so users don’t need additional software to open them
  • Mention the file size so you user can determine if they have enough space for the file

7. Linking with Accessibility Attributes

The aria-label attribute lets you describe links to screen readers. Like this:

<ahref="https://www.example.com"aria-label="Readmoreaboutbuildingabrand">Readmore</a>

It’s useful when the anchor text isn’t descriptive.

For example, let’s say you display snippets of content and include a “read more” link:

HTML Link Code: How to Create Hyperlinks with HTML (+ 9 Examples) (10)

With the “aria-label” you can add more context behind the “read more” link.

This way, people who use screen readers will know what the link is for.

8. Linking with Title Attributes

The title attribute shows text when users hover over a link:

HTML Link Code: How to Create Hyperlinks with HTML (+ 9 Examples) (11)

And you get this text by adding in the title attribute:

<ahref="https://www.example.com"title="Readmoreaboutthistopicbyclickingthislink">Anchortext</a>

Use it to give additional context to your links.

For example, tell users where they’ll end up if they click the link. In this example, the title text could say something like, “click this link for an in-depth guide on this topic at www.example.com.”

9. Adding Relationships to Your Links

Adding a relationship to your links helps search engines and browsers understand the connection between the linked document and the current one.

For example, if you collaborated with another business, you’d add the rel=”sponsored” attribute value to your anchor element, like this:

<ahref="https://www.example.com"rel="sponsored">Anchortext</a>

This tells search engines that the link is part of an advertising/sponsorship collaboration.

Here are some other common relationship attributes:

  • nofollow: Instructs search engines to ignore the link for search ranking purposes. Use when you're linking to content that you don't necessarily endorse or when you want to prevent search engines from passing link equity to the linked page.
  • noopener: A security measure that prevents the opened page from accessing information from the original page. Use when you use the target=”_blank” attribute value. It helps protect your site from potential security vulnerabilities.
  • noreferrer: Stops browsers from sending the original page’s address as a referrer. Use when you don’t want the linked page to track referral traffic from your site.

Styling and Designing Links with CSS

With CSS, you can style your links to match your brand by changing their colors and design.

CSS stands for cascading style sheets. It’s a stylesheet language that tells web browsers how to display web documents written in markup languages like HTML.

We’ll discuss two ways to edit the CSS:

  1. Inline CSS
  2. An external CSS file

Inline CSS

Inline CSS lets you add styling right into the HTML code for a single element.

Just add a style attribute. Like this:

<ahref="https://www.example.com"style="color:red;">Anchortext</a>

In this code, we use “style” to add color.

You can change the color using:

  • Color keywords (like red)
  • HEX codes
  • RGB and RGBA values
  • HSL values

If you want to remove the hyperlink’s underline, you can use the “text-decoration:none;” property. Like this:

<ahref="https://www.example.com"style="color:red;text-decoration:none;">Anchortext</a>

Inline CSS works when you need to make one hyperlink look different than the rest.

For example, say your links are all green. But you have a downloadable file, and you want the link to be orange. For that, use inline CSS.

External CSS File

An external CSS file lets you set global styles.

In your external CSS file, add this code:

a{
color:red;/*Changethistoyourdesiredcolor*/
text-decoration:none;/*Removethislinetokeepthelink’sunderline*/
}

As with inline CSS, you can use color keywords, HEX codes, RGB and RGBA values, or HSL values to set your links’ color.

Check Your Hyperlinks with Site Audit

To give users a great experience, make sure your hyperlinks work at all times.

This way, users won’t hit dead ends and can find what they need.

Use Semrush’s Site Audit tool to check your website for broken links.

Click “Issues” and search “broken.”

HTML Link Code: How to Create Hyperlinks with HTML (+ 9 Examples) (12)

This shows you which links need your attention. Fix them so users can navigate your site—and click links to external sites—with ease.

Try Site Audit for free today.

HTML Link Code: How to Create Hyperlinks with HTML (+ 9 Examples) (2024)

FAQs

HTML Link Code: How to Create Hyperlinks with HTML (+ 9 Examples)? ›

The <a> tag defines a hyperlink, which is used to link from one page to another. The most important attribute of the <a> element is the href attribute, which indicates the link's destination. By default, links will appear as follows in all browsers: An unvisited link is underlined and blue.

How to create a hyperlink in HTML with an example? ›

The <a> tag defines a hyperlink, which is used to link from one page to another. The most important attribute of the <a> element is the href attribute, which indicates the link's destination. By default, links will appear as follows in all browsers: An unvisited link is underlined and blue.

What is the correct HTML for a hyperlink as an example? ›

To make a hyperlink 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 hyperlink starts and the </a> tag indicates where it ends. Whatever text gets added inside these tags, will work as a hyperlink. Add the URL for the link in the <a herf=" ">.

What are 3 types of hyperlinks in HTML? ›

To make a hyperlink in HTML, use the anchor tag: <a href="URL" title="Description of link">link text</a> . There are three different types of hyperlinks on the web, absolute, relative, and inline links.

How do you turn a HTML code into a link? ›

To create a link to a file or folder, you need to use an <a href > tag. Add your file name to the first part of the tag and include the words you want to link between the tags. In the example below, we link the sentence This is my homepage to a file called index.

How do I hyperlink to a specific page in HTML? ›

How to Link to a Specific Part of a Page
  1. Name the object or text you want to link to.
  2. Take the name you've chosen, and insert it into an opening HTML anchor link tag.
  3. Place that complete opening <a> tag from above before the text or object you want to link to, and add a closing </a> tag after.
May 4, 2023

Which is a best example of hyperlink? ›

Hyperlinks can be presented in different forms, like an image, icon, text, or any type of visible element that, when clicked, redirects you to a specified url. For example, if you were to click HERE, you will land in my profile with a list of my other articles. That's a hyperlink.

What is the correct format for creating a hyperlink? ›

To insert a hyperlink we use the anchor tag represented by <a> and the text is inserted in the <a> and </a> tags. It supports flow content, phrasing content, and interactive content. It also supports the global and event attributes in HTML. Links should provide a large area so that it is easy to activate them.

What are the rules for hyperlinks in HTML? ›

The <a> HTML element (or anchor element), with its href attribute, creates a hyperlink to web pages, files, email addresses, locations in the same page, or anything else a URL can address. Content within each <a> should indicate the link's destination.

What are three hyperlinks examples? ›

Text hyperlink – Uses a word or phrase to take visitors to another page, file or document. Image hyperlink – Uses an image to take visitors to another page, file or document. Bookmark hyperlink – Uses text or an image to take visitors to another part of a web page.

What does a hyperlink look like? ›

In most graphical web browsers, links are displayed in underlined blue text when they have not been visited, but underlined purple text when they have. When the user activates the link (e.g., by clicking on it with the mouse) the browser displays the link's target.

How do I add a link to a button in HTML? ›

To add a link to a button, you can use an anchor tag <a> which will wrap your button. Here's an example code with HTML. You can replace https://www.example.com with the URL you want to link to and "Click me" with the text you want to display on the button.

How to create a hyperlink in HTML? ›

Chapter Summary
  1. Use the <a> element to define a link.
  2. Use the href attribute to define the link address.
  3. Use the target attribute to define where to open the linked document.
  4. Use the <img> element (inside <a> ) to use an image as a link.

How to create a URL link? ›

You can also insert a URL link by using the shortcut keys "Ctrl+K". The window below asks you to enter the hyperlink URL. If you selected something before using Ctrl+K, the URL itself will not appear on the page but what you selected will serve as a link to http://www.microsoft.com.

How do I get a link in HTML? ›

A link (or hyperlink as it is also called) is created with a special <a> tag called an "anchor". It requires a closing tag and is used to delineate the text or HTML content that should be linked on the page. An <a> tag can also be used to mark a section of a web page as a target for another link to jump to.

How do you create a hyperlink from text in HTML? ›

A basic link is created by wrapping the text or other content inside an <a> element and using the href attribute, also known as a Hypertext Reference, or target, that contains the web address.

How to create an internal link in HTML? ›

It is very simple. You just have to add an id to whatever element you want to link to. For example, <h1 id="Hello"></h1> . Then set your href to a # and then the id, <a href="#Hello">Go to Hello</a> .

How to get a new line in HTML? ›

The <br> tag inserts a single line break.

How do you create a hyperlink through text? ›

The big question is, how do you send a link in a text? There's just one easy step to follow. To include a link in any text message, just type or paste the full URL into your text. Most messaging platforms automatically turn the URL into a link allowing contacts to click and access the linked page.

Top Articles
Excel Formula to Calculate Compound Interest with Regular Deposits
How to Calculate Savings Account Interest | Capital One
Canary im Test: Ein All-in-One Überwachungssystem? - HouseControllers
Kaydengodly
Lifebridge Healthstream
Alan Miller Jewelers Oregon Ohio
OSRS Fishing Training Guide: Quick Methods To Reach Level 99 - Rune Fanatics
Cvs Devoted Catalog
Hardly Antonyms
Animal Eye Clinic Huntersville Nc
Hell's Kitchen Valley Center Photos Menu
Amc Flight Schedule
Char-Em Isd
50 Shades Darker Movie 123Movies
Pekin Soccer Tournament
Kp Nurse Scholars
Unity - Manual: Scene view navigation
Outlet For The Thames Crossword
Unforeseen Drama: The Tower of Terror’s Mysterious Closure at Walt Disney World
Breckie Hill Mega Link
Directions To Cvs Pharmacy
Greenville Sc Greyhound
Powerschool Mcvsd
Avatar: The Way Of Water Showtimes Near Maya Pittsburg Cinemas
Weather Underground Durham
Valley Craigslist
Why comparing against exchange rates from Google is wrong
Stubhub Elton John Dodger Stadium
Jt Closeout World Rushville Indiana
The Menu Showtimes Near Amc Classic Pekin 14
Craigslist Central Il
Ma Scratch Tickets Codes
404-459-1280
Louisville Volleyball Team Leaks
Build-A-Team: Putting together the best Cathedral basketball team
Dr Adj Redist Cadv Prin Amex Charge
USB C 3HDMI Dock UCN3278 (12 in 1)
Henry County Illuminate
Hell's Kitchen Valley Center Photos Menu
Tiny Pains When Giving Blood Nyt Crossword
Überblick zum Barotrauma - Überblick zum Barotrauma - MSD Manual Profi-Ausgabe
Cranston Sewer Tax
Shane Gillis’s Fall and Rise
Live Delta Flight Status - FlightAware
Dragon Ball Super Super Hero 123Movies
Market Place Tulsa Ok
2000 Ford F-150 for sale - Scottsdale, AZ - craigslist
Okta Login Nordstrom
Evil Dead Rise - Everything You Need To Know
Research Tome Neltharus
Mike De Beer Twitter
Latest Posts
Article information

Author: Edwin Metz

Last Updated:

Views: 5867

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Edwin Metz

Birthday: 1997-04-16

Address: 51593 Leanne Light, Kuphalmouth, DE 50012-5183

Phone: +639107620957

Job: Corporate Banking Technician

Hobby: Reading, scrapbook, role-playing games, Fishing, Fishing, Scuba diving, Beekeeping

Introduction: My name is Edwin Metz, I am a fair, energetic, helpful, brave, outstanding, nice, helpful person who loves writing and wants to share my knowledge and understanding with you.