Min and max sizing constraints help control how small or large an element can get. This keeps your design neat and readable on different screen sizes.
Min and max sizing constraints in Tailwind
Start learning this pattern below
Jump into concepts and practice - no test required
min-w-{size} max-w-{size} min-h-{size} max-h-{size}Replace {size} with Tailwind size values like full, screen, or spacing units like 24 (which means 6rem).
These classes set CSS properties min-width, max-width, min-height, and max-height.
<div class="min-w-24">Content</div><div class="max-w-screen-sm">Content</div><div class="min-h-40 max-h-96">Content</div>This page shows three colored boxes demonstrating min and max width and height constraints using Tailwind classes. The first box never gets narrower than 10rem. The second box never grows wider than 20rem. The third box has a height between 6rem and 12rem and scrolls if content is too tall.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Min and Max Sizing Constraints</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="flex flex-col items-center gap-6 p-6"> <div class="bg-blue-200 min-w-40 p-4">This box is at least 10rem wide.</div> <div class="bg-green-200 max-w-xs p-4">This box is at most 20rem wide.</div> <div class="bg-red-200 min-h-24 max-h-48 p-4 overflow-auto"> This box is between 6rem and 12rem tall.<br /> Add more text to see scrolling if it grows taller. </div> </body> </html>
Use overflow-auto or similar if content might overflow the max height.
Min and max sizing help keep your layout flexible but controlled on different devices.
Min and max sizing constraints keep elements from getting too small or too big.
Tailwind uses classes like min-w- and max-h- to set these limits.
They help make your design look good on all screen sizes.
Practice
min-w-20 do to an element?Solution
Step 1: Understand the class prefix
The prefixmin-w-means minimum width in Tailwind CSS.Step 2: Interpret the value
The number 20 corresponds to 5rem in Tailwind's spacing scale.Final Answer:
Sets the minimum width of the element to 5rem -> Option BQuick Check:
min-w-20 means min-width: 5rem [OK]
- Confusing min-w with max-w
- Mixing width and height classes
- Assuming number is pixels, not rem
Solution
Step 1: Identify max height prefix
The prefixmax-h-sets maximum height in Tailwind.Step 2: Match the value to rem
Value 40 corresponds to 10rem in Tailwind spacing scale.Final Answer:
max-h-40 -> Option AQuick Check:
max-h-40 means max-height: 10rem [OK]
- Using max-w instead of max-h
- Using min-h or min-w instead of max-h
- Confusing 10 with 40 in spacing scale
<div class="min-w-24 max-w-48 bg-blue-200">Content</div>
What is the minimum and maximum width of the div in rem?
Solution
Step 1: Convert min-w-24 to rem
In Tailwind, 24 equals 6rem (24 * 0.25rem).Step 2: Convert max-w-48 to rem
48 equals 12rem (48 * 0.25rem).Final Answer:
Minimum 6rem, Maximum 12rem -> Option CQuick Check:
min-w-24 = 6rem, max-w-48 = 12rem [OK]
- Assuming numbers are pixels
- Mixing min and max values
- Forgetting Tailwind spacing scale factor
Solution
Step 1: Understand Tailwind spacing scale
16 equals 4rem and 32 equals 8rem (16*0.25=4rem, 32*0.25=8rem).Step 2: Check each option's min and max values
min-h-16 max-h-8 sets min-h-16 (4rem) but max-h-8 (2rem), which is smaller than min height, causing conflict.Final Answer:
min-h-16 max-h-8 -> Option AQuick Check:
Max height smaller than min height is invalid [OK]
- Setting max smaller than min
- Confusing spacing numbers with rem
- Using wrong prefixes (w vs h)
Solution
Step 1: Convert rem to Tailwind spacing numbers
12rem ÷ 0.25rem = 48, 24rem ÷ 0.25rem = 96, 8rem ÷ 0.25rem = 32, 16rem ÷ 0.25rem = 64.Step 2: Match classes to these values
min-w-48 and max-w-96 set width limits; min-h-32 and max-h-64 set height limits correctly.Final Answer:
min-w-48 max-w-96 min-h-32 max-h-64 -> Option DQuick Check:
Spacing numbers match rem sizes for min/max width and height [OK]
- Using rem values directly as class numbers
- Mixing width and height classes
- Choosing wrong spacing scale numbers
