0
0
Tailwindmarkup~5 mins

Min and max sizing constraints in Tailwind

Choose your learning style9 modes available
Introduction

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.

You want a box to never get smaller than a button inside it.
You want an image to grow but not become too big on large screens.
You want text containers to stay readable by not shrinking too much.
You want a sidebar to have a minimum width but still be flexible.
You want a card to expand but not overflow the page width.
Syntax
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.

Examples
This box will never be narrower than 6rem (24 x 0.25rem).
Tailwind
<div class="min-w-24">Content</div>
This box will not grow wider than the small screen size breakpoint.
Tailwind
<div class="max-w-screen-sm">Content</div>
This box will be at least 10rem tall but no taller than 24rem.
Tailwind
<div class="min-h-40 max-h-96">Content</div>
Sample Program

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.

Tailwind
<!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>
OutputSuccess
Important Notes

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.

Summary

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.