So, I know that I can make a custom featured-image size by adding this to my functions.php file:

add_image_size('newsize', 883, 300, true);

and calling it with:


But, I also have CSS rules to make images responsive by including:

img { display:block; width:100%; height:auto; }

So, what's happening is, if someone uploads an image that exceeds the image size I specified (883x300), then the image is cropped, and when I call it, I get a perfect 883 x 300 image.

Unfortunately, if I have an image that is smaller than those dimensions, the function still works as it should (cropping the width or the height if they exceed), but then the image falls short of filling that canvas space (883 pixels.)

So for example, if I load an image that is 500x350 in the featured image, normally calling that featured image would output a 500x300 image, but because images are meant to be responsive, CSS stretches that image to be 883 pixels wide, the size of the div. That, in turn, makes the height larger, as it stretches both dimensions. It's imperative that the image height does not exceed 300 pixels.

So... how can I have my cake and eat it too? Is there a way I can force a smaller image into a 883x300 canvas before my CSS gets to it to stretch it out?

Many thanks, WA

  • You can put min-width:xxx px; where xxx px is the minimum width of each breakpoint size. I've tried it into a theme I am developing, the downsize is that I have to use either javascript or the full image for these situations.
    – Panagiotis
    Commented Mar 7, 2014 at 22:09

3 Answers 3


You can wrap the image in a figure.

<!-- html -->
<figure class="constrained-container">
    <img src="my-image.jpg" alt="What my image is about"/>

Then style the figure as well as the image.

/* css */
.constrained-container {
    height: 300px;
    overflow: hidden; /* this hides excess of the image */
.constrained-container img {
    display: block;
    width: 100%;

So if you know your height of image is 300px, then not put height auto in css make it 300px. ( or adjust height according to your design )

img { display:block; width:100%; height:300px; }
  • this will not work in all cases, if I set a CSS rule to keep it 300px, the image will get stretched, as its natural size would be 500x300, width 100% would make it 883px by 300px. It's getting cropped before CSS is applied to it.
    – RCNeil
    Commented May 20, 2013 at 17:10
  • can you give me link of you site ? Commented May 20, 2013 at 17:19
  • Is hiding the overflow of the img container not enough ? .container { width: 883px; height: 300px; overflow: hidden; } .container img { width: 100%; height: auto; } The image is not cropped but it looks cropped. You could use % instead of px to define container size.
    – Simon
    Commented Nov 22, 2013 at 14:43

When dealing with the images in responsive site, i enclose the image in a div and i fix the image width (in percentage) you need not fix the height.Irrespective of the image size it will be responsive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.