Skip to content

object-position

Utilities for controlling how a replaced element's content should be positioned within its container.

Quick reference

ClassStyles
object-top-leftobject-position: top left;
object-topobject-position: top;
object-top-rightobject-position: top right;
object-leftobject-position: left;
object-centerobject-position: center;
object-rightobject-position: right;
object-bottom-leftobject-position: bottom left;
object-bottomobject-position: bottom;
object-bottom-rightobject-position: bottom right;
object-(<custom-property>)object-position: var(<custom-property>);
object-[<value>]object-position: <value>;

Source: https://tailwindcss.com/guide/object-position

Examples

Basic example

html
<img class="size-24 object-top-left ..." src="/img/mountains.jpg" />
<img class="size-24 object-top ..." src="/img/mountains.jpg" />
<img class="size-24 object-top-right ..." src="/img/mountains.jpg" />
<img class="size-24 object-left ..." src="/img/mountains.jpg" />
<img class="size-24 object-center ..." src="/img/mountains.jpg" />
<img class="size-24 object-right ..." src="/img/mountains.jpg" />
<img class="size-24 object-bottom-left ..." src="/img/mountains.jpg" />
<img class="size-24 object-bottom ..." src="/img/mountains.jpg" />
<img class="size-24 object-bottom-right ..." src="/img/mountains.jpg" />

Using a custom value

Use the object-[&lt;value&gt;] syntax to set the object position based on a completely custom value:

html
<img class="object-[25%_75%] ..." src="/img/mountains.jpg" />

For CSS variables, you can also use the object-(&lt;custom-property&gt;) syntax:

html
<img class="object-(--my-position) ..." src="/img/mountains.jpg" />

This is just a shorthand for object-[var(&lt;custom-property&gt;)] that adds the var() function for you automatically.

Responsive design

Prefix an object-position utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

html
<img class="object-center md:object-top ..." src="/img/mountains.jpg" />

Learn more about using variants in the variants documentation.

Released under the MIT License.