Tailwind Place Items: An Ultimate Guide to Positioning HTML Elements

In this article we will focus on Tailwind place items property and classes with examples.

When it comes to designing responsive websites, positioning HTML elements can be a daunting task.

The traditional way of using float, position, and margin properties may not always work as expected.

Fortunately, Tailwind CSS has an intuitive and efficient way of positioning HTML elements using the Place Items classes.

Tailwind Place Items



Tailwind Place Items

Tailwind place items property is used to align both the grid or flex items and the container along the horizontal and vertical axes.

It is a shorthand property that combines the align-items and justify-items properties.

The align-items property is used to align the items along the vertical axis, while the justify-items property is used to align the items along the horizontal axis.

By setting the place-items property, you can align both axes at once.


Tailwind Place Items Classes

Tailwind Place Items offers several alignment options that you can use to position HTML elements.

Some of the most commonly used options include:

ClassesOverview
place-items-startUsing this class, the items will be positioned towards the top left corner of the container and the grid or flex tracks will also start from that point.
place-items-endIn this case, the items will be positioned towards the bottom right corner of the container.
place-items-centerThis class ensures that the items are positioned at the center of the container and the tracks will also start from that point.
place-items-baselineIn this case, the items will be positioned in a way that the text baseline of each item is aligned with the text baseline of the other items, and the tracks will also start from that point.
place-items-stretchItems and their tracks are expanded to take up all available space in the container, regardless of their original size.

Tailwind Place items start

This class aligns the grid or flex items and tracks to the start of the container along both the horizontal and vertical axes.

This results in the items and tracks being positioned towards the top left corner of the container.

Any extra space in either axis will not be utilized by the items and tracks, as they will not be stretched or spaced out to fill that space.

Syntax

<element class="place-items-start">...</element>

The following example revolves around the place-items-start class in Tailwind:

Example: 

<!DOCTYPE html> <html><head> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="m-3 text-center"> <h1 class="text-gray-700 text-2xl font-semibold"> MrExamples </h1> <p class="my-2 font-semibold">Place Items class in Tailwind</p> <p class="text-gray-500 font-medium my-2">Using place-items-start class</p> <div class=" h-48 w-full grid grid-cols-3 gap-2 place-items-start bg-gray-200 border-solid border-2 border-gray-900 font-medium"> <div class="bg-red-500 w-4/5 h-14 rounded-sm">1st</div> <div class="bg-blue-400 w-4/5 h-14 rounded-sm">2nd</div> <div class="bg-pink-400 w-4/5 h-14 rounded-sm">3rd</div> <div class="bg-green-400 w-4/5 h-14 rounded-sm">4th</div> <div class="bg-amber-500 w-4/5 h-14 rounded-sm">5th</div> <div class="bg-orange-400 w-4/5 h-14 rounded-sm">6th</div> </div> </body> </html>

Tailwind Place Items End

This is the class used for aligning grid or flex items to the end of the container along both the horizontal and vertical axes is called place-items-end.

This will position the items towards the bottom right corner of the container, without any extra spacing or alignment being applied.

Syntax

<element class="place-items-end">...</element>

Below example highlights the usage of place-items-end class in Tailwind:

Example: 

<!DOCTYPE html> <html><head> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="m-3 text-center"> <h1 class="text-gray-700 text-2xl font-semibold"> MrExamples </h1> <p class="my-2 font-semibold">Place Items class in Tailwind</p> <p class="text-gray-500 font-medium my-2">Using place-items-end class</p> <div class=" h-48 w-full grid grid-cols-3 gap-2 place-items-end bg-gray-200 border-solid border-2 border-gray-900 font-medium"> <div class="bg-red-500 w-4/5 h-14 rounded-sm">1st</div> <div class="bg-blue-400 w-4/5 h-14 rounded-sm">2nd</div> <div class="bg-pink-400 w-4/5 h-14 rounded-sm">3rd</div> <div class="bg-green-400 w-4/5 h-14 rounded-sm">4th</div> <div class="bg-amber-500 w-4/5 h-14 rounded-sm">5th</div> <div class="bg-orange-400 w-4/5 h-14 rounded-sm">6th</div> </div> </body> </html>

Tailwind Place Items Center

This class aligns the flex or grid items and the container path to the center along both the horizontal and vertical axes.

This means that the items will be positioned at the center of the container and the tracks will also start from that point.

If the container has extra space in either axis, the items will not be stretched or spaced out to fill that space.

Syntax

<element class="place-items-center">...</element>

The following example demonstrates the working of place-items-center class in Tailwind:

Example: 

<!DOCTYPE html> <html><head> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="m-3 text-center"> <h1 class="text-gray-700 text-2xl font-semibold"> MrExamples </h1> <p class="my-2 font-semibold">Place Items class in Tailwind</p> <p class="text-gray-500 font-medium my-2">Using place-items-center class</p> <div class=" h-48 w-full grid grid-cols-3 gap-2 place-items-center bg-gray-200 border-solid border-2 border-gray-900 font-medium"> <div class="bg-red-500 w-4/5 h-14 rounded-sm">1st</div> <div class="bg-blue-400 w-4/5 h-14 rounded-sm">2nd</div> <div class="bg-pink-400 w-4/5 h-14 rounded-sm">3rd</div> <div class="bg-green-400 w-4/5 h-14 rounded-sm">4th</div> <div class="bg-amber-500 w-4/5 h-14 rounded-sm">5th</div> <div class="bg-orange-400 w-4/5 h-14 rounded-sm">6th</div> </div> </body> </html>

Tailwind Place Items Baseline

The function of this class is to align both the grid items and the grid tracks to the baseline of the grid container along both the horizontal and vertical axes.

This means that the items will be positioned in a way that the text baseline of each item is aligned with the text baseline of the other items, and the tracks will also start from that point.

If the container has extra space in either axis, the items will not be stretched or spaced out to fill that space.

Syntax

<element class="place-items-baseline">...</element>

Below example implements the place-items-baseline class in Tailwind:

Example: 

<!DOCTYPE html> <html><head> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="m-3 text-center"> <h1 class="text-gray-700 text-2xl font-semibold"> MrExamples </h1> <p class="my-2 font-semibold">Place Items class in Tailwind</p> <p class="text-gray-500 font-medium my-2">Using place-items-baseline class</p> <div class=" h-48 w-full grid grid-cols-3 gap-2 place-items-baseline bg-gray-200 border-solid border-2 border-gray-900 font-medium"> <div class="bg-red-500 w-4/5 h-14 rounded-sm">1st</div> <div class="bg-blue-400 w-4/5 h-14 rounded-sm">2nd</div> <div class="bg-pink-400 w-4/5 h-14 rounded-sm">3rd</div> <div class="bg-green-400 w-4/5 h-14 rounded-sm">4th</div> <div class="bg-amber-500 w-4/5 h-14 rounded-sm">5th</div> <div class="bg-orange-400 w-4/5 h-14 rounded-sm">6th</div> </div> </body> </html>

Tailwind Place Items Stretch

Both grid or flex items and their tracks are stretched with this class to fill the entire grid container along both horizontal and vertical axes.

Regardless of their original size, the items and tracks will be expanded to cover all the available space in the container.

Items with a set height or width will be stretched to fit the space. If not, they will be given equal amounts of space to fill.

Syntax

<element class="place-items-stretch">...</element>

Using this example, we can better understand the place-items-stretch class in Tailwind:

Example: 

<!DOCTYPE html> <html><head> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="m-3 text-center"> <h1 class="text-gray-700 text-2xl font-semibold"> MrExamples </h1> <p class="my-2 font-semibold">Place Items class in Tailwind</p> <p class="text-gray-500 font-medium my-2">Using place-items-stretch class</p> <div class=" h-48 w-full grid grid-cols-3 gap-2 place-items-stretch bg-gray-200 border-solid border-2 border-gray-900 font-medium"> <div class="bg-red-500 w-4/5 rounded-sm">1st</div> <div class="bg-blue-400 w-4/5 rounded-sm">2nd</div> <div class="bg-pink-400 w-4/5 rounded-sm">3rd</div> <div class="bg-green-400 w-4/5 rounded-sm">4th</div> <div class="bg-amber-500 w-4/5 rounded-sm">5th</div> <div class="bg-orange-400 w-4/5 rounded-sm">6th</div> </div> </body> </html>

Conclusion

Tailwind Place Items simplifies the process of positioning HTML elements in responsive designs.

It offers an intuitive and efficient way of aligning elements within a container using flexbox properties.

By using the Place Items , you can achieve complex layouts and responsive designs with minimal code.

So next time you’re struggling to position HTML elements, give Tailwind Place Items a try and see how easy it can be.

We value your feedback.
+1
1
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!
icon

Leave a Reply

Your email address will not be published. Required fields are marked *