, 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)."/> , 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).">

Home  >  Article  >  Web Front-end  >  How to use link tag in html

How to use link tag in html

下次还敢
下次还敢Original
2024-04-27 18:52:331072browse

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>

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>

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!

Statement:
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
Previous article:How to use li in htmlNext article:How to use li in html