-
Hajipur, Bihar, 844101
object-fit
?The CSS object-fit
property specifies how the content of a replaced element (like <img>
, <video>
, or <iframe>
) should be resized to fit its container box.
It controls how the image or video scales and crops to fill the space without distorting the aspect ratio.
object-fit
Value | Description |
---|---|
fill |
Stretches the content to fill the container, ignoring aspect ratio (may distort). |
contain |
Scales content to fit inside container while maintaining aspect ratio (may leave empty space). |
cover |
Scales content to cover the entire container while maintaining aspect ratio (may crop). |
none |
Keeps original size of content, ignoring container size. |
scale-down |
Scales content down to the smaller of none or contain . |
img {
width: 300px;
height: 200px;
object-fit: cover;
}
This ensures the image covers the container area without distortion, cropping if needed.
fill
: May stretch image, distorting it.
contain
: Shows the whole image with letterboxing (empty space).
cover
: Fills container, cropping overflow.
none
: Shows image at original size, ignoring container.
scale-down
: Like none
or contain
, whichever is smaller.
Q1. Use object-fit: cover
for a 200x200px image container.
Q2. Use object-fit: contain
to show full image inside fixed size div.
Q3. Prevent image distortion using object-fit
.
Q4. Use object-fit: fill
to stretch image to container size.
Q5. Apply object-fit: none
to display image at original size.
Q6. Use scale-down
to fit image in container but keep original size if smaller.
Q7. Combine object-fit
with fixed height and width on images.
Q8. Create circular images with object-fit: cover
.
Q9. Use object-fit
for responsive video thumbnails.
Q10. Use object-fit
in a flexbox container with fixed image size.
Q1: What does object-fit: cover do?
Q2: Which value maintains the original size of an image?
Q3: What is the difference between contain and cover?
Q4: Which value can cause image distortion?
Q5: What does object-fit: scale-down do?
Q6: Can object-fit be used on background images?
Q7: Which elements can use object-fit?
Q8: How to prevent cropping with object-fit?
Q9: Which value scales image to container ignoring aspect ratio?
Q10: What happens if object-fit is not set?