Order and self-alignment help you control where items appear and how they line up inside a container. This makes your page look neat and organized.
Order and self-alignment in Tailwind
/* Order syntax */ order-{number} /* Self-alignment syntax */ self-auto self-start self-center self-end self-stretch
Order uses numbers to move items forward or backward visually.
Self-alignment changes how one item aligns inside its container, ignoring the container's default alignment.
<div class="flex"> <div class="order-2">Second</div> <div class="order-1">First</div> <div class="order-3">Third</div> </div>
<div class="flex items-start h-24"> <div class="self-center">Center aligned</div> <div class="self-end">End aligned</div> <div>Default aligned</div> </div>
This example shows three colored boxes inside a row. They appear in the order: green, red, blue because of the order classes. Each box aligns vertically differently: top, center, and bottom.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Order and Self-Alignment Example</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="p-6"> <h1 class="text-xl font-bold mb-4">Order and Self-Alignment Demo</h1> <div class="flex h-24 border border-gray-400"> <div class="bg-blue-400 text-white p-4 order-3 self-start">Box 1 (order 3, start)</div> <div class="bg-green-400 text-white p-4 order-1 self-center">Box 2 (order 1, center)</div> <div class="bg-red-400 text-white p-4 order-2 self-end">Box 3 (order 2, end)</div> </div> </body> </html>
Order only changes visual position, not the actual HTML order. This helps screen readers read content in the correct order.
Self-alignment works only inside flex or grid containers.
Use small order numbers for items you want to appear first.
Order changes the visual position of items without changing the code order.
Self-alignment lets one item align differently inside its container.
Both help make layouts flexible and easy to adjust.
Practice
order utility in Tailwind CSS do?Solution
Step 1: Understand the purpose of
Theorderorderutility changes the visual order of flex items without changing their order in the HTML code.Step 2: Compare with other options
Options A, C, and D describe unrelated CSS properties like font size, margin, and background color, which are not related toorder.Final Answer:
Changes the visual position of an item without changing the HTML order -> Option AQuick Check:
Order changes visual position only [OK]
- Confusing order with margin or padding
- Thinking order changes HTML code
- Mixing order with color or font utilities
Solution
Step 1: Identify the class for first order
In Tailwind,order-firstsets the item to appear before all others visually.Step 2: Understand other options
order-lastplaces the item last,order-1andorder-0set numeric order butorder-firstis the special class for first position.Final Answer:
order-first -> Option CQuick Check:
Use order-first to appear first [OK]
- Using order-1 instead of order-first for first position
- Confusing order-last with order-first
- Assuming order-0 is always first
<div class="flex"> <div class="order-2">A</div> <div class="order-1">B</div> <div class="order-3">C</div> </div>
What is the visual order of the items displayed in the browser?
Solution
Step 1: Understand the order values
Items have order values: A=2, B=1, C=3. Lower order values appear first visually.Step 2: Arrange items by order
Order 1 (B) appears first, then order 2 (A), then order 3 (C). So visual order is B A C.Final Answer:
B A C -> Option BQuick Check:
Lower order value appears first [OK]
- Assuming HTML order is visual order
- Mixing up order numbers
- Ignoring that order affects only visual placement
Solution
Step 1: Understand self-alignment classes
self-endaligns the single item to the end of the cross axis (vertical in a row flex container).Step 2: Differentiate from container alignment
items-endaligns all items, butself-endtargets only one item.Final Answer:
self-end -> Option DQuick Check:
Use self-end for single item vertical end alignment [OK]
- Using items-end to align only one item
- Confusing self-start with self-end
- Not understanding self- vs items- prefixes
Solution
Step 1: Set visual order to last
Useorder-lastto make the second item appear last visually.Step 2: Align only the second item vertically centered
Useself-centerto align that item vertically center without affecting others.Step 3: Confirm other options
items-startanditems-centeraffect all items, not just one.order-3is numeric butorder-lastis clearer for last position.Final Answer:
order-last self-center -> Option AQuick Check:
order-last + self-center for last and centered item [OK]
- Using items-start or items-center instead of self- classes
- Using numeric order instead of order-last
- Aligning all items instead of just one
Ready to prove it?
Pass the test and this pattern moves unknown
