- In CSS, it’s always
url
. - In HTML:
- It’s
href
(short for Hypertext REFerence) for all kinds of links, including tagsa
andlink
. - When it’s not a link, you are setting the source, so it’s
src
.
- It’s
src – I want to load up this resource for myself.
href – I want to refer to this resource for someone else.
url – A script wants to use this url as a variable.
The anchor tag will not display the image; it will merely link to it. If you want to display the image, you use the IMG tag.
There is a differentiation between src and href and they can’t be used interchangeably. We use src for replaced elements while href for establishing a relationship between the referencing document and an external resource.
href attribute specifies the location of a Web resource thus defining a link or relationship between the current element (in case of anchor a
) or current document (in case of link
) and the destination anchor or resource defined by this attribute. When we write:
<link href="style.css" rel="stylesheet" />
The browser understands that this resource is a stylesheet and the processing parsing of the page is not paused (rendering might be paused since the browser needs the style rules to paint and render the page). It is not similar to dumping the contents of the css file inside the style
tag. (Hence is is advisable to use link
rather than @import
for attaching stylesheets to your html document.)
src attribute just embeds the resource in the current document at the location of the element’s definition. For eg. When the browser finds
<script src="script.js"></script>
The loading and processing of the page is paused until this the browser fetches, compiles and executes the file. It is similar to dumping the contents of the js file inside the script
tag. Similar is the case with img
tag. It is an empty tag and the content, that should come inside it, is defined by the src
attribute. The browser pauses the loading until it fetches and loads the image. [so is the case with iframe
]
This is the reason why it is advisable to load all JavaScript files at the bottom (before the </body>
tag)
友情链接
深圳车辆实时定位物联网无线通信有限公司
========================
如需友情链接,发邮件到 lanchh@live.com 联系
========================
志文工作室
厦门地铁
云轻灵网络科技有限公司