HTML Link Tag <link>

Usage

The HTML link tag allows to you to link css files with your HTML webpage.

While linking CSS is the most common use of the link tag, it can be used to connect other external resources as well.

What you’ll notice about the link tag is that it has no structure data and nothing that is visible to the user.

Linking your CSS to HTML is simple.

The link tag sits in the section.

Simply upload your stylesheet to somewhere on your server.

Add the path to the file in the href=”Path to your file” as shown below.

Keep in mind that the styles from your stylesheet will now apply to your entire site.

Code:


<!DOCTYPE html>

<html>

<head>

<link rel="stylesheet" href="/file/stylesheet.css">

</head>

<body>

Content of the page goes here.

</body>

</html>

Required Attributes

  • None

Optional Attributes

  • Href: Defines the path to the linked file
  • Hreflang: Defines the language of the linked file
  • Media: You can define what media type will display this style
  • Rel: Defines the relationship between the existing page and linked file
  • Type: You may see older sites defining type as ‘text/css’, however as of HTML5 this is no longer required

Core Attributes