# CSS aspect-ratio: Responsive Boxes, Images and Videos

DevFeed: [CSS aspect-ratio: Responsive Boxes, Images and Videos](<https://devfeed.tech/articles/css-aspect-ratio-responsive-boxes-images-and-videos-130904.md>)

Original publisher: [Read original article](<https://markodenic.com/css-aspect-ratio/>)

Author: Marko

Published: 2026-11-12T09:00:00Z

Content type: article

Language: en

Sources: [Marko Denic Blog](<https://devfeed.tech/sources/marko-denic-blog.md>)

Topics: [CSS](<https://devfeed.tech/topics/css.md>), [Responsive Design](<https://devfeed.tech/topics/responsive-design.md>), [Image](<https://devfeed.tech/topics/image.md>), [Front end](<https://devfeed.tech/topics/frontend.md>), [Web Development](<https://devfeed.tech/topics/web-development.md>), [performance-optimization](<https://devfeed.tech/topics/performance-optimization.md>)

Tags: [absolute](<https://devfeed.tech/tags/absolute.md>), [ads](<https://devfeed.tech/tags/ads.md>), [aspect](<https://devfeed.tech/tags/aspect.md>), [auto-fill](<https://devfeed.tech/tags/auto-fill.md>), [avatar](<https://devfeed.tech/tags/avatar.md>), [background](<https://devfeed.tech/tags/background.md>), [border-radius](<https://devfeed.tech/tags/border-radius.md>), [css](<https://devfeed.tech/tags/css.md>), [hack](<https://devfeed.tech/tags/hack.md>), [images](<https://devfeed.tech/tags/images.md>), [images-and-videos](<https://devfeed.tech/tags/images-and-videos.md>), [layout](<https://devfeed.tech/tags/layout.md>), [object-fit](<https://devfeed.tech/tags/object-fit.md>), [padding](<https://devfeed.tech/tags/padding.md>), [property](<https://devfeed.tech/tags/property.md>), [ratio](<https://devfeed.tech/tags/ratio.md>), [responsive](<https://devfeed.tech/tags/responsive.md>), [shift](<https://devfeed.tech/tags/shift.md>), [square](<https://devfeed.tech/tags/square.md>), [tutorial](<https://devfeed.tech/tags/tutorial.md>), [videos](<https://devfeed.tech/tags/videos.md>), [web-development](<https://devfeed.tech/tags/web-development.md>)

## AI overview

CSS `aspect-ratio` sets a preferred width-to-height proportion, letting the browser calculate a dimension when one is `auto`. The excerpt shows using `width: 100%` with `aspect-ratio: 16 / 9` for responsive video embeds, and `object-fit: cover` to crop images into consistent square or card-shaped boxes. Image `width` and `height` attributes let browsers reserve space before loading; CSS can then scale images responsively. Ratios can appear overridden when both dimensions are fixed, content forces a box taller, flex or grid stretching sets the height, or the element is inline. The excerpt suggests making a dimension automatic, setting `min-height: 0` and overflow for text boxes, or aligning flex and grid items to the start.

## Source excerpt

How the CSS aspect-ratio property works: responsive 16:9 videos without the padding hack, square and portrait images with object-fit, avoiding layout shift, and why aspect-ratio sometimes seems ignored.