Skip to main content
Inspiring
July 31, 2022
Question

Stated image dimesions is incorrect

  • July 31, 2022
  • 2 replies
  • 882 views

Looking at a page with images I notice the sizes are set thus width="300" height="300"

On the page the images look OK

The images are larger than these measurements but do vary.

As this is dynamic page which pulls in a variety of images,

is it best to go for the largest image size allowed by the website.

I think the size stated causes errors with the Google robot.

Many thanks for your advice.

John

    This topic has been closed for replies.

    2 replies

    Nancy OShea
    Community Expert
    Community Expert
    July 31, 2022

    Your images should be scaled to required size and optimized for the web BEFORE they are uploaded to your server.

     

    OPTION 1: USE RESPONSIVE IMAGES WITH <PICTURE> TAG

    Photoshop's ExportAs feature is a good tool for this.  It permits you to create 1x, 2x and 3x sized images for various devices.  Combined with <picture> tag and srcset attribute, you can deliver the ideal sized image to appropriate devices, thus reducing excess bandwidth to mobile users.

     <picture>
      <source media="(min-width: 650px)" srcset="big_image.jpg">
      <source media="(min-width: 465px)" srcset="med_image.jpg">
      <img src="smallest_image.jpg">
    </picture> 

     

    OPTION 2: USE CSS PERCENTAGE WIDTHS

    • img {max-width:100%}  downscales images to fit smaller devices but maintains native file size on large devices.
    • img {width: 100%} downscales & upscales images to fit any device however distortion & pixelation may occur. 
    • Remove HTML height and width values from code.

     

     Hope that helps.

     

    Nancy O'Shea— Product User & Community Expert
    Inspiring
    July 31, 2022

    Thanks very much for all of that information.
    The images size is set to 900 x 900 using P S Elements

    Would this be the way to go
    <img src="img_test.jpg" alt="Nature" class="responsive" width="100%" height="auto">
    Taken from www.w3schools.com
    Regards

    John

    Legend
    July 31, 2022
    quote

    Thanks very much for all of that information.
    The images size is set to 900 x 900 using P S Elements

    Would this be the way to go
    <img src="img_test.jpg" alt="Nature" class="responsive" width="100%" height="auto">
    Taken from www.w3schools.com
    Regards

    John


    By @johnhardy10

     

    You can do but its better to seperate out your html mark up and css. 

     

    <img src="img_test.jpg" alt="Nature" class="responsive">

     

    Since the img has a class of repsonsive you can create a css selector for it and include it in a css stylesheet which is then linked to your page;

     

    /* CSS SELECTOR */

    .responsive {

    max-width: 100%;

    height: auto;

    }

     

    max-width will stop the image growing beyond its natural width. Once an image grows beyond its natural width it will deteriorate.

    Legend
    July 31, 2022

    It does not matter that the images are larger than the size they will appear on the website. However good practice is to deliver them close to the largest size that they need to appear on your website and certainly they shouldn't be so large as to cause issue like  being slow to download. A better practice is to use srcset to deliver images optimised for the device that they will be viewed on, you don't really want a 1500px wide image to be delivered on a 600px wide screen, that's were srcset can deliver the size of image applicable for the width of the screen.

     

    Also adding px width and height directly to the img tag itself will make the image non responsive so l don't advise doing so unless you are developing a static width website for desktop. Infact using px to declare width is generally bad practice in most cases. You should be using percentage width or another flexible unit like em as they respond to a variety of screen width sizes.