Kombai Logo

Tailwind CSS Display

The display property defines how elements are rendered within the document flow— whether as block-level elements, inline elements, flex containers, or other layout types. It plays a crucial role in shaping the structure and behavior of your design.

Tailwind CSS makes toggling between these display styles effortless with its intuitive utility classes. In this guide, we’ll explore how to effectively use Tailwind’s display utilities to build responsive, well-structured layouts.

ClassPropertiesExample
blockdisplay: block;<div className="block"></div>
inline-blockdisplay: inline-block;<div className="inline-block"></div>
inlinedisplay: inline;<div className="inline"></div>
flexdisplay: flex;<div className="flex"></div>
inline-flexdisplay: inline-flex;<div className="inline-flex"></div>
tabledisplay: table;<div className="table"></div>
inline-tabledisplay: inline-table;<div className="inline-table"></div>
table-captiondisplay: table-caption;<div className="table-caption"></div>
table-celldisplay: table-cell;<div className="table-cell"></div>
table-columndisplay: table-column;<div className="table-column"></div>
table-column-groupdisplay: table-column-group;<div className="table-column-group"></div>
table-footer-groupdisplay: table-footer-group;<div className="table-footer-group"></div>
table-header-groupdisplay: table-header-group;<div className="table-header-group"></div>
table-row-groupdisplay: table-row-group;<div className="table-row-group"></div>
table-rowdisplay: table-row;<div className="table-row"></div>
flow-rootdisplay: flow-root;<div className="flow-root"></div>
griddisplay: grid;<div className="grid"></div>
inline-griddisplay: inline-grid;<div className="inline-grid"></div>
contentsdisplay: contents;<div className="contents"></div>
list-itemdisplay: list-item;<div className="list-item"></div>
hiddendisplay: none;<div className="hidden"></div>

Overview of Display

Block and Inline Elements

Block elements spans the full line width by default. Items typically stack vertically, each occupying its own line. Conversely, inline elements render side by side with other inline elements without a line break. If the element is inline-block, it wraps normally around other inline elements but can have its own height, width, margin, and padding values.

Tailwind provides block, inline-block, and inline utilities for the above display properties.

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

Flow Root Element

Flow-root elements create a new block formatting context, which ensures that floated elements are contained within their parent. This prevents layout issues, such as content overlapping or collapsing, by isolating the element's layout from the rest of the page. In Tailwind CSS, you can use the flow-root utility class to apply display: flow-root to an element.

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

Flex Element

When an element has flex utility, it becomes a flex container in Tailwind, enabling flex item alignment, spacing, and consistent distribution of space along a single row (or a column when flex-direction changes). It’s one of the most common display modes for modern responsive layouts because it allows items to expand or shrink dynamically to fill available space.

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

Inline Flex Element

Inline flex merges the benefits of flex with the natural behavior of inline elements. By applying display: inline-flex, your flex container can remain on the same text line or shared line with other inline elements, if space permits, instead of starting on a new line.

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

Grid Element

Grid is a powerful layout system that enables two-dimensional structuring—both rows and columns simultaneously. Tailwind’s grid, grid-cols-, grid-rows-, and other classes let you produce flexible or fixed grid templates. In Tailwind, the grid utility maps the container to the display: grid property.

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

Inline Grid Element

An inline grid is similar to the inline flex concept. By using display: inline-grid, you can place the grid container in an inline formatting context, allowing it to reside alongside inline or text elements. It behaves similarly to a block-level grid, except it does not force a line break before and after.

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

Contents Element

Tailwind’s contents utility sets display: contents, which makes child elements appear like direct children of the grandparent. The contents can be used to remove an intermediate wrapper from the layout perspective, although it does not remove the actual element from the DOM tree. This approach can be advantageous for complex grid or flex-based child elements where the parent container must be visually bypassed.

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

Table Element

A table display sets an element’s display to behave like a <table> in HTML. You can pair it with table-related utilities in Tailwind (e.g., table-row, table-cell) to replicate a tabular layout. Although using Flex or Grid is often more common, table-based displays can be useful for purely tabular data or older layout patterns.

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

Hidden Element

Hidden in Tailwind equates to display: none, effectively removing an element from the render flow. This differs from other presence-based classes like invisible (which preserves layout space). When an element is set to hidden, it is entirely absent visually, and it does not affect the positioning of siblings.

Use hidden for toggling entire content regions off, helpful in scenarios like conditionally rendering certain elements.

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

States and Responsiveness

Hover and Focus States

Tailwind CSS supports dynamic and interactive behaviors using state-based variants like hover and focus, which can be prepended to utility classes to apply styles only when those states are active.

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

Breakpoint Modifiers

Tailwind CSS allows you to apply utility classes conditionally based on responsive breakpoints, using variants like sm:, md:, lg:, and more. By prefixing these modifiers to utility classes, the styles are applied only when the specified breakpoints are active.

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

Real World Examples

A responsive grid layout for featuring blog posts with images, titles, and excerpts.

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

E-commerce Category Showcase

A flex-based layout for showcasing product categories with hover effects and clear visual hierarchy.

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

Team Members Grid

A responsive team members grid that uses inline-block display for consistent spacing and alignment.

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

Collapsible Navigation Menu

A responsive navigation with hamburger menu for mobile devices.

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

Collapsible FAQ Section

A clean accordion interface using strategic display: block and display: none properties for progressive disclosure.

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

Best Practices

Maintain Design Consistency

Consistency is a fundamental principle when using display utilities in Tailwind CSS. These utilities, such as flex, grid, block, and others, allow you to structure your layouts efficiently. Decide on standard use cases for flex versus grid in your design system. While flex might be used for one-dimensional layouts like navigation bars, grid can be reserved for more complex, two-dimensional layouts like dashboards.

Creating reusable class patterns or design tokens for frequently used layouts can further enhance consistency. For instance, define a flex-row-center class that combines flex, items-center, and justify-center for centering flex children horizontally and vertically. Such patterns make it easier to maintain consistency while simplifying the development process.

Leverage Utility Combinations

Tailwind CSS utilities can be combined thoughtfully to create flexible designs. Display utilities, such as grid and flex, are really helpful when used with alignment and spacing utilities.

For example, combine grid with gap-* and place-items-* to create intuitive and visually appealing layouts. Similarly, flex can be paired with justify-*, items-*, and flex-* to create responsive, row-based layouts.

The key is to balance utility combinations for clarity and performance. Avoid overloading components with too many utilities, as this can make your code harder to read and maintain. Focus on combining utilities that complement each other to achieve your layout goals effectively.

Accessibility Considerations

Enhance Readability and Navigability

Using display utilities effectively can greatly enhance both the readability and navigability of your interface. By structuring content with flex or grid, you can create logical groupings and alignments that help users process information intuitively. For instance, using flex with justify-between for navigation links creates a clean and predictable layout, while grid can be ideal for organizing cards or dashboards.

When designing complex layouts, minimize unnecessary nesting, as it can reduce readability and complicate accessibility. Instead, keep your component hierarchy clean and leverage Tailwind’s utilities for alignment, spacing, and responsive adjustments.

Ensure Keyboard Accessibility

Keyboard navigation is a cornerstone of web accessibility, allowing users who rely on keyboards or assistive devices to interact with content. When using Tailwind CSS display utilities such as hidden, block, inline, etc., it’s critical to ensure that interactive elements remain navigable by keyboard.

When toggling visibility dynamically, such as opening a modal or dropdown, proper focus management is crucial. Focus should programmatically move to the newly visible element without requiring the user to manually tab through the page.

For example, when a modal opens, the focus should automatically shift to its first interactive element (e.g., a close button or input field). When the modal is closed, the focus should return to the element that triggered it (e.g., the button or link). To complement this, use the tabindex attribute to control the keyboard navigability of elements.