Web Analytics Made Easy -
StatCounter HTML code for putting in images - CodingForum

Announcement

Collapse
No announcement yet.

HTML code for putting in images

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • HTML code for putting in images

    Every time i try writing the code to put in an image and i veiw the page it appears as a little swuare with the red x in it. What is the exact code for images. and i write everything in notepad.

  • #2
    <img src='pathToFile' alt='' /> and path to the src has to either be an absolute path name to the image or a relative path starting from the directory your html file is in.

    Can you post the code that is not working for you.

    Comment


    • #3
      I had it in a sapre notepad file but i deleted it yesterday i think the problem was ia wasnt filling out the alt attribute in it whaat does that do?

      Comment


      • #4
        a missing alt attribute in an <img /> won't stop the image from displaying as long as the path to the images in the src is correct.

        The alt attribute is meant to just display "alternate text" if an image in the src is not found and for screen readers to read for their users. Some browsers also display the alt text when you hover over an image, but the title attribute is best used for that.

        Comment


        • #5
          Oh is the alt an alternate path fro the HTML file like you were saying.

          Comment


          • #6
            so even if i need to put the alt atribute do i still have to do the alt=' ' />

            Comment


            • #7
              Originally posted by Javake View Post
              Oh is the alt an alternate path fro the HTML file like you were saying.
              no no no

              Have a look at the link I posted for the img element, but here is a quick example
              Code:
              <img src="./pics/myPic.jpg" alt="My favourite photo" />

              Comment


              • #8
                i put <img src='C:\Users\Reb\My Pictures\Downloads\anonymous.jpg' />
                And it still did the red x but im also diplaing the html file in IE is that what is causing it or is it i wrote the path wrong. Cause i cant find where it says the full path of the image in my computer. ( i have windows 7)

                Comment


                • #9
                  Ok i see but i still dont know where to find the path to the image. im looking at in in my pics but i cant find where it displays the path. it displays half of it in the properties of the photo but not the second half. Total noobie status
                  '

                  Comment


                  • #10
                    ok, do the following and it should work. It's usually better to use relative rather than absolute paths

                    1 - put your html file in C:\Users\Reb\My Pictures\Downloads where your image currently is. Let's call the html file myFile.html if you like.

                    2 - then in myFile.html in the <body> add

                    Code:
                    <img src="anonymous.jpg" alt=" my anonymous photo" />
                    3 - save and close the html file and then double click it and it should open up in your default browser with the image displayed.
                    Last edited by webdev1958; Aug 28, 2011, 06:22 AM.

                    Comment


                    • #11
                      OK it worked thanks a TON man, i was lost with the whole path part. Now when you write the path is it supposed to be the file location or the path from the html file to the img you want to post?

                      Comment


                      • #12
                        Nevermind you already said that in your earlier posts. Well thanks man you helped alot.

                        Comment


                        • #13
                          pheeww - glad it's sorted

                          Now when you write the path is it supposed to be the file location or the path from the html file to the img you want to post?
                          Normally, the images for a website will be in a sub folder of the site's home folder. Then when you specify the path in a src it can be either a full(absolute) path or a relative path from the folder the html file is in as you have done now and it works.

                          Normally I specify relative path names, so my suggestion to make things easier for you, is to create a "work area" folder somewhere on your C: drive and put your html files in that folder. Under that work area folder create a sub folder called pics and put all your images in there for the current exercise.

                          Then in your html files when you need to display an image just do this
                          Code:
                          <img src="./pics/myPic.jpg" alt="" />
                          Last edited by webdev1958; Aug 28, 2011, 06:36 AM.

                          Comment


                          • #14
                            Thats a good idea. Now i was making a website and the code for it isnt a file is a file i saved in my computer put i jsut copy pasted it into a section for html code in the website editor. So if i want to put an img on there would i be writing the same path?

                            Comment


                            • #15
                              What i mean to say is how am i supposed to write a path when the code isnt saved on my computer so it doesnt have a starting point if ia did a relative path, so wh=ould i ahve to do a absolute path for my website.

                              Comment

                              Working...
                              X