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!

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


[Solved] Unable to link Images

I'm working on the Front-End Web Development track and I was following along with Sublime Text 2, but when I tried to link images to the HTML document they weren't displayed. My browser is Firefox and the site is still offline. I've tried different addresses but none seemed to work. My code is below.

<!DOCTYPE html>
    <meta http-equiv = "Content-Type" content = "text/html; charset = utf-8"/>
    <title>Smells Like Bakin' Cupcake Company</title>
    <link rel = "stylesheet" href = "css/normalize.css" type = "text/css" media = "screen">
    <link rel = "stylesheet" href = "css/grid.css" type = "text/css" media = "screen">
    <div class = "container clearfix">
        <div class = "grid_4">
            <img src = "img/logo.gif" alt = "Smells Like Bakin">
        <div class = "grid_8 omega">
            <ul class = "nav">
                <li><a href = "#">About</a></li>
                <li><a href = "#">Cupcakes &amp; Prices</a></li>
                <li><a href = "#">Locations</a></li>
                <li class = "last"><a href = "#">Contact Us</a></li>
        <div id = "intro" class = "grid_9">
            <h1>Opposites really do attract, especially in our kitchen! We combine unexpected flavors that melt together to create ironically delicious desserts.</h1>
            <p><a href = "#" class = "btn">Browse Our Cupcakes</a></p>

        <div class = "grid_3">  
            <img src = "img/you-bake-me-blush.gif" alt = "You Bake Me Blush">

        <div id = "featured-cupcake" class = "grid_7">
            <h2>Cupcake of the Week</h2>
            <p>This weeks featured cupcake is the <a href = "#">Avocado Chocolate cupcake</a>. Its strange combo of flavors will kick your taste buds into fiesta mode!</p>
            <img src = "img/featured-cupcake.jpg" alt = "Avocado Chocolate Cupcake">

        <div id = "new-cupcakes" class = "grid_5 omega">
            <h2>Fresh Out the Oven</h2>
            <p>Our newest cupcakes are <a href = "#">Bacon Me Crazy</a> and <a href = "#">Jalapeño So Spicy</a>.</p>
            <img src = "img/new-cupcake-bacon.jpg" alt = "Bacon Me Crazy">
            <img src = "img/new-cupcake-jalapeno.jpg" alt = "Jalapeno So Spicy">

        <div class = "grid_7">
            <h2>Inside the Kitchen</h2>
            <p>Smells Like Bakin' started out in the garage of the husband wife duo Allison &amp; Joseph. Allison is the baker, and Joseph found a way for them to make a business out of her tasty treats. Flash forward to today and they have a successful store front, catering business and cupcake truck.</p>
            <p><a href = "#" class = "btn-small">Read More</a></p>

        <div class = "grid_5 omega">
            <h2>Get Bakin' with Us</h2>

            <div id = "contact">
                <p>Call us: <span>1-555-CUP-CAKE</span><br>
                Email us: <a href = "#">bakeon@smellslikebacon.com</a>

            <p>We announce all of our new flavors first through Facebook &amp; Twitter, and even take requests!</p>
            <a href = "http://www.facebook.com/SmellsLikeBakin"><img src = "img/facebook.gif" alt = "Facebook"></a>
            <a href = "https://twitter.com/#!/smellslikebakin"><img src = "img/twitter.gif" alt = "Twitter"></a>

        <div id = "copyright" class = "grid_12">
            <p>&copy; 2012 Smells Like Bakin' Cupcake Company. All Rights Reserved.</p>


3 Answers

You are adding unnecessary spaces between your attributes and values, you need to remove them, there should be no space between the attribute (src) and the value (="img/logo.gif") - See below.

Original: <img src = "img/logo.gif" alt = "Smells Like Bakin">

Correct: <img src="img/logo.gif" alt="Smells Like Bakin">

I tried that but the images aren't appearing. Maybe my address is wrong, should it start at the C drive?

Thanks, It seems I thought it was just preference.

not a problem! Its a common mistake because people see the space between the element and the attribute and think the same thing applies with the attribute and the value!

Well, I tried deleting the spaces and it seems I have another error. I think it might be the addresses to the images. Should they start at the C drive? How high up the tree do they need to go?

(I'll assume you've downloaded and extracted the course images and have not re-named them)

  • Create a folder on your desktop, call it Website (or anything it's not important)
  • Inside the Website folder you must save your current sublime/html file inside as index.html
  • Inside the Website folder you must also create a folder called img - this is where you must put all the extracted course images
  • if done correctly your browser should be able to locate the images within the img folder

Thanks! It finally worked. I've been working for quite some time on this. I thought the image files could be located anywhere on the hard drive.

James Barnett
James Barnett
39,199 Points

> I thought the image files could be located anywhere on the hard drive.

They can be as long as you use the correct path.

further reading

James Barnett
James Barnett
39,199 Points

> I thought it was just preference

It is just a preference, it will validate just fine.

OK, now I get it. I was having a lot of difficulty in finding websites that explained. They usually just tell you <img> syntax, but not where to link them .

No worries my friend! When working with html/css you need to create a root folder to keep all your files within so the browser knows exactly where to look and find everything!

You can name the root folder anything but you must save your html file inside as index.html. The root folder must also contain a folder for your images (it's good practice to name the folder either img or images) and any other files you want to display on your website (including CSS files)

James Barnett
James Barnett
39,199 Points

> The root folder must also contain a folder for your images must also contain a folder for your images

That's actually more of a preference or a convention rather than a requirement of the way HTML works.