basic newbie question about images in html

Discussion in 'HTML & Website Design' started by Will1987, Mar 8, 2010.

  1. #1
    Hi,

    just starting out. I'm trying to put your basic image in the html code with the "<img src=" tag. I was on a tutorial and they say that in this you basically tell the browser what the url of the image is. Yet in their example it wasn't a url but, it seems, just the file that was listed, like, well here's the actual example in the tutorial: <img src="w3schools.jpg" width="104" height="142" /> - how's that a url? Don't you need the: http://www. etc?

    Probably some simple answer but I can't seem to find it at the moment.

    thanks a lot,

    Will MacBride

    also I was wondering: does it have to come from a web address? i.e. if I have a picture on a hard drive I want to put on a website I'm designing, woulc I have to upload that to some website (i.e. photobucket or something) and then reference it? Or could I reference it somehow just from my hard drive somehow?
     
    Will1987, Mar 8, 2010 IP
  2. adityastar

    adityastar Active Member

    Messages:
    164
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #2
    If u use only the file name then it will work as long as the file is in the directory where your HTML file is.

    For ex.

    If your images are stored in images folder and your url to image is : http://www.yourdomain.com/images/abc.jpg

    then you can use either the full url or just images/abc.jpg

    Both will work.
     
    adityastar, Mar 8, 2010 IP
  3. drhowarddrfine

    drhowarddrfine Peon

    Messages:
    5,428
    Likes Received:
    95
    Best Answers:
    7
    Trophy Points:
    0
    #3
    More info: when you just use the file name it's called a relative path meaning it's relative to the location of the page being accessed. If you give the full URI, then that's called absolute pathname.
     
    drhowarddrfine, Mar 8, 2010 IP
  4. harryhood

    harryhood Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yeah.

    image.jpg are just images that you have uploaded on your server.
    You could put the entire URL and it would work the same.

    You do need the entire URL for images that are not in your directory.
     
    harryhood, Mar 8, 2010 IP
  5. Will1987

    Will1987 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for those there clraificationalities folks... The thing is, right now I'm writing a page in notebook - it's not uploaded to any server yet. I tried just putting the file name and it didn't work. Come to think of it maybe it wasn't in the same directory i.e. I didn't put the full path. That should work if I'm just writing the page in notebook right?

    thanks a lot,
    Will
     
    Will1987, Mar 9, 2010 IP
  6. Mentalhead

    Mentalhead Active Member

    Messages:
    1,344
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    53
    #6
    Like people said you have to follow the certain path to the image.
    Easiest way, and the common way is to put all images in images folder.
    For example you've made new folder called "My Website" in My Documents, now you store all your .html files in that folder (My Website folder).
    If you store any images in that folder then you can just write the filename <img src="image.jpg" />
    But if you create another folder inside the My Website folder named "images" for example and put images on it you have to specify the path. Same goes when you put your files on some server.
    So in that case the img code would look like:
    <img src="images/image.jpg" />
    As you see you don't need to specify the whole path because the folder where you store your index.html file (in this case My Website folder) is considered as root folder.
     
    Mentalhead, Mar 9, 2010 IP
  7. rediska

    rediska Peon

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Note: Use relative paths - it is much easier (for you, for the server and Apache)
     
    rediska, Mar 10, 2010 IP