How to use link tag in html

下次还敢
Release: 2024-04-27 18:52:33
Original
1078 people have browsed it

The link tag in HTML is used to link to external resources, such as CSS files, icons and fonts. The syntax is , where rel specifies the type and href specifies the resource URL. Common types include stylesheet (CSS), icon (Favicon), font-face (font), preconnect (pre-connection), prefect (prefetch resources).

How to use link tag in html

Usage of link tag in HTML

What is link tag?

The link tag is an HTML element used to link external resources (such as CSS files, icons, fonts) into HTML documents.

The syntax of the link tag

<code class="html"><link rel="rel-type" href="source-url"></code>
Copy after login

Among them:

  • rel The attribute specifies the type of link, such as stylesheet, icon etc. The
  • href attribute specifies the URL of the external resource to link to.

Types of link tags

The link tag can be used to link to different types of external resources. The most common types include:

  • stylesheet: Link to external CSS files.
  • icon: Link website icon (Favicon).
  • font-face: Link to external font files.
  • preconnect: Preconnect to other servers.
  • prefect: Prefetch resources for fast loading.

Using the link tag

To use the link tag, add the following code in the <head> section:

<code class="html"><head>
  <link rel="stylesheet" href="style.css">
  <link rel="icon" href="favicon.ico">
</head></code>
Copy after login

This code will link the external CSS file style.css and the favicon favicon.ico.

Attributes of the link tag

In addition to the rel and href attributes, the link tag also supports other attributes, including :

  • media: Specify the media type applicable to the CSS file (such as screen, print).
  • type: Specifies the MIME type of the external resource.
  • sizes: Specify the size of the icon.
  • crossorigin: Specify cross-origin settings when accessing external resources.
  • referrerpolicy: Specifies the HTTP header sent when requesting external resources.

The above is the detailed content of How to use link tag in html. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template