🎨 HTML / CSS
Intermediate
What is the CSS object-fit property?
Answer
object-fit controls how a replaced element (primarily <img> and <video>) is scaled and positioned within its container when the element's intrinsic aspect ratio differs from the container's. fill (default): stretches to fill, potentially distorting the image. contain: scales to fit entirely within the box, preserving aspect ratio — may leave empty space ("letterbox"). cover: scales to fill the box entirely, preserving aspect ratio — may crop edges. This is the most commonly used value for hero images and avatars. none: no scaling. scale-down: smaller of none or contain. Pair with object-position (like background-position) to control where the image is cropped.
More HTML / CSS Questions
View all →- Intermediate How does the CSS cascade work?
- Intermediate What is BEM (Block Element Modifier) methodology in CSS?
- Intermediate What are CSS custom properties (CSS variables)?
- Intermediate What is the difference between em, rem, px, vh, and vw units in CSS?
- Intermediate How does Flexbox differ from CSS Grid? When would you use each?