Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML How to Make a Website Creating HTML Content Include External CSS

ΒΏWhat is the difference between href and src for a browser?

In a Html document is used href in elements like "a" and "link", and src in "img", and other tags.

So, What do they have in common for a navigator, the elements using href and those using src?

4 Answers

Quite simple, if you remember that "src" means source, meaning the source where it points to, so in other words you're pointing to a file and href is an abbreviation for "Hypertext REFerence"

See: http://www.w3schools.com/tags/att_a_href.asp and http://en.wikipedia.org/wiki/Hyperlink Hope this clear things up :)

Cheers,

Remzi

Thanks!

But my doubt now is Why a css file is linked by a hypertext reference while a script by just source? :/

This ^

My (admittedly limited) understanding of the two is as follows:

src tells the browser where to look for an element to be put on or into the page (the source of where something is coming form)

href tells the browser where the element should point. (the direction that element should point)

Also you could relatively point to a file or absolute, for example: <img src="img/myFile.png"> or <img src="http://hostname/img/myFile.png">

The answer is not a short one, and I wouldn't want to take credit for somebody else's answer, but I found a very good, very detailed answer here...

http://stackoverflow.com/questions/3395359/difference-between-src-and-href

It directly answers the css vs script question :D

I'm going to go read it myself ;)

Good questions! Thanks!

Dallas, that is the post i was looking for, it even includes the differences respect to the HTML5 spec, it's pretty complete,

thanks very much ;D,

Ricky Sparks
Ricky Sparks
22,249 Points

href is for text links while src is for images that are added

Ricky Sparks
Ricky Sparks
22,249 Points

They have in common is that href is links for text and src is links for images

But src isn't only used with images. For example, it's used with script tags too. :/

Ricky Sparks
Ricky Sparks
22,249 Points

Yes that is true :) here is some more info

ex: <script src="URL">

The URL of the external script file.

Possible values: 1.An absolute URL - points to another web site (like src="http://www.example.com/example.js")

2.A relative URL - points to a file within a web site (like src="/scripts/example.js")