HTML/CSS image link - Is this ok?

I saved my html/css codes to a file on my desktop so the route on my code is rather long. If I submit it will this make a difference? Below for reference:

< img src=“file:///Users/Dave/Desktop/App-Academy/html-css-assessment/images/desert.jpg” width=“344px” height=“194” >
< img src=“file:///Users/Dave/Desktop/App-Academy/html-css-assessment/images/person-avatar.jpg” class=“avatar”
style=“float:left” >

Hi, and welcome to the community!

It’s best practice to use a relative path (in relation to the file you are writing code in) as opposed to an absolute path, as you’ve written above. With an absolute path, the image won’t be found if your files are run on a different computer, because Users/Dave/Desktop won’t exist on that device.

Try replacing your absolute path with this relative path: "/images/desert.jpg" - are you getting the same result? This path identifies the image file in relation to the index.html file, rather than in relation to your device’s file structure, which allows it to be read when the files are read on a different device.

Let us know what happens when you change the path!
Jesse

Gotcha! I was trying to do the relative path but it wasn’t loading. I just did a good amount of digging but didn’t find an answer; for relative path do I need to have the images in the home directory?

Never mind, I got it figured out - I was definitely overthinking it! And thanks so much for your help!

1 Like