Lesson 17 +10 XP

Display

Display

Display utilities control how an element is shown.

Common display values

ClassCSS
blockdisplay: block
inline-blockdisplay: inline-block
inlinedisplay: inline
flexdisplay: flex
inline-flexdisplay: inline-flex
griddisplay: grid
inline-griddisplay: inline-grid
contentsdisplay: contents
flow-rootdisplay: flow-root
hiddendisplay: none

Table displays

table, table-caption, table-cell, table-column, table-row, table-header-group, table-footer-group, table-row-group, inline-table, and list-item also exist.

Hiding an element

hidden removes the element from the layout entirely (display: none):

<div class="hidden md:block">Visible on medium screens and up</div>

Screen-reader-only content

sr-only visually hides content while keeping it available to screen readers (a 1px box with clip-path). not-sr-only undoes it.

<span class="sr-only">Loading...</span>

A note on replaced elements

Preflight makes images display: block. Use inline to make them inline again:

<img class="inline" src="..." alt="..." />

TL;DR

  • block, inline, flex, grid, hidden, and more.
  • hidden = display none.
  • sr-only hides visually but keeps for screen readers.
  • flex and grid are display values, not separate systems.