Tailwind CSS Images
Build image layouts with Tailwind CSS utilities for sizing, object fit, backgrounds, overlays, and galleries.
Images are block-level
In Tailwind, images and other replaced elements (like svg, video, canvas, and others) are display: block by default.
This helps to avoid unexpected alignment issues that you often run into using the browser default of display: inline.
If you ever need to make one of these elements inline instead of block, simply use the inline utility:
Setting the background position
Use bg-{side} utilities to control the position of an element’s background image.
bg-top-left
bg-top
bg-top-right
bg-left
bg-center
bg-right
bg-bottom-left
bg-bottom
bg-bottom-right
Contain
Use bg-contain to scale the background image to the outer edges without cropping or stretching.
Resizing to cover a container
Resize an element’s content to cover its container using object-cover.
Containing an element
Resize an element’s content to stay contained within its container using object-contain.
Scaling down if too large
Display an element’s content at its original size but scale it down to fit its container if necessary using object-scale-down.
Using an element’s original size
Display an element’s content at its original size ignoring the container size using object-none.
Overlay image
Combine a background image with layered content to create an image overlay card.
Masonry example with overlay
Combine a masonry-style image grid with text overlays and hover states.