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 trialTushar Das
1,110 PointsDifference between "src" and "href"
Hey, I have a doubt about the use of href and src can't we use href instead of src, well I tried and I couldn't , but why?
2 Answers
Steven Parker
231,236 PointsThose properties do different things, and apply to different elements. An anchor ("a") might have an href property, it describes where the browser should go when you click on the element. Until you click, it does nothing.
An image ("img") might have a src property, it describes where to get the image data to display on the screen. Its function is not dynamic or related to clicking.
Inaki Morton
2,636 PointsThe simple way to see the difference is the href refers to a place inside your web page vs the src refers to somewhere outside the webpage.
Joel Brennan
18,300 PointsJoel Brennan
18,300 PointsHi,
href is generally used for anchor links, src is used to specify the path to the image source.
example image tag:
<img src="img/moon.jpg" />
example anchor link:
<a href="some-other-page.html">Go to some other page</a>
href is also used for linking stylesheets etc..
Does that help at all?