Tailwind CSS Justify-items

The justify-items utility class in Tailwind CSS allows you to control the horizontal alignment of flex items within a flex container. With Tailwind's justify-items class, you can easily adjust the positioning of flex items along the main axis.

Applying Justify Items

To apply the alignment to a flex container, you can use the justify-items-{alignment} utility class, where {alignment} represents the desired alignment. Here are the available alignment options:

  • justify-items-start: Aligns flex items to the start of the main axis.
  • justify-items-end: Aligns flex items to the end of the main axis.
  • justify-items-center: Aligns flex items to the center of the main axis.
  • justify-items-stretch: Stretches flex items to fill the main axis.
  • justify-items-auto: Resets the alignment to the value set by the flex container.
html
<div class="flex justify-items-center">
<div class="bg-purple-500 text-center ">item 1</div>
<div class="bg-purple-500 text-center">item 2</div>
<div class="bg-purple-500 text-center">item 3</div>
</div>

Preview

item 1
item 2
item 3

Responsive Justify Items

Tailwind CSS allows you to apply justify items classes responsively at different breakpoints. To use responsive justify items classes, you can append the breakpoint prefix to the utility class. For example, md:justify-items-center applies the center alignment starting from the medium breakpoint and above.

html
<div class="flex justify-items-start md:justify-items-center">
<!-- Flex items here -->
</div>

In the above example, the flex items are aligned to the start of the main axis by default (justify-items-start), but starting from the medium breakpoint and above, the alignment is changed to center (justify-items-center).

Tailwind Justify-items Class Table

ClassProperties
justify-items-autojustify-items: auto;
justify-items-startjustify-items: start;
justify-items-endjustify-items: end;
justify-items-centerjustify-items: center;
justify-items-stretchjustify-items: stretch;

Windframe Tailwind blocks

footer

Build modern projects using Bootstrap 5 and Contrast

Trying to create components and pages for a web app or website from scratch while maintaining a modern User interface can be very tedious. This is why we created Contrast, to help drastically reduce the amount of time we spend doing that. so we can focus on building some other aspects of the project.

Contrast Bootstrap PRO consists of a Premium UI Kit Library featuring over 10000+ component variants. Which even comes bundled together with its own admin template comprising of 5 admin dashboards and 23+ additional admin and multipurpose pages for building almost any type of website or web app.
See a demo and learn more about Contrast Bootstrap Pro by clicking here.

ad-banner