Skip to main content

Tailwind CSS Object Position Cheatsheet

Control how images and videos are positioned within their containers.
Click any class to copy to clipboard.

Object Position

Use object-{position} to control how an image or video should be positioned within its container. Works best with object-cover or object-none.

Tip: Object position only has a visible effect when the image is scaled using object-cover, object-none, or object-scale-down.

Object Fit

Use object-{fit} to control how an image or video is resized to fit its container.

object-cover

Scales the image to cover the entire container while maintaining aspect ratio. Parts of the image may be cropped.

object-contain

Scales the image to fit within the container while maintaining aspect ratio. May leave empty space.

object-fill

Stretches the image to fill the container exactly. Aspect ratio is not preserved.

object-none

Displays the image at its original size. Parts may be hidden or space may be empty.

Common Examples

Avatar with Face Focus

Avatar example
Avatar example
<img class="object-cover object-top" />
<img class="object-cover object-center" />

Hero Image with Bottom Focus

Hero example
<div class="h-64 w-full overflow-hidden">
  <img
    src="hero.jpg"
    class="w-full h-full object-cover object-bottom"
  />
</div>

Thumbnail Gallery

Thumbnail
Thumbnail
Thumbnail
<div class="grid grid-cols-3 gap-2">
  <img class="aspect-square object-cover object-center" />
  <img class="aspect-square object-cover object-center" />
  <img class="aspect-square object-cover object-center" />
</div>

Card with Image

<div class="card w-80 bg-base-100 shadow-xl">
  <figure class="h-48 overflow-hidden">
    <img
      src="product.jpg"
      alt="Product"
      class="w-full h-full object-cover object-center"
    />
  </figure>
  <div class="card-body">
    <h2 class="card-title">Product Name</h2>
    <p>Description text here...</p>
  </div>
</div>

Responsive Object Position

<!-- Different positions at different breakpoints -->
<img class="object-cover object-left md:object-center lg:object-right" />

<!-- Change object-fit at breakpoints -->
<img class="object-contain md:object-cover" />

Quick Reference

ClassCSS Property
object-bottomobject-position: bottom
object-centerobject-position: center
object-leftobject-position: left
object-left-bottomobject-position: left bottom
object-left-topobject-position: left top
object-rightobject-position: right
object-right-bottomobject-position: right bottom
object-right-topobject-position: right top
object-topobject-position: top

Object Fit Classes

ClassCSS Property
object-containobject-fit: contain
object-coverobject-fit: cover
object-fillobject-fit: fill
object-noneobject-fit: none
object-scale-downobject-fit: scale-down

Arbitrary Values

Use bracket notation for custom object positions not included in the default scale.

<!-- Custom position with percentages -->
<img class="object-[25%_75%]" />

<!-- Custom position with length values -->
<img class="object-[10px_20px]" />

<!-- Mix of keyword and percentage -->
<img class="object-[center_25%]" />