Discover how a few simple classes can transform your layout without rewriting your HTML!
Why Order and self-alignment in Tailwind? - Purpose & Use Cases
Imagine you have a row of photos on a webpage. You want to change the order of some photos and make one photo stand out by moving it up or down inside the row.
If you try to move photos by cutting and pasting HTML code or adding extra empty spaces, it gets messy and breaks the layout. Also, moving one photo up or down inside the row means rewriting a lot of code or adding complicated styles.
Using Tailwind's order utilities, you can easily change the order of items without changing the HTML. With self- alignment classes, you can move a single item up or down inside a flex container, making it stand out visually without extra markup.
<div class="flex"> <div>Photo 1</div> <div>Photo 2</div> <div>Photo 3</div> </div> <!-- To move Photo 3 first, you must reorder HTML -->
<div class="flex"> <div class="order-2">Photo 1</div> <div class="order-3">Photo 2</div> <div class="order-1 self-start">Photo 3</div> </div> <!-- Change order and vertical alignment with classes only -->
You can rearrange and highlight items visually with simple class changes, making your layout flexible and easy to update.
On a product page, you want to show a featured product first and make its image align higher than others to catch attention, all without changing the HTML structure.
Manually changing order by editing HTML is slow and error-prone.
Tailwind's order classes let you reorder items easily.
self- alignment classes let you move single items up or down inside a flex container.