Home > Web Front-end > HTML Tutorial > The difference between src and href attributes

The difference between src and href attributes

怪我咯
Release: 2017-01-16 17:19:06
Original
2268 people have browsed it

There is a difference between src and href, which can be used confusingly. src is used to replace the current element, and href is used to establish a link between the current document and the referenced resource.

src is the abbreviation of source, which points to the location of external resources. The pointed content will be embedded in the document at the location of the current tag; when requesting the src resource, the resource pointed to will be downloaded and applied to the document. For example, js scripts, img pictures, frames and other elements.

<script src ="js.js"></script>
Copy after login

When the browser parses this element, it will pause the downloading and processing of other resources until the resource is loaded, compiled, and executed. The same is true for elements such as pictures and frames, similar to the resource pointed to. Embed within the current tag. This is why the js script

is placed at the bottom instead of the head.

href is the abbreviation of Hypertext Reference, which points to the location of the network resource and establishes a link to the current element (anchor) or current document (link). If we add

<link href="common.css" rel="stylesheet"/>
Copy after login
## to the document #Then the browser will recognize the document as a css file, download the resources in parallel and will not stop processing the current document. This is why it is recommended to use the link method to load css instead of using the @import method. The content of

src is used to replace the current element and is an essential part of the page. The content of

href is introduced to establish a connection between the current document and the referenced resource. It is a reference.

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