Web Analytics Made Easy -
StatCounter do you put width and height attributes on your <img />s? - CodingForum

Announcement

Collapse
No announcement yet.

do you put width and height attributes on your <img />s?

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

  • do you put width and height attributes on your <img />s?

    i have gotten in the habit of not doing so, with rare exception. i fail to see the need. i have never had any problems with <img /> boxes taking on wacky proportions as a result of this practice. and especially if you need to adjust the slicing of a larger graphic, or simply the dimensions of a whole one, leaving the markup dynamic just makes the most sense to me. but i see width and height attributes all the time, so are there some advatages to using them that i'm not familiar with?

  • #2
    Both those attributes are depricated no? I never use them, I never set a width for any image.
    Omnis mico antequam dominus Spookster!

    Comment


    • #3
      Helping the browser

      Back in the good ol' days, explicitly setting width and height on images was meant to help the browser reserve a space for it before the actual image was loaded, thus preventing the need for re-rendering the page every time an image finished loading.

      Since these attributes are deprecated, width and height would have to be set through a style sheet, or - and this is probably one of the rare appropriate applications of it - through an inline style on the image itself.
      Seperation of content and presentation gets fuzzy here, since the width and height of an image - when used as content - arguably are aspects of content, and not of presentation.
      Regards,
      Ronald.
      ronaldvanderwijden.com

      Comment


      • #4
        hmm. i can see your point i suppose, but it always seemed like this supposed "re-rendering" you speak of was no different than how the browser shifts content when the window itself is resized. and this doesn't involve any actual re-rendering (as far as downloading).
        Last edited by coder_seth; Feb 12, 2004, 05:33 AM.

        Comment


        • #5
          Re-rendering revisited

          The difference there is that on resizing a page already loaded, the browser has all the page elements in cache and "knows" how much room the various elements require; it only needs to shift them around a bit.

          On loading a new page, laden with images, the browser first renders the page with all the readily available elements (text, etc.), then for each image finishing loading, it has to rearrange the page to acommodate that image, which may need more space then initially acounted for.

          Try refreshing the main page or a forum main page on this site to see the effect of image placeholders being replaced by actual images.
          Regards,
          Ronald.
          ronaldvanderwijden.com

          Comment


          • #6
            Discussed previously. I hold with my argument.

            The attributes ARE NOT deprecated, by the way. Look at the XHTML Strict DTD, and do a text search for 'height' (Ctrl+F in most browsers). Should be the second item that comes up. Here's a quote if you can't be bothered:
            Code:
            <!ELEMENT img EMPTY>
            <!ATTLIST img
              %attrs;
              src         %URI;          #REQUIRED
              alt         %Text;         #REQUIRED
              longdesc    %URI;          #IMPLIED
              [color=red]height      %Length;       #IMPLIED
              width       %Length;       #IMPLIED[/color]
              usemap      %URI;          #IMPLIED
              ismap       (ismap)        #IMPLIED
              >
            David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
            W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

            Comment

            Working...
            X