0

I'm trying to document a solid explanation between the technicals of the href vs the src attribute.

So with my understanding of href vs src..

  • href - will link other external resources (e.g. <a>, <link>)
  • src - while source attributes will embed and load them in replaced elements (such as the <img>, <iframe>, <script>)

Example:

  • An <a href="http://static-website.com/page"> will link to the page.html in an anchor tag but will not request it automatically or load it's contents directly on the document page.
  • However when using the src attribute in <iframe src="http://static-website.com/page"> it will then actually request it, embed and load the content in the document page.

So if you use an href in a link tag <link href="./css/main.css"> why does it behave as though the CSS style rules have been actually loaded or embedded into the document to style the elements like a src attribute?

Jonathan002
  • 9,639
  • 8
  • 37
  • 58
  • Does this answer your question? https://stackoverflow.com/questions/3395359/difference-between-src-and-href – Turnip Apr 23 '18 at 13:45
  • No, starring at that post actually gave me this question.. He points out that `src` attributes embeds the resource while `href` attributes links the resource. So my confusion from that is our HTML documents should not be styled since the tag does not use the `src` attribute. – Jonathan002 Apr 23 '18 at 13:47
  • The contents of the file isn't embedded in the document - like a script tag would be. It is loaded into memory and the style definitions are used to style the HTML. It isn't really behaving like a script.src attribute. – Turnip Apr 23 '18 at 13:54
  • It's not like `src` and `href` are interchangeable really. Meaning, you can't arbitrarily decide on each element to use either `src` or `href`; it's predetermined what elements take what attribute. It then depends on what that element does with the attribute. There's no general definition of what `src` or `href` *does*, because the attribute itself doesn't *do* anything. – deceze Apr 23 '18 at 13:54
  • @deceze I know the src and href attribute are predetermined in their elements, but in my document, I'm trying to explain why the authors of HTML have decided to have 2 attribute names instead of one for connecting external resources to the document. Looking around and in the post linked, it seems apparent that src embeds and href links. – Jonathan002 Apr 23 '18 at 14:08
  • *"This document `a`nchor `h`yperlink-`ref`erences this other document…", "the `s`ou`rc`e for this ` – deceze Apr 23 '18 at 14:12

0 Answers0