Kombai Logo

Tailwind CSS Resize

Resize allows elements to be resizable by the user- horizontally, vertically, or both. It typically controls how an element can be dragged or stretched by the end-user, often seen in text areas or other containers.

Tailwind includes a set of utilities that map directly to resize properties, making it easy to apply these transformations in a production-ready environment. Throughout this guide, we will explore how to utilize these utilities in different contexts, showcase how to manage them during interactive states, and introduce ways to adapt them for responsive design.

ClassPropertiesExample
resize-noneresize: none;<div className="resize-none"></div>
resize-yresize: vertical;<div className="resize-y"></div>
resize-xresize: horizontal;<div className="resize-x"></div>
resizeresize: both;<div className="resize"></div>

Overview of Resize

All Directions Resizing

Allowing an element to be resized in both height and width can significantly improve the flexibility of your layout. This approach is often used in text editing environments, multi-line input fields, or other scenarios where you anticipate unpredictable content lengths.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Vertically Resizing

Restricting resizing to a vertical direction is beneficial if your container should only expand in height. This is frequently used for textareas where the text length varies but the element’s width remains consistent to match form layouts or other page structures.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Horizontally Resizing

Some use cases demand a horizontally resizable container—for instance, a sidebar that you want users to be able to expand or contract, but maintain fixed height constraints. This approach is equally relevant for advanced layouts, such as adjustable columns in data tables.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

No Resizing

Sometimes you need to ensure that an element cannot be resized, effectively disabling the user’s ability to modify its dimensions. Even if default styling might allow resizing (e.g., <textarea> in some browsers), you can override it with a straightforward utility in Tailwind.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

States and Responsiveness

While we have covered core functionality, styling often needs to adapt based on state changes (like a hover or focus event), and also across different breakpoints. This flexibility ensures that your design remains consistent yet adaptable, especially for complex, interactive UI elements.

Hover and Focus States

Using state modifiers for hover and focus states can emphasize the resizable container when the user interacts with it.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Breakpoint Modifiers

Breakpoint modifiers in Tailwind allow you to override classes at specific screen widths. For example, you might want to enable horizontal resizing on large screens but disable it on smaller devices to preserve layout integrity.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Real World Examples

Dynamic Text Editor with Resize Controls

A text editor component with resizable input area and character count display.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

A responsive product gallery with resizable image containers.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Reviews Dashboard

A resizable textarea component for customer service representatives to manage product reviews.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Notes Application

A note-taking interface with resizable text areas for each note, allowing users to adjust the height based on content length.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Chat Application

A modern chat interface with resizable message input area.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Best Practices

Leverage Utility Combinations

Tailwind's utility classes can be combined thoughtfully for sophisticated styling. Pairing resize utilities with padding, border, or background classes ensures a resizable element remains visually appealing. For instance, you might use resize-y with border, rounded corners, and hover effects to create an engaging, modern input field that clearly signals its interactivity.

Combining multiple utilities lets you unify your brand’s design language. By systematically layering classes, you can quickly build components that integrate resizing, spacing, color interactions, and typography without reverting to heavy custom styles.

Build Responsive Design

Responsive design ensures that resizing remains meaningful across a broad range of devices and screen sizes. Tailwind’s breakpoint modifiers, such as md, lg, etc., let you toggle resizing behavior based on screen width. A container may allow two-dimensional scaling only on desktops, while restricting it entirely on small mobile screens to preserve layout stability.

The key is to identify where resizing enhances usability for your target audience. On smaller touchscreens, pinch-zoom might be more intuitive than dragging edges. Meanwhile, mid-sized tablets or laptops can benefit from partial resizing to accommodate content. By tailoring each breakpoint setting, you can deliver a more intuitive experience.

Accessibility Considerations

Enhance Readability and Navigability

Resizing in Tailwind can greatly enhance readability, particularly for users who need to enlarge text or interface elements for better accessibility. The ability to drag the element size ensures that content remains well-structured, prevents overflow or clipping, and supports better comprehension.

Additionally, thoughtfully selected font families, weights, and sizes play a vital role in creating a comfortable reading experience. Navigability is just as crucial—while expandable or contractible containers offer layout flexibility, they should be designed to avoid visual confusion or overlapping with nearby elements, ensuring a user-friendly interface.

Focus on High Contrast

High contrast in resizable input fields is vital for accessibility and user clarity, ensuring that users can easily distinguish interactive elements from the surrounding content. This not only supports users with low vision or color blindness but also guarantees that form elements remain easily identifiable, even when resized.

To achieve these accessibility standards, it's crucial to select color pairings that meet or exceed the WCAG contrast ratio of 4.5:1. Tailwind CSS provides a large color palette and also offers a configuration file where you can define and extend your color palette to ensure compliance with accessibility guidelines.