VOOZH about

URL: https://www.geeksforgeeks.org/css/tailwind-css-object-fit/

⇱ Tailwind CSS Object Fit - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Tailwind CSS Object Fit

Last Updated : 23 Jul, 2025

This class accepts more than one value in Tailwind CSS. All the properties are covered in class form. It is the alternative to the CSS object-fit property. This class is used to specify how an image or video should be resized to fit its content box for controlling a replaced element's content resizing.

Object fit Classes

  • object-contain 
  • object-cover 
  • object-fill 
  • object-none 
  • object-scale-down

object-contain Class

This class is used to replace the image and preserves the aspect ratio of the original image while fitting within the content box. Resize an element's content to stay contained within its container.

Syntax:

<element class="object-contain">...</element>

Example 1: This example demonstrates the use of the .object-contain class.

Output:

πŸ‘ Image

object-cover Class

This class preserves the aspect ratio of the original image as the replaced image while fitting in the content box. Sometimes it is clipped to fit when the aspect ratio of the original image doesn’t match with the aspect ratio of the content box. Resize an element's content to cover its container using this class.

Syntax:

<element class="object-cover">...</element>

Example 2: This example demonstrates the use of the .object-cover class.

Output:

πŸ‘ Image

object-fill Class

This class replaced image is stretched to fit the content box. The replaced image will completely fill the box needless of its aspect ratio. Stretch an element's content to fit its container using the class.

Syntax:

<element class="object-fill">...</element>

Example 3: This example demonstrates the use of the .object-fill class.

Output:

πŸ‘ Image

object-none Class

In this class, the replaced image will ignore the aspect ratio of the original image. Hence, it is not resized. The class displays an element's content at its original size ignoring the container size.

Syntax:

<element class="object-none">...</element>

Example 4: This example demonstrates the use of the .object-none class.

Output:

πŸ‘ Image

object-scale-down

This class replaced image is resized as if none or contain were specified and results in the smallest object size. The class displays an element's content at its original size but scale it down to fit its container.

Syntax:

<element class="object-scale-down">...</element>

Example 5: This example demonstrates the use of the .object-scale-down class.

Output:

πŸ‘ Image
Comment