Why is it needed

Discussion in 'HTML & Website Design' started by oo7ml, Aug 12, 2007.

  1. #1
    Why is it important to put a width and a height attribute in an image

    <img src="images/example.jpg" width="40" height="40">

    compared to this:

    <img src="images/example.jpg">


    I've noticed that sometimes Dream weaver automatically puts them in and other times it doesn't
     
    oo7ml, Aug 12, 2007 IP
  2. qazu

    qazu Well-Known Member

    Messages:
    1,834
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    165
    #2
    It's good practice to include width and height so that the image is not distorted.
     
    qazu, Aug 12, 2007 IP
  3. sogastic

    sogastic Peon

    Messages:
    202
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have used <img src="images/example.jpg"> and works with opera ie and firefox. But some non-popular browsers may need width and height.
     
    sogastic, Aug 12, 2007 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #4
    If you are rendering inside a dynamic size container, putting the width and height in the HTML let's that container render onscreen at the proper size BEFORE image loading starts. If you omit those most browsers will either hold off on rendering the container (especially if said container is a table), or have to 'shift' the design around on screen once it starts loading images, leading to a layout that 'jumps' into place. (as if that doesn't happen enough already with CSS)

    Because it's extra bytes it actually makes the page take longer to load, but it gives the illusion of the page loading faster... it's one of those performance vs. user experience things.
     
    deathshadow, Aug 12, 2007 IP