You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Block] Image - Resized images maintain a fixed height on small screens, distorting image or adding margins #52739
When an image block is resized and the user does not choose a scaling behavior, the image is stretched (compressed) on mobile devices, retaining it's original height while reducing it's width to fit the screen.
If the user chooses the Scale option to contain the image size, there are large white margins added above and below the image on small devices in order to retain the same height.
Step-by-step reproduction instructions
Insert an image into a post
Resize the image to a smaller size, but do not select a scaling option
View the site using responsive tools and observe the image respond by only reducing width
Return to the editor and select Contain under SCALE
Refresh the site, and now observe the margins added to top and bottom of the image, again retaining the height of the image
Screenshots, screen recording, code snippet
Screen.Capture.on.2023-07-18.at.09-45-47.mp4
No Scale Set
"Contain" Scale Set
Environment info
WordPress 6.2.2
Replicated in Gutenberg 16.2.1, 16.2.0, 16.1.2, and with Gutenberg deactivated.
This means that when max-width kicks in, the height is no longer proportional, because it’s using the 472px fixed value, which has precedence over the auto because it's in an element style attribute.
The only solution I see here (other than the contain approach) is to keep height as auto in the element styles. So instead of:
{width:545px;height:472px;}
the element styles should be:
{width:545px;height: auto;aspect-ratio:545/472;}
This will account for the use-case where the aspect ratio is intentionally changed (i.e. when the user intentionally stretched the image in the editor), and will preserve that aspect ratio regardless of whether the preferred width or the max width gets used.
Activity
cuemarie commentedon Jul 18, 2023
Workaround
In the editor, clear out the Height selection and it will default to
Autoand remove the scaling feature. This will correct the issue:Editor

Live Site

sgomes commentedon Jul 19, 2023
Trying this on a different example, the element had the following styles:
But Gutenberg also adds the following:
This means that when
max-widthkicks in, the height is no longer proportional, because it’s using the472pxfixed value, which has precedence over theautobecause it's in an element style attribute.sgomes commentedon Jul 19, 2023
The only solution I see here (other than the
containapproach) is to keepheightasautoin the element styles. So instead of:the element styles should be:
This will account for the use-case where the aspect ratio is intentionally changed (i.e. when the user intentionally stretched the image in the editor), and will preserve that aspect ratio regardless of whether the preferred width or the max width gets used.
annezazu commentedon Jul 25, 2023
@ajlende I see you're working on some image block fixes. Mind taking a look here?
ajlende commentedon Jul 26, 2023
Thanks for the ping. This is another side-effect of #52286 it seems. I'll try to take a look this week.