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 Build a Simple Website Text Editors and HTML Images and Lists

adding an image

So here is my code, any ideas why it's not working?

<!-- img src="cupcake.jpg" alt="cupcake" / -->

I added the comment so it would appear in the forum... I tried it with an open ended tag and closed tag

James Barnett
James Barnett
39,199 Points

> I added the comment so it would appear in the forum

The forum uses markdown to correctly format code, check out this thread on how to type code in the forum for some examples.

8 Answers

src should also include the directory. They mention it is in the directory of "img" (a common practice) and as such should be listed as src="directory/file.extension" so if I had an image named "headerimage.jpg" in my img directory, it would be: html <img src="img/headerimage.jpg" alt="headerimage"></img> trying to not just give the direct answer to the code challenge away... sorry.

where do I find the directory/filepath?

Mattia Gobbi
Mattia Gobbi
4,595 Points
<img src="cupcake.jpg" alt="cupcake">

Is this the code you tried? It should work. If no image is showing the reason is because the file cupcake.jpg is not in the same folder as the HTML file.


Please refer to the answer of James, I didn't notice that the question was strictly related to a code challenge!

Where is it and how do I move it?

Because thats exactly what my code looks like. I am used to Textastic, an iPad editor. It makes thing much easier and way more user friendly

they mention that the image is inside the directory img so,

<img src="img/cupcake.jpg" alt="cupcake"></img>

I'm on my way again, thanks for the help guys!

James Barnett
James Barnett
39,199 Points

Sounds like you've got a file path issue with your images.

The way it works is that you have to put your images in the correct folder relative, to your HTML file.

Here's an example:

file directory structure example

Does that help?

If not, you can read up about absolute vs relative paths