Image centering depends on context: inline, block container, flex/grid, or absolutely positioned overlays.
Reliable centering patterns
- Block image +
margin-inline: auto. - Parent flex/grid alignment utilities.
- Object-position for media crop emphasis.
Important interview questions and answers
- Q: Why does margin auto not center inline images?
A: Inline elements need block context or text alignment changes. - Q: Best centering strategy in card components?
A: Flex/grid centering on parent for predictable behavior. - Q: Centering vs cropping difference?
A: Centering positions box; cropping control needs object-fit/object-position.
Practice: Change one property in the playground and observe cascade + layout in DevTools.