How to Crop Food Thumbnails with CSS Object Position

The same crepe image in portrait frames: center crop loses the berries and a left-aligned crop retains them

When a portrait thumbnail cuts off the food, keep object-fit: cover and move the visible crop with object-position. In the example above, aligning a wide crepe image to the left keeps the strawberries in a 4:5 card.

Start with the frame and the detail you need

This AI-generated crepe image is 1536 × 1024 pixels. The strawberries are to the left of the crepe, so a centered portrait crop keeps the crepe but loses the berries. The left-aligned crop keeps the strawberries and cream while cutting off more of the plate on the right.

Keep the card size and shift the crop

Add a class of food-thumb to the image. The ratio reserves a portrait box. cover fills it without stretching the food. Set the horizontal position to the side that contains the important detail. This example changes the alignment while leaving the source file untouched.

.food-thumb {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  object-position: left center;
}
Left-aligned portrait crop showing folded crepes, sliced strawberries, and whipped cream
The CSS applied to the wide source in a 4:5 thumbnail.

In our crop comparison, the centered portrait window started about 358 pixels from the left edge of the original. The left-aligned window started at zero. Both show roughly 819 pixels of the source width. The difference comes from the position, with the ratio and image held constant. See the CSS specification for object positioning.

Check the smallest card and the link preview

Open the card at its narrowest intended size. If the shifted crop still loses too much, choose a wider card, a source with more room around the dish, or object-fit: contain when showing the full photo matters more than filling the frame. A social app may create its own preview crop, so check the sharing image separately. For other source shapes, see portrait, square and wide dessert images.

Find more free food images

Search ingredients, seasonal food and backgrounds in the Image Library.