Difference between SRC and HREF

The SRC and HREF attributes are used to include some external entities like an image, a CSS file, a HTML file, any other web page or a JavaScript file.

Is there a clear differentiation between SRC and HREF? Where or when to use SRC or HREF? I think they can’t be used interchangeably.

I’m giving below few examples where these attributes are used:

  • To refer a CSS file: href="https://stackoverflow.com/questions/3395359/cssfile.css" inside the link tag.
  • To refer a JS file: src="https://stackoverflow.com/questions/3395359/myscript.js" inside the script tag.
  • To refer an image file: src="https://stackoverflow.com/questions/3395359/mypic.jpg" inside an image tag.
  • To refer another webpage: href="http://www.webpage.com" inside an anchor tag.

15 Answers
15

Leave a Comment