object-fit for Responsive Images in CSS


Control how content fills its container while preserving aspect ratio with object-fit.

Source Code

img {
    width: 100%;
    height: 200px; /* Set a height to see the effect */
    object-fit: cover; /* Options: fill, contain, cover, none, scale-down */
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments