html - Difference between SRC and HREF -
SRC
and HREF
attributes to include some external entities Used like an image, a css file, an HTML file, any other web page or javascript file.
Is there a clear discrimination between SRC
and HREF
? When or when should I use SRC
or HFF? I think they can not be used each other.
I give some examples below where these properties are:
- Reference to a CSS file:
href = "cssfile.css" inside the link tag
. - To reference a JS file:
src = "myscript.js"
inside the script tag. - To reference an image file:
src = "mypic.jpg"
inside an image tag. - To reference another webpage:
href = "http: /www.webpage.com" inside an anchor tag
Note: @ John-Yin is more appropriate about changes in glasses.
Yes there are differences between src and href and they can not be used alternately between referenced documents and external resources. For the elements to establish a relationship we use href for src .
The Href (hypertext reference) attribute specifies the location of the Web resource, thus present element (anchor
in the case of a
) or current document ( Iflink
) and destination anchor or resource defined by this attribute When we write:& lt; Link href = "style.css" rel = "stylesheet" />
The browser understands that this resource is a stylesheet and the parsing of
processingpage is not (prevented from rendering) The browser needs style rules to color and render the page). It is similar to dumping the contents of the CSS file inside thestyle
tag Nosrc
(source) attribute only embeds the resource in the current document in place of the definition of the element, for example when the browser searches
& Lt; Script src = "script.js" & gt; & Lt; / Script & gt;
The page is loading and processing is paused until the browser fetches, compiles and executes the browser. This is similar to dumping the contents of the JS file inside the
script
tag, in a similar manner it is a case with theimg
tag, it is an empty tag and content that it comes in. Should be defined by thesrc
attribute. Stops the browser until it loads until it brings the image and does not load. [This is the case with theiframe
]This is the reason that it is advisable to load all JavaScript files below (
& lt; / body & gt;
tag)
Update : For more information about how this is implemented according to HTML5 specs, see @John-Yin.
Comments
Post a Comment