Home  >  Article  >  Web Front-end  >  What is the difference between link tag and a tag in HTML? how to use?

What is the difference between link tag and a tag in HTML? how to use?

不言
不言Original
2019-01-18 16:07:0215641browse

The

link tag and the a tag are both tags used for links, but what is the difference between them? This article will introduce to you the difference between link tags and a tags.

What is the difference between link tag and a tag in HTML? how to use?

First let’s take a look at what the link tag is? The

link tag is a tag used to connect other pages related to this page, however, this tag has no direct relationship with the appearance of the website.

So basically it is written in the head tag. The

link tag is typically used to read CSS and JavaScript as external files, and to read web icons named favicon.

What is a tag?

When you see a link, someone may think of the a tag

The a tag defines a hyperlink, which is used to link from one page to another.

Let’s take a look at the difference between link tags and a tags

As mentioned in the above definition, the link tag has no direct relationship with the appearance of the website .

However, the a tag creates a hyperlink element in the page.

If you want to create a basic hyperlink, use the a tag. If you want to read other files from HTML, use the link tag.

How to use link tag?

These files can be separated from the HTML and saved externally as .css files or .js files.

You need to use the link tag above to read the file.

Let’s look at a specific example

The code is as follows

HTML

<html>
<head>
    <link rel="stylesheet" href="style.css">
</head>
    <div class="text">text</div>
</html>

CSS

.text {
    color: blue;
    }

The running result is as follows

What is the difference between link tag and a tag in HTML? how to use?

#Through the above method, you can see that the CSS written in style.css is actually successfully connected to HTML through the link tag.


The rel attribute specifies the relationship between this HTML and CSS, and the href attribute specifies the path of the file to be read.

How to use the a tag ?

aThe use of tags is very simple. Let’s look at specific examples

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
<a href="http://www.php.cn/">php中文网</a>
</body>
</html>

The running effect is as follows

What is the difference between link tag and a tag in HTML? how to use?

Click on the above "php Chinese website" link to jump to the home page of the php Chinese website.

The above is the detailed content of What is the difference between link tag and a tag in HTML? how to use?. 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