TailwindCSS: Layout: display-class

After doing my article on TailwindCSS I said I would do some articles on the classes so this one is for the layout display class

  • Covered in the display will be:

    • block, inline-block and inline
    • flex and inline-flex
    • grid and inline-grid
    • contents
    • table(and various utilities)
    • hidden
  • Instead of having to write out your css: display: flex; its as easy as just adding flex to a class class="flex" in your HTML file.

  • The display is Utilities for controlling the display box type of an element.

Classes and properties

block, inline-block and inline

  • These classes control the flow of texts and elements.
  • using the property block will put the element on its own line and fill its parent.
  • Using the property of inline-block the element will wrap to prevent the text inside from extending beyond its parent.
  • When controlling the flow of text, using the CSS property display: inline will cause the text inside the element to wrap normally.


  • Use flex to create a block-level flex container
<div class="flex items-center">
    <img ----- >
  • This example will centre your container and centre your content inside the container.


  • Used to create an inline flex container that flows with the text
today I wrote an article 
   <span class="inline-flex">
      <img ----- >
all about tailwindCSS
  • This will put your image in the flow of the text.


  • Use grid to create a grid container
<div class="grid gap-4 grid-cols-3 grid-rows-3">
  <!-- ... -->
  • This example will give you a 3 column 3 row grid with a gap between each element.

  • You can use:


to create an inline grid-container.


  • Use contents to create a phantom container whose children act like direct children of the parent.


  • this incudes the classes for table, table-row, table-cell, table-caption, table-column, table-column-group, table-header-group, table-row-group, and table-footer-group.

  • These are the utilities you can use to create elements that behave like their respective table elements.

  • eg.

<div class="table w-full ...">
  <div class="table-header-group ...">
    <div class="table-row">
      <div class="table-cell text-left ...">Song</div>
      <div class="table-cell text-left ...">Artist</div>
      <div class="table-cell text-left ...">Year</div>
--- more table rows with table cells.


  • used to set an element to display:none; and remove it from the page layout.


<div class="flex ...">
  <div class="hidden ...">01</div>
  • The number 1 box will be completely gone from the page and the number 2 box will take its place.

Final note

  • You can use Tailwind to conditionally apply utility classes in different states, like to add inline-flex only when hovered over, and also for different breakpoints like only using inline-flex at medium screens and over. eg.
<div class="flex hover:inline-flex">
  <!-- ... -->


<div class="flex md:inline-flex">
  <!-- ... -->
  • As you have seen Tailwind has a fantastic range of layout options to make your project look great without much effort, and it can mainly be done from your HTML file just by adding in the classes. Thank you for reading I hope you find this article useful.
Avatar for Lisa Tinmurth

Written by Lisa Tinmurth


Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.