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 Organize with Unordered Lists

I am trying to add images to my unordered list.

I am trying to add images to the unordered list, but do not have a menu on the left. Have I missed a step?

8 Answers

Justin Green
Justin Green
16,430 Points

Hi Dana - Can you post your code. Would be happy to take a look.

DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Nick Pettit</title> 6 </head> 7 <body> 8 <header> 9 <a href="index.html"> 10 <h1>Nick Pettit</h1> 11 <h2>Designer</h2> 12 </a> 13 <nav> 14 <section> 15 <ul> 16 <li><a href="index.html">Portfolio</a></li> 17 <li><a href="about.html">About</a></li> 18 <li><a href="contact.html">Contact</a></li> 19 </ul> 20 </nav> 21 </header> 22 </section> 23 <footer> 24 <p>© 2013 Nick Pettit.</p> 25 </footer> 26 </body> 27 </html>

That didn't work...let me try again.

I am using an iPad at the moment and can't figure out how to do it. I don't see a tilde or a back tic.

Justin Green
Justin Green
16,430 Points

No worries. An image in an ordered list would like something like this:

<section>
    <ul>
          <li>
               <a href="image url"></a>
          </li>
    </ul>
</section>

The image would be nested inside of the list item tag. Will wait for your reply to check again. Hope this helps.

-JG

Jacques Vincilione
Jacques Vincilione
17,292 Points

That would not work if she was trying to actually show the image. See my answer below.

Maybe I am overthinking this. I was assuming I would have an image file like Nick did. But maybe in the tutorial I am only writing the code. I'll let you know. Thanks.

Justin Green
Justin Green
16,430 Points

Not at all. Replace the "image url" from the above code with your file path for the image.

<section>
    <ul>
          <li>
               <a href="img/example-image.jpg"></a>
          </li>
    </ul>
</section>

Let me know if this works.

Jacques Vincilione
Jacques Vincilione
17,292 Points

So, if you want to just link to an image, but not show it, you can use Justin Green's solution, however, if you want to actually display the image you have two options:

  1. HTML only, you can also add an anchor tag around the image if you want it to be a link.
<section>
    <ul>
          <li>
               <img src="img/example-image.jpg" alt="My Example Image" />
          </li>
    </ul>
</section>
  1. This solution uses a CSS background image to show the image.
<section>
    <ul>
          <li>
               <div id="myImage"></div>
          </li>
    </ul>
</section>
#myImage {
    background: url("img/example-image.jpg") no-repeat;
    width: 100px; //this would be the image width
    height: 100px; //this would be the image width
}

While both would work, I would suggest the first solution due to the SEO benefits of the alt property on the img tag. Although, there are other ways to get that same benefit using CSS.

Justin Green
Justin Green
16,430 Points

Good catch! Not sure what I was thinking there. Thanks for sharing the CSS background option.