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
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.