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 trialFrancisco Ugarte
1,066 PointsΒΏ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
Remzi Cavdar
1,227 PointsQuite 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
Ricky Sparks
22,249 Pointshref is for text links while src is for images that are added
Ricky Sparks
22,249 PointsThey have in common is that href is links for text and src is links for images
Francisco Ugarte
1,066 PointsBut src isn't only used with images. For example, it's used with script tags too. :/
Ricky Sparks
22,249 PointsYes 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")
Francisco Ugarte
1,066 PointsFrancisco Ugarte
1,066 PointsThanks!
But my doubt now is Why a css file is linked by a hypertext reference while a script by just source? :/
Dallas Davis
4,129 PointsDallas Davis
4,129 PointsThis ^
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)
Remzi Cavdar
1,227 PointsRemzi Cavdar
1,227 PointsAlso you could relatively point to a file or absolute, for example:
<img src="img/myFile.png">
or<img src="http://hostname/img/myFile.png">
Dallas Davis
4,129 PointsDallas Davis
4,129 PointsThe 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!
Francisco Ugarte
1,066 PointsFrancisco Ugarte
1,066 PointsDallas, 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,