9

Again while typing I read this question but that's a different one...and that too is not solved yet, as the person who's answer is marked as correct, says this in the end

I don't know direct answer to your question, but I'm pretty curious about tag, too. Finding answer would probably include some web archives digging.

So the question is quiet simple, why are we using src attribute for <script> tag but href for a <link> tag, now that confuses me many times when am including stylesheets and scripts...why it can't be same? any specific reason for this?

For example

<script href="#"></script>
<link href="#" />

Or

<script src="#"></script>
<link src="#" />
Community
  • 1
  • 1
Mr. Alien
  • 153,751
  • 34
  • 298
  • 278

1 Answers1

9

A link points somewhere via a hypertext reference (hence href). This is why we use <a href too.

A script takes its source from elsewhere and is embedded into the current page, hence src. Compare <img src

EDIT: Of course, another equally valid answer would be "It just does!" :p

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • Oh yea so for embedding some stuff you need `src` for example flash object too right? – Mr. Alien Dec 20 '12 at 04:48
  • Great, thank you, now this is clear and a simple example..thanks – Mr. Alien Dec 20 '12 at 04:50
  • While this answer is not wrong, it could benefit from clarification. There is a more comprehensive answer at this question: [Difference between SRC and HREF](http://stackoverflow.com/questions/3395359/difference-between-src-and-href/21549827) – gfullam Sep 23 '15 at 17:27
  • Well if you are "linking to" a style-sheet you are really adding those styles to your page, not just "referring" to those styles, you are ADDING THEM TO YOUR PAGE. Not much different from how applying an IMG to your page changes how the page looks. So while the explanation is good for why "A" tag uses "href" not so much for "link". Also when creating a hyperlink its target does not get downloaded until you click the link. But when "linking" a style-sheet with href it does. – Panu Logic Jul 01 '19 at 12:45
  • 1
    As @PanuLogic mentioned, link with href or img with src will bring both style and image into the page and show it to the user. So, I am having trouble understanding why can't we interchange them then? Like what is the fundamental difference that prevents link with src from working? Ok, so browser will wait for css file to download if I use src but then the changes should reflect soon right? I have a simple css file (in KBs) which should be downloaded when using link with src but css doesn't reflect in browser then. So, what is this fundamental difference? – Prasanjit Rath Aug 28 '21 at 07:42
  • @Prasanjit Rath : It might be better if there was just one attribute for all of them, it would make it easier to remember. Simplicity is good. But as of currently it is a matter of semantics, a script does have its "source" somewhere and the src -attribute tells the browser where to get it from. But a link does not have a "source" because it is not a program. It is just a reference to some other file. – Panu Logic Apr 25 '22 at 18:04