Menu

Tailwind CSS Min Width

The min-width property in CSS defines the minimum width an element can have. This ensures the element never becomes smaller than the specified min-width value, regardless of other constraints like width or max-width.

This guide provides a clear breakdown of configuring and applying min-width in Tailwind CSS using built-in utilities, conditional modifiers, and custom values.

ClassPropertiesExample
min-w-0min-width: 0px;<div className="min-w-0"></div>
min-w-1min-width: 0.25rem; <div className="min-w-1"></div>
min-w-2min-width: 0.5rem; <div className="min-w-2"></div>
min-w-3min-width: 0.75rem; <div className="min-w-3"></div>
min-w-4min-width: 1rem; <div className="min-w-4"></div>
min-w-5min-width: 1.25rem; <div className="min-w-5"></div>
min-w-6min-width: 1.5rem; <div className="min-w-6"></div>
min-w-7min-width: 1.75rem; <div className="min-w-7"></div>
min-w-8min-width: 2rem; <div className="min-w-8"></div>
min-w-9min-width: 2.25rem; <div className="min-w-9"></div>
min-w-10min-width: 2.5rem; <div className="min-w-10"></div>
min-w-11min-width: 2.75rem; <div className="min-w-11"></div>
min-w-12min-width: 3rem; <div className="min-w-12"></div>
min-w-14min-width: 3.5rem; <div className="min-w-14"></div>
min-w-16min-width: 4rem; <div className="min-w-16"></div>
min-w-20min-width: 5rem; <div className="min-w-20"></div>
min-w-24min-width: 6rem; <div className="min-w-24"></div>
min-w-28min-width: 7rem; <div className="min-w-28"></div>
min-w-32min-width: 8rem; <div className="min-w-32"></div>
min-w-36min-width: 9rem; <div className="min-w-36"></div>
min-w-40min-width: 10rem; <div className="min-w-40"></div>
min-w-44min-width: 11rem; <div className="min-w-44"></div>
min-w-48min-width: 12rem; <div className="min-w-48"></div>
min-w-52min-width: 13rem; <div className="min-w-52"></div>
min-w-56min-width: 14rem; <div className="min-w-56"></div>
min-w-60min-width: 15rem; <div className="min-w-60"></div>
min-w-64min-width: 16rem; <div className="min-w-64"></div>
min-w-72min-width: 18rem; <div className="min-w-72"></div>
min-w-80min-width: 20rem; <div className="min-w-80"></div>
min-w-96min-width: 24rem; <div className="min-w-96"></div>
min-w-pxmin-width: 1px;<div className="min-w-px"></div>
min-w-0.5min-width: 0.125rem; <div className="min-w-0.5"></div>
min-w-1.5min-width: 0.375rem; <div className="min-w-1.5"></div>
min-w-2.5min-width: 0.625rem; <div className="min-w-2.5"></div>
min-w-3.5min-width: 0.875rem; <div className="min-w-3.5"></div>
min-w-fullmin-width: 100%;<div className="min-w-full"></div>
min-w-minmin-width: min-content;<div className="min-w-min"></div>
min-w-maxmin-width: max-content;<div className="min-w-max"></div>
min-w-fitmin-width: fit-content;<div className="min-w-fit"></div>

Overview of Min Width

Adding the Min Width

You can apply min-width using Tailwind's predefined min-w-* classes, e.g., min-w-2, min-w-3, etc.

This is a live editor. Play around with it!
import React from 'react';

const MinWidthDemo = () => {
  return (
    <div className="h-screen flex items-center justify-center bg-gray-100">
      <div
        className="min-w-80 p-4 bg-blue-500 text-white rounded-lg"
        // min-width: 20rem;
      >
        <img
          src="https://images.unsplash.com/photo-1705909237050-7a7625b47fac"
          alt="Example"
          className="rounded-lg w-full"
        />
        <p className="mt-2">This box will always be at least 20rem wide.</p>
      </div>
    </div>
  );
};

export default MinWidthDemo;

States and Responsiveness

Modern web development often involves adapting UI elements based on interactivity and screen sizes. Tailwind helps dynamically apply min-width based on states or breakpoints.

Hover and Focus States

State-driven styles like hover and focus let you modify the minimum width as users interact with elements. This approach is particularly useful for creating interactive designs that emphasize usability.

This is a live editor. Play around with it!
import React from 'react';

const HoverFocusMinWidth = () => {
  return (
    <div className="h-screen flex items-center justify-center bg-gray-200">
      <button
        className="bg-blue-500 text-white p-3 rounded-md min-w-20 focus:min-w-36 transition-all"
      >
        Hover or Focus on me
      </button>
    </div>
  );
};

export default HoverFocusMinWidth;

Breakpoint Modifiers

In responsive designs, min-width values might need adjustments based on screen size or device type. Tailwind's breakpoint modifiers(sm, md, etc.) simplify this process.

This is a live editor. Play around with it!
import React from 'react';

const ResponsiveMinWidth = () => {
  return (
    <div className="h-screen flex items-center justify-center bg-gray-300">
      <button
        className="bg-green-400 text-black p-4 rounded-lg min-w-20 sm:min-w-32 md:min-w-40"
      >
      Responsive Button
      </button>
    </div>
  );
};

export default ResponsiveMinWidth;

Custom Min Width

Tailwind CSS empowers developers with flexibility to define unique min-width values using either extensions of the theme or arbitrary values.

Extending the Theme

In Tailwind's configuration, the theme object can be extended to add custom min-width utilities. The added values become available globally.

This is a live editor. Play around with it!
import tailwindConfig from "./tailwind.config.js";
tailwind.config = tailwindConfig;

import React from 'react';

const CustomThemeMinWidth = () => {
  return (
    <div className="h-screen flex flex-col items-center justify-center bg-gray-50 space-y-5">
      <div
        className="min-w-small bg-purple-500 text-white p-5 rounded-lg"
        // min-width: 18rem (288px)
      >
        Min Width: 18rem
      </div>
      <div
        className="min-w-large bg-red-500 text-white p-5 rounded-lg"
        // min-width: 24rem (384px)
      >
        Min Width: 24rem
      </div>
    </div>
  );
};

export default CustomThemeMinWidth;

Using Arbitrary Values

If predefined or theme values are insufficient, Tailwind allows developers to use arbitrary values directly in their classes. This method provides instant access to any custom value without editing the configuration.

This is a live editor. Play around with it!
import React from 'react';

const ArbitraryValueMinWidth = () => {
  return (
    <div className="h-screen flex flex-wrap gap-4 items-center justify-center bg-gray-100">
      <div
        className="min-w-[250px] bg-orange-500 text-white p-4 rounded-lg"
        // min-width: 250px
      >
        Min Width: 250px
      </div>
      <div
        className="min-w-[350px] bg-yellow-500 text-gray-900 p-4 rounded-lg"
        // min-width: 350px
      >
        Min Width: 350px
      </div>
    </div>
  );
};

export default ArbitraryValueMinWidth;

Real World Examples

Product Comparison Cards

A responsive product comparison layout with minimum width cards to ensure consistent spacing and readability.

This is a live editor. Play around with it!
export default function ProductComparison() {
  const products = [
    {
      name: "Standard Laptop",
      price: "$899",
      rating: 4.5,
      image: {
        src: "https://images.unsplash.com/photo-1496181133206-80ce9b88a853",
        alt: "Standard Laptop Model"
      },
      features: ["8GB RAM", "256GB SSD", "HD Display"]
    },
    {
      name: "Budget Laptop",
      price: "$599",
      rating: 4.2,
      image: {
        src: "https://images.unsplash.com/photo-1541807084-5c52b6b3adef",
        alt: "Budget Laptop"
      },
      features: ["4GB RAM", "128GB SSD", "HD Display"]
    }
  ];

  return (
    <div className="flex flex-wrap justify-center gap-4 p-6">
      {products.map((product) => (
        <div key={product.name} className="min-w-[280px] bg-white rounded-lg shadow-lg p-4">
          <img 
            src={product.image.src} 
            alt={product.image.alt}
            className="w-full h-48 object-cover rounded-t-lg"
          />
          <div className="p-4">
            <h3 className="text-xl font-bold">{product.name}</h3>
            <p className="text-2xl text-blue-600">{product.price}</p>
            <div className="mt-2">
              {product.features.map((feature) => (
                <span key={feature} className="block text-gray-600">✓ {feature}</span>
              ))}
            </div>
          </div>
        </div>
      ))}
    </div>
  );
}

Dashboard Statistics Grid

A responsive dashboard layout with minimum width tiles for statistics and metrics.

This is a live editor. Play around with it!
export default function DashboardStats() {
  const stats = [
    {
      title: "Total Revenue",
      value: "$124,563",
      icon: "https://images.unsplash.com/photo-1523287562758-66c7fc58967f",
      change: "+12.5%"
    },
    {
      title: "Active Users",
      value: "45,789",
      icon: "https://images.unsplash.com/photo-1517841905240-472988babdf9",
      change: "+8.2%"
    },
    {
      title: "Conversion Rate",
      value: "3.42%",
      icon: "https://images.unsplash.com/photo-1551288049-bebda4e38f71",
      change: "+2.4%"
    },
    {
      title: "Avg. Order Value",
      value: "$86.22",
      icon: "https://images.unsplash.com/photo-1526304640581-d334cdbbf45e",
      change: "+5.1%"
    },
    {
      title: "Orders",
      value: "2,847",
      icon: "https://images.unsplash.com/photo-1553729459-efe14ef6055d",
      change: "+15.3%"
    },
    {
      title: "Refunds",
      value: "$2,356",
      icon: "https://images.unsplash.com/photo-1559526324-4b87b5e36e44",
      change: "-3.2%"
    }
  ];

  return (
    <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 p-6">
      {stats.map((stat) => (
        <div key={stat.title} className="min-w-[200px] bg-white rounded-xl shadow p-4">
          <div className="flex items-center space-x-4">
            <img 
              src={stat.icon} 
              alt={stat.title}
              className="w-12 h-12 rounded-full"
            />
            <div>
              <h3 className="text-gray-500 text-sm">{stat.title}</h3>
              <p className="text-2xl font-bold">{stat.value}</p>
              <span className={`text-sm ${stat.change.startsWith('+') ? 'text-green-500' : 'text-red-500'}`}>
                {stat.change}
              </span>
            </div>
          </div>
        </div>
      ))}
    </div>
  );
}

A responsive team member gallery with minimum width cards to maintain layout consistency.

This is a live editor. Play around with it!
export default function TeamGallery() {
  const team = [
    {
      name: "Sarah Johnson",
      role: "CEO",
      image: {
        src: "https://images.unsplash.com/photo-1494790108377-be9c29b29330",
        alt: "Sarah Johnson"
      },
      social: {
        twitter: "#",
        linkedin: "#",
        github: "#"
      }
    },
    {
      name: "Michael Chen",
      role: "CTO",
      image: {
        src: "https://images.unsplash.com/photo-1472099645785-5658abf4ff4e",
        alt: "Michael Chen"
      },
      social: {
        twitter: "#",
        linkedin: "#",
        github: "#"
      }
    },
    {
      name: "Emma Williams",
      role: "Lead Designer",
      image: {
        src: "https://images.unsplash.com/photo-1438761681033-6461ffad8d80",
        alt: "Emma Williams"
      },
      social: {
        twitter: "#",
        linkedin: "#",
        github: "#"
      }
    },
    {
      name: "David Kim",
      role: "Senior Developer",
      image: {
        src: "https://images.unsplash.com/photo-1500648767791-00dcc994a43e",
        alt: "David Kim"
      },
      social: {
        twitter: "#",
        linkedin: "#",
        github: "#"
      }
    },
    {
      name: "Lisa Martinez",
      role: "Product Manager",
      image: {
        src: "https://images.unsplash.com/photo-1517365830460-955ce3ccd263",
        alt: "Lisa Martinez"
      },
      social: {
        twitter: "#",
        linkedin: "#",
        github: "#"
      }
    },
    {
      name: "James Wilson",
      role: "Marketing Lead",
      image: {
        src: "https://images.unsplash.com/photo-1519345182560-3f2917c472ef",
        alt: "James Wilson"
      },
      social: {
        twitter: "#",
        linkedin: "#",
        github: "#"
      }
    }
  ];

  return (
    <div className="flex flex-wrap justify-center gap-6 p-8 bg-gray-100">
      {team.map((member) => (
        <div key={member.name} className="min-w-[250px] max-w-xs bg-white rounded-2xl shadow-xl overflow-hidden">
          <img 
            src={member.image.src} 
            alt={member.image.alt}
            className="w-full h-64 object-cover"
          />
          <div className="p-6">
            <h3 className="text-xl font-bold">{member.name}</h3>
            <p className="text-gray-600">{member.role}</p>
            <div className="mt-4 flex justify-center space-x-4">
              {Object.keys(member.social).map((platform) => (
                <a
                  key={platform}
                  href={member.social[platform]}
                  className="text-gray-400 hover:text-gray-600"
                >
                  {platform}
                </a>
              ))}
            </div>
          </div>
        </div>
      ))}
    </div>
  );
}

Feature Comparison Table

A responsive feature comparison table with minimum width columns for better readability.

This is a live editor. Play around with it!
export default function FeatureComparison() {
  const features = [
    {
      name: "Basic Plan",
      price: "$9/mo",
      features: ["10GB Storage", "2 Users", "Email Support", "Basic Analytics", "API Access", "Weekly Backups"],
      recommended: false
    },
    {
      name: "Pro Plan",
      price: "$29/mo",
      features: ["50GB Storage", "10 Users", "Priority Support", "Advanced Analytics", "API Access", "Daily Backups"],
      recommended: true
    },
    {
      name: "Enterprise Plan",
      price: "$99/mo",
      features: ["Unlimited Storage", "Unlimited Users", "24/7 Support", "Custom Analytics", "API Access", "Real-time Backups"],
      recommended: false
    }
  ];

  return (
    <div className="overflow-x-auto p-6">
      <div className="flex flex-col space-x-6">
        {features.map((plan) => (
          <div 
            key={plan.name}
            className={`min-w-[300px] p-6 rounded-xl ${
              plan.recommended ? 'bg-blue-50 border-2 border-blue-500' : 'bg-white border border-gray-200'
            }`}
          >
            {plan.recommended && (
              <span className="bg-blue-500 text-white px-4 py-1 rounded-full text-sm">
                Recommended
              </span>
            )}
            <h3 className="text-2xl font-bold mt-4">{plan.name}</h3>
            <p className="text-4xl font-bold my-4">{plan.price}</p>
            <ul className="space-y-4">
              {plan.features.map((feature) => (
                <li key={feature} className="flex items-center">
                  <svg className="w-5 h-5 text-green-500 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M5 13l4 4L19 7" />
                  </svg>
                  {feature}
                </li>
              ))}
            </ul>
            <button className={`w-full mt-6 py-3 rounded-lg ${
              plan.recommended ? 'bg-blue-500 text-white' : 'bg-gray-800 text-white'
            }`}>
              Choose Plan
            </button>
          </div>
        ))}
      </div>
    </div>
  );
}

A responsive portfolio gallery with minimum width items to maintain visual consistency.

This is a live editor. Play around with it!
export default function PortfolioGallery() {
  const projects = [
    {
      title: "E-commerce Platform",
      category: "Web Development",
      image: {
        src: "https://images.unsplash.com/photo-1523474253046-8cd2748b5fd2",
        alt: "E-commerce Platform Preview"
      },
      description: "A full-featured online shopping platform"
    },
    {
      title: "Mobile Banking App",
      category: "Mobile Development",
      image: {
        src: "https://images.unsplash.com/photo-1563013544-824ae1b704d3",
        alt: "Banking App Preview"
      },
      description: "Secure and intuitive banking application"
    },
    {
      title: "Travel Blog",
      category: "Web Design",
      image: {
        src: "https://images.unsplash.com/photo-1469854523086-cc02fe5d8800",
        alt: "Travel Blog Preview"
      },
      description: "Personal travel experiences platform"
    },
    {
      title: "Fitness Tracker",
      category: "Mobile Development",
      image: {
        src: "https://images.unsplash.com/photo-1476480862126-209bfaa8edc8",
        alt: "Fitness App Preview"
      },
      description: "Health and workout tracking application"
    },
    {
      title: "Restaurant Website",
      category: "Web Design",
      image: {
        src: "https://images.unsplash.com/photo-1517248135467-4c7edcad34c4",
        alt: "Restaurant Website Preview"
      },
      description: "Modern restaurant presentation site"
    },
    {
      title: "Weather Dashboard",
      category: "Web Development",
      image: {
        src: "https://images.unsplash.com/photo-1504608524841-42fe6f032b4b",
        alt: "Weather App Preview"
      },
      description: "Real-time weather monitoring dashboard"
    }
  ];

  return (
    <div className="bg-gray-100 p-8">
      <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
        {projects.map((project) => (
          <div 
            key={project.title}
            className="min-w-[280px] group relative overflow-hidden rounded-xl bg-white shadow-lg"
          >
            <img 
              src={project.image.src}
              alt={project.image.alt}
              className="w-full h-64 object-cover transform group-hover:scale-110 transition-transform duration-300"
            />
            <div className="absolute inset-0 bg-gradient-to-t from-black/70 to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-300">
              <div className="absolute bottom-0 p-6 text-white">
                <span className="text-sm uppercase tracking-wider">{project.category}</span>
                <h3 className="text-2xl font-bold mt-2">{project.title}</h3>
                <p className="mt-2 text-gray-200">{project.description}</p>
                <button className="mt-4 px-6 py-2 bg-white text-black rounded-full hover:bg-gray-100 transition-colors">
                  View Project
                </button>
              </div>
            </div>
          </div>
        ))}
      </div>
    </div>
  );
}

Customization Examples

Responsive Product Card with Custom Min Width

This example demonstrates a product card that maintains a minimum width across different screen sizes using a custom min-width configuration.

This is a live editor. Play around with it!
import tailwindConfig from "./tailwind.config.js";
tailwind.config = tailwindConfig;

// App.js
export default function ProductCard() {
  return (
    <div className="flex flex-wrap gap-4 p-6 bg-gray-100">
      <div className="min-w-card bg-white rounded-xl shadow-lg overflow-hidden">
        <img
          src="https://images.unsplash.com/photo-1523275335684-37898b6baf30"
          alt="Product"
          className="w-full h-48 object-cover"
        />
        <div className="p-4">
          <h2 className="text-xl font-bold">Premium Watch</h2>
          <p className="text-gray-600 mt-2">Luxury timepiece with leather strap</p>
          <button className="mt-4 w-full bg-blue-600 text-white py-2 rounded-lg">
            Add to Cart
          </button>
        </div>
      </div>
    </div>
  )
}

Dashboard Sidebar with Dynamic Min Width

A collapsible sidebar that uses custom min-width values for expanded and collapsed states.

This is a live editor. Play around with it!
import tailwindConfig from "./tailwind.config.js";
tailwind.config = tailwindConfig;
import {useState} from "react"

// App.js
export default function DashboardSidebar() {
  const [isExpanded, setIsExpanded] = useState(true)

  return (
    <div className={`
      ${isExpanded ? 'min-w-sidebar-expanded' : 'min-w-sidebar-collapsed'}
      h-screen bg-gray-800 text-white transition-all duration-300
    `}>
      <div className="p-4">
        <button
          onClick={() => setIsExpanded(!isExpanded)}
          className="w-full flex items-center justify-center"
        >
          <img
            src="https://images.unsplash.com/photo-1518806118471-f28b20a1d79d"
            alt="Profile"
            className="w-10 h-10 rounded-full"
          />
        </button>
        
        {isExpanded && (
          <nav className="mt-8 space-y-4">
            <a href="#" className="block py-2 px-4 hover:bg-gray-700 rounded">Dashboard</a>
            <a href="#" className="block py-2 px-4 hover:bg-gray-700 rounded">Analytics</a>
            <a href="#" className="block py-2 px-4 hover:bg-gray-700 rounded">Settings</a>
          </nav>
        )}
      </div>
    </div>
  )
}

A modal component with custom min-width values that adapt to different screen sizes.

This is a live editor. Play around with it!
import tailwindConfig from "./tailwind.config.js";
tailwind.config = tailwindConfig;

// App.js
export default function ResponsiveModal() {
  return (
    <div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4">
      <div className="
        min-w-modal-xs
        sm:min-w-modal-sm
        md:min-w-modal-md
        lg:min-w-modal-lg
        bg-white rounded-2xl shadow-xl
      ">
        <div className="p-6">
          <div className="flex justify-between items-center">
            <h2 className="text-2xl font-bold">Subscribe to Newsletter</h2>
            <button className="text-gray-500 hover:text-gray-700">
              <svg className="w-6 h-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
              </svg>
            </button>
          </div>
          
          <div className="mt-6">
            <input
              type="email"
              placeholder="Enter your email"
              className="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500"
            />
            <button className="mt-4 w-full bg-blue-600 text-white py-3 rounded-lg hover:bg-blue-700">
              Subscribe Now
            </button>
          </div>
        </div>
      </div>
    </div>
  )
}

Best Practices

Maintain Design Consistency

Consistency is a critical aspect of user experience design. By applying Tailwind CSS min-width utilities uniformly across your project, you ensure that layouts feel professional and make the interface predictable for users.

For example, use consistent min-w-* values for similar components like cards, buttons, or modals to maintain a harmonious visual alignment even across varying content types. Avoid assigning arbitrary values; instead, extend the theme configuration to include reusable custom values.

Leverage Utility Combinations

Combining utilities in Tailwind CSS unlocks advanced layouts that are both functional and aesthetically pleasing. Use min-width utilities alongside spacing utilities (e.g., p-*, gap-*) to develop structured layouts that are visually balanced and adaptable.

For example, wrapping elements within flex containers using classes like flex and flex-wrap allow child elements with specific min-w-* settings to rearrange dynamically.

Accessibility Considerations

Enhance Readability and Navigability

Using min-w-* in designs can significantly enhance readability by ensuring text containers remain spacious enough for users to consume content comfortably. When designing forms, cards, or modals, restrict how narrow an element can become to prevent cramped layouts or overflowing text.

This is a live editor. Play around with it!
export default function ReadableForm() {
  return (
    <div className="h-screen flex justify-center items-center bg-gray-100">
      <form className="min-w-80 max-w-lg bg-white p-6 rounded-xl shadow-lg">
        <h2 className="text-xl font-bold text-center">Contact Us</h2>
        <input 
          type="text" 
          placeholder="Name" 
          className="w-full border border-gray-300 rounded-md p-3 mt-4 focus:ring-2 focus:ring-blue-500" 
        />
        <textarea 
          placeholder="Message" 
          className="w-full border border-gray-300 rounded-md p-3 mt-4 focus:ring-2 focus:ring-blue-500"
          rows={5}
        ></textarea>
        <button type="submit" className="w-full mt-4 py-3 bg-blue-600 text-white rounded-md">
          Submit
        </button>
      </form>
    </div>
  );
}

Focus on High Contrast

Contrast issues impact individuals with low vision or color blindness, and improper handling of min-width often magnifies this issue. Use containers with sufficient min-w dimensions in conjunction with Tailwind utilities like bg-* and text-* to provide ample room for text while maintaining accessible contrast ratios.

When designing cards or call-to-action sections, apply wider min-w-* utilities to support large typography or icons alongside text. The additional space provided by larger minimum widths helps accommodate high-contrast foreground and background pairings, avoiding visual clutter.

For interactive elements, use min-w-* in combination with Tailwind's state variants like hover:bg-* and focus:border-*. This ensures that color-based highlights or outlines retain their visibility across all states, further enhancing visual accessibility and usability.