HTML Link Tags Explained (+ All Attributes and Values) (2024)

HTML <link> tags help define relationships between resources on your website.

In this post, we’ll explore what HTML link tags are, how to use them, and common mistakes to avoid when adding them to your site or webpage.

What Is an HTML Link Tag?

The HTML <link> tag is an HTML tag (a piece of code) that establishes connections between the document you’re on and its external resources (files or other assets).

You should place HTML link tags in an HTML document’s <head> section. Like this:

<!DOCTYPEhtml>
<htmllang="en">
<head>
<linkrel="stylesheet"type="text/css"href="styles.css">
</head>
<body>
<!--Thecontentofyourwebpagegoeshere-->
</body>
</html>

Browsers that currently support HTML link tags include:

  • Chrome
  • Edge
  • Safari
  • Opera
  • Firefox

Browsers that don’t support HTML link tags might not render them properly. Meaning they might ignore the tag altogether and display nothing at all.

7 Uses of the HTML Link Tag

Let’s look at a few common examples of link tags in HTML.

1. Link an External Style Sheet

An external style sheet is a file with Cascading Style Sheets (CSS) code. This code defines the styles and layout of a webpage—like background color.

For a style sheet to work, you must link it to the page you’d like to style. Otherwise, the browser won’t know about it and won’t display as you’ve intended.

Here’s how you can use the HTML link tag to link to the style sheet:

<!DOCTYPEhtml>
<htmllang="en">
<head>
<linkrel="stylesheet"type="text/css"href="styles.css">
</head>
<body>
<!--Thecontentofyourwebpagegoeshere-->
</body>
</html>

2. Display a Favicon

A favicon is a small icon displayed in the browser’s tab or bookmark.

Here’s one:

HTML Link Tags Explained (+ All Attributes and Values) (1)

Use the HTML link tag like in the example below to display your favicon across various browsers:

<!DOCTYPEhtml>
<htmllang="en">
<head>
<linkrel="icon"href="favicon.png">
</head>
<body>
<!--Thecontentofyourwebpagegoeshere-->
</body>
</html>

3. Set a Canonical URL

A canonical URL indicates the primary version of a webpage when duplicate content exists across the site. And tells search engines which page to prioritize and rank in organic (unpaid) search results.

To specify a canonical page, use the HTML link tag like this:

<!DOCTYPEhtml>
<htmllang="en">
<head>
<linkrel="canonical"href="https://www.example.com/canonical-page">
</head>
<body>
<!--Thecontentofyourwebpagegoeshere-->
</body>
</html>

4. Set the Language of a Page

The hreflang attribute specifies the language and (optionally) intended region of a document. Which is useful if you have content in different languages.

Why?

Because with the hreflang attribute, search engines can display the most relevant search results to users in different countries.

For example, if you Google “semrush blog” in the United States, you’ll see this result:

HTML Link Tags Explained (+ All Attributes and Values) (2)

But if you’re in Spain, you’ll see this:

HTML Link Tags Explained (+ All Attributes and Values) (3)

You can define pages for different countries and languages using the HTML link tag as shown below (this one has alternate Spanish and French versions):

<!DOCTYPEhtml>
<htmllang="en">
<head>
<linkrel="alternate"hreflang="en"href="https://example.com/page">
<linkrel="alternate"hreflang="es"href="https://example.com/es/page">
<linkrel="alternate"hreflang="fr"href="https://example.com/fr/page">
</head>
<body>
<!--Thecontentofyourwebpagegoeshere-->
</body>
</html>

5. Preload Specific Resources

Preloading instructs browsers to request and store a resource in its cache right when (or soon after) the page starts loading. Which can improve a website’s performance, speed, and user experience.

A common preload request is for fonts. And you can set a font to preload with an HTML link tag like this:

<!DOCTYPEhtml>
<htmllang="en">
<head>
<!--Preloadfonts-->
<linkrel="preload"as="font"type="font/woff2"href="your-font.woff2">

<!--Linktotheexternalstylesheetusingthefont-->
<linkrel="stylesheet"type="text/css"href="styles.css">
</head>
<body>
<!--Thecontentofyourwebpagegoeshere-->
</body>
</html>

You can set resources to preload on a page-by-page basis.

6. Connect Your RSS Feed

A Really Simple Syndication (RSS) feed is a way for websites to share content and updates.

And users can subscribe to different websites through RSS feed readers like this one:

HTML Link Tags Explained (+ All Attributes and Values) (4)

This lets them see when sites publish new content.

Use the HTML link tag to link to your RSS feed so a user can subscribe to your feed.

<!DOCTYPEhtml>
<htmllang="en">
<head>
<linkrel="alternate"type="application/rss+xml"title="RSSFeed"href="rss-feed.xml">
</head>
<body>
<!--Thecontentofyourwebpagegoeshere-->
</body>
</html>

7. Link to External Fonts

HTML link tags let you link to external fonts (like those in Google Fonts) to use on your site.

Here’s the code to use:

<!DOCTYPEhtml>
<htmllang="en">
<head>
<!--LinktoanexternalfontfromGoogleFonts-->
<linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Open+Sans">
</head>
<body>
<!--Thecontentofyourwebpagegoeshere-->
</body>
</html>

Additional HTML Link Tag Attributes and Values

Link tag attributes provide additional information and go between the opening and closing tag.

And values indicate the specific content assigned to an attribute.

HTML Link Tags Explained (+ All Attributes and Values) (5)

Both attributes and their values guide the HTML link tag in performing its designated tasks. In other words, they tell it how to behave.

Here are current HTML link tag attributes and their common values:

Attribute

Values

Definition

Example

as

audio

document

embed

fetch

font

image

object

script

style

track

video

worker

Specifies the type or role of the linked resource. It’s required when using the “preload” attribute.

<link rel="preload" as="audio" href="audio.mp3">

crossorigin

anonymous

use-credentials

Indicates whether the browser should fetch the crossorigin request as anonymous—i.e., without sending credentials (like cookies)

<link rel="stylesheet" href="https://example.com/styles.css" crossorigin="anonymous">

fetchpriority

high

low

auto

Helps browsers prioritize how to fetch resources. Which can improve your site’s performance when handled correctly.

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans" fetchpriority=”high”>

href

URL

Indicates the URL in absolute or relative terms of the linked resource

<link rel="stylesheet" href="https://example.com/styles.css">

hreflang

You may use ISO 639-1 or the ISO 3166-1 alpha-2 country and language codes

Indicates the language (and possibly the intended country) of the linked resource

<link rel="alternate" hreflang="fr" href="https://example.com/fr/page">

imagesizes

Height x width

or

Percent of viewport width (vw)

Helps preload responsive images. Used only with rel="preload" and as="image."

<link rel="preload" as="image" href="example.jpg" imagesrcset="example_300px.jpg 300w, example_600px.jpg 600w, example_1200px.jpg 1200w" imagesizes="50vw">

imagesrcset

URL

Specifies a list of images. The browser will select the most appropriate image to display. Used only with rel="preload" and as="image."

<link rel="preload" as="image" href="example.jpg" imagesrcset="example_300px.jpg 300w, example_600px.jpg 600w, example_1200px.jpg 1200w" imagesizes="50vw">

integrity

cryptographic hash value

Provides a hash value for verifying the integrity of the linked resource. Which can give you an extra layer of security when loading resources.

<link rel="stylesheet" href="styles.css" integrity="sha256-BBq2K8ntPke0J1Xy2ftV07cHJZaMjRZEmmgvsq81IB4=">

media

all

print

screen

speech

aspect-ratio

color

color-index

grid

height

monochrome

orientation

resolution

scan

width

Specifies the type of device or screen size that the linked resource is designed for

<link rel="stylesheet" href="styles-mobile.css" media="screen and (max-width: 600px)">

referrerpolicy

no-referrer

no-referrer-when-downgrade

origin

origin-when-cross-origin

unsafe-url

Specifies how much referrer information to include when fetching the resource

<link rel="stylesheet" href="styles.css" referrerpolicy="no-referrer">

rel

alternate

author

canonical

dns-prefetch

help

icon

license

next

pingback

preconnect

prefetch

preload

prerender

prev

search

stylesheet

Specifies the relationship between the current document and the linked resource

<link rel="icon" href="favicon.png">

sizes

Any height x width size

Used to indicate sizes of icons. It can only be used with rel=”icon.”

<link rel="icon" type="image/png" sizes="16x16" href="favicon.png">

title

text

Defines the default or alternate style sheet to keep track of linked style sheets. It does not affect how the browser applies them.

<link rel="stylesheet" href="styles.css" title="Main Style Sheet">

type

Various media types like:

text/css

text/javascript

image/svg+xml

Describes the media type for the linked resource

<link rel="stylesheet" href="styles.css" type="text/css">

Here are mistakes people frequently make when adding the <link> tag to their site. By avoiding them, you can ensure that your link tags work well and that browsers can read them.

Adding the Tag to Page’s Body Section

The HTML link tag belongs in the <head> section of your HTML document.

Why?

Because according to semantic HTML, the <head> section of an HTML document is where metadata should go. (Metadata is information that describes data. And HTML link tags are considered metadata elements.)

An HTML link tag may not work as expected if you add it to the <body>.

For instance, placing your style sheet HTML link tag in the <body> section could cause a delay in loading the style of that web page.

You can check where your link tag is by viewing your page’s source code. Right-click on the page in the browser and select “View Page Source.”

HTML Link Tags Explained (+ All Attributes and Values) (6)

Then, press Ctrl+F (Command+F on Mac) and search <head>.

HTML Link Tags Explained (+ All Attributes and Values) (7)

(You can also search </head> to find where the <head> section ends.)

Look through the code to ensure the link tags in your HTML are within the <head> and </head> tags. If they aren’t, either move them or reach out to your web developer for help.

Using Incorrect Attributes or Values

You can only use specific values associated with each attribute. And some attributes can only work with other attributes.

For example, if you use “rel=preload” in your link tag, you must also use the as attribute.

Refer to our list of HTML link tag attributes and their values above to ensure you’re using the right ones.

Incorporating Deprecated Attributes

Deprecated—meaning outdated—attributes may not work. Because modern browsers typically phase out support for them.

Organizations like the World Wide Web Consortium (W3C) may decide to deprecate attributes for various reasons. Like changing technology.

For example, the rev attribute was previously used to show the reverse relationship between the current document and the linked document. For example:

<linkrev="made"href="related-document.html">

This HTML link tag indicated that the linked document (related-document.html) was made by the current document.

But because the rev attribute only accounts for reverse relationships, the W3C deprecated it. It now advises people to use the rel attribute instead, which is more flexible.

Here’s how you’d rework the example above using the current rel attribute:

<linkrel="author"href="related-document.html">

Other deprecated attributes for the HTML link tag include:

  • charset: Defines the encoding of the linked resource
  • methods: Provides information about the functions or actions that could be performed on a linked object
  • target: Specifies whether the linked document should load in a window or frame

Check your code for any of these attributes. And replace them with something more suitable if needed.

Check for HTML Link Tag Issues on Your Site

Use a diagnostic tool like Semrush’s Site Audit to track technical issues on your site. Including ones that arise from mistakes within your HTML link tags.

Here’s how.

Open Site Audit. Enter your domain URL and click “Start Audit.”

HTML Link Tags Explained (+ All Attributes and Values) (8)

This opens a menu where you can configure all your settings.

Next, click “Start Site Audit.”

HTML Link Tags Explained (+ All Attributes and Values) (9)

Once your audit is complete, you’ll receive a detailed report of what you need to improve.

Click on the “Issues” tab.

HTML Link Tags Explained (+ All Attributes and Values) (10)

This displays a list of technical issues with your site.

For example, pages with duplicate content—which would benefit from an HTML link tag with a canonical attribute.

HTML Link Tags Explained (+ All Attributes and Values) (11)

Site Audit also spots hreflang errors, canonical tag errors, and slow pages. (Slow pages might benefit from using the fetchpriority attribute within your HTML link tag.)

You can click “Why and how to fix it” next to each issue to better understand and address the problem.

Cleaning up these issues helps you create a great user experience on your site. And optimize your pages so search engines can easily crawl, index, and rank them in search results.

Try Site Audit for free.

HTML Link Tags Explained (+ All Attributes and Values) (2024)
Top Articles
Signing Git Commits and Tags with GPG
Amazon boosts max base pay for corporate workers to $350,000 as labor market heats up
Funny Roblox Id Codes 2023
Login Page
Mackenzie Rosman Leaked
Women's Beauty Parlour Near Me
Toyota gebraucht kaufen in tacoma_ - AutoScout24
Apply A Mudpack Crossword
Magic Mike's Last Dance Showtimes Near Marcus Cedar Creek Cinema
Mikayla Campinos Videos: A Deep Dive Into The Rising Star
Pvschools Infinite Campus
Simon Montefiore artikelen kopen? Alle artikelen online
Maplestar Kemono
Panorama Charter Portal
Aucklanders brace for gales, hail, cold temperatures, possible blackouts; snow falls in Chch
Rachel Griffin Bikini
Icommerce Agent
1773X To
bode - Bode frequency response of dynamic system
FDA Approves Arcutis’ ZORYVE® (roflumilast) Topical Foam, 0.3% for the Treatment of Seborrheic Dermatitis in Individuals Aged 9 Years and Older - Arcutis Biotherapeutics
Tips on How to Make Dutch Friends & Cultural Norms
Qual o significado log out?
Isaidup
Theater X Orange Heights Florida
Wemod Vampire Survivors
Www Craigslist Madison Wi
Kirk Franklin Mother Debra Jones Age
Villano Antillano Desnuda
'Insidious: The Red Door': Release Date, Cast, Trailer, and What to Expect
Bayard Martensen
Gncc Live Timing And Scoring
Devotion Showtimes Near The Grand 16 - Pier Park
Kristen Hanby Sister Name
Newsday Brains Only
Wbli Playlist
Joplin Pets Craigslist
آدرس جدید بند موویز
19 Best Seafood Restaurants in San Antonio - The Texas Tasty
Temu Y2K
One Main Branch Locator
Mixer grinder buying guide: Everything you need to know before choosing between a traditional and bullet mixer grinder
Linda Sublette Actress
Gfs Ordering Online
Sdn Fertitta 2024
The power of the NFL, its data, and the shift to CTV
Advance Auto.parts Near Me
Blue Beetle Showtimes Near Regal Evergreen Parkway & Rpx
All Weapon Perks and Status Effects - Conan Exiles | Game...
What is 'Breaking Bad' star Aaron Paul's Net Worth?
Cch Staffnet
Food and Water Safety During Power Outages and Floods
18443168434
Latest Posts
Article information

Author: Duncan Muller

Last Updated:

Views: 5708

Rating: 4.9 / 5 (59 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Duncan Muller

Birthday: 1997-01-13

Address: Apt. 505 914 Phillip Crossroad, O'Konborough, NV 62411

Phone: +8555305800947

Job: Construction Agent

Hobby: Shopping, Table tennis, Snowboarding, Rafting, Motor sports, Homebrewing, Taxidermy

Introduction: My name is Duncan Muller, I am a enchanting, good, gentle, modern, tasty, nice, elegant person who loves writing and wants to share my knowledge and understanding with you.