What is the differences btw <...href... and <...src...>? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 6

What is the differences btw <...href... and <...src...>?

6th Nov 2017, 6:54 PM
Crazed
Crazed - avatar
4 ответов
+ 9
SRC isn't isolated to images. For example, think about <script> tag for JS, it also uses src. SRC is used to load resources into the page and HREF is used to link to a resource external for the page. As such, when you use src it's taking place during that loading phase, which is why we often place our JS scripts at the bottom or inside of the ready so it'll only load once everything else is done loading. As for HREF, the page continues to do its thing and doesn't wait for the HREF to download its resource.
6th Nov 2017, 7:10 PM
AgentSmith
+ 7
@Netkos Ent has it. Questions like this just make me go digging. Because I didn't have this straight myself (and I may have made an error), I intend this only to add on to @Netkos Ent's shorter, faster answer. Up to HTML 4 [1] 'src' is used when the resource REPLACES the element. Replaced elements [2] [3] are independent of the CSS formatting model Replaced elements are fetched immediately and pause parsing 'href' establishes a relationship between the document and external resource. They do NOT pause parsing (may pause rendering). Also noted: same consideration for css link= and @import In HTML5: <script> can now take "async" and "deferred" attributes* [link 1] links to the answer directly below it, which explains them. [1] https://stackoverflow.com/a/7794936/3981745 [2] https://developer.mozilla.org/en-US/docs/Web/CSS/Replaced_element [3] https://www.sitepoint.com/replaced-elements-html-myths-realities/ * I knew about this, but I really didn't think it mattered until just now.
6th Nov 2017, 9:50 PM
Kirk Schafer
Kirk Schafer - avatar
+ 4
thank you
7th Nov 2017, 8:06 AM
Cristina Zamora
Cristina Zamora - avatar
+ 4
@Kirk Thanks for adding onto it all bro! Nicely done as well.
7th Nov 2017, 2:01 PM
AgentSmith