Responsive utilities for controlling the CSS display property across breakpoints, with additional support for print contexts.
Overview
Display utilities set the CSS display property. The classes cover a subset of its values, and combine across breakpoints on one element.
Notation
Display classes that apply to all breakpoints, from xs to 2xl, have no breakpoint prefix: they apply from min-width: 0 and up, outside any media query. The classes of the other breakpoints carry the breakpoint as a prefix.
The classes are named using the format:
.d-{value}forxs.{breakpoint}:d-{value}forsm,md,lg,xl, and2xl
Where value is one of:
noneinlineinline-blockblockgridinline-gridtabletable-celltable-rowflexinline-flex
To change the set of values, edit values of the display entry in the $utilities map and recompile the Sass.
The media queries affect screen widths with the given breakpoint or larger. For example, .lg:d-none sets display: none; on lg, xl, and 2xl screens.
Display utilities also have a variant per container width, under the @ prefix: .@md:d-none hides an element when the nearest query container is at least as wide as the md breakpoint, whatever the width of the viewport.
The dark: variant applies within @media (prefers-color-scheme: dark): .dark:d-none hides an element when the system color scheme is dark.
Examples
A display class changes how an element is laid out, whatever its tag: an inline <div>, or a block <span>.
<div class="d-inline p-xs bg-primary fg-contrast">d-inline</div>
<div class="d-inline p-xs bg-neutral fg-contrast">d-inline</div><span class="d-block p-xs bg-primary fg-contrast">d-block</span>
<span class="d-block p-xs bg-neutral fg-contrast">d-block</span>Hiding elements
Responsive display classes control element visibility across breakpoints without requiring separate markup for each screen size.
.d-none hides an element at all breakpoints. Breakpoint-prefixed variants (.sm:d-none, etc.) hide elements at that breakpoint and above.
To show an element only within a range of screen sizes, combine a .{breakpoint}:d-none class with a .{breakpoint}:d-block class. For example, .d-none .md:d-block .xl:d-none makes an element visible only on medium and large screens.
| Screen size | Class |
|---|---|
| Hidden on all | .d-none |
| Hidden only on xs | .d-none .sm:d-block |
| Hidden only on sm | .sm:d-none .md:d-block |
| Hidden only on md | .md:d-none .lg:d-block |
| Hidden only on lg | .lg:d-none .xl:d-block |
| Hidden only on xl | .xl:d-none .2xl:d-block |
| Hidden only on 2xl | .2xl:d-none |
| Visible on all | .d-block |
| Visible only on xs | .d-block .sm:d-none |
| Visible only on sm | .d-none .sm:d-block .md:d-none |
| Visible only on md | .d-none .md:d-block .lg:d-none |
| Visible only on lg | .d-none .lg:d-block .xl:d-none |
| Visible only on xl | .d-none .xl:d-block .2xl:d-none |
| Visible only on 2xl | .d-none .2xl:d-block |
<div class="lg:d-none">hide on lg and wider screens</div>
<div class="d-none lg:d-block">hide on screens smaller than lg</div>Display in print
The display utilities have a print: variant, which applies within @media print. It has the values of the breakpoint variants:
.print:d-none.print:d-inline.print:d-inline-block.print:d-block.print:d-grid.print:d-inline-grid.print:d-table.print:d-table-row.print:d-table-cell.print:d-flex.print:d-inline-flex
The print variant combines with the other display classes on one element.
<div class="print:d-none">Screen only (hidden in print)</div>
<div class="d-none print:d-block">Print only (hidden on screen)</div>
<div class="d-none lg:d-block print:d-block">Hidden below lg on screen, always shown in print</div>CSS
Display utilities are generated via the utilities API.
Reference
The table lists all display utilities and their CSS properties.
| Class | Properties |
|---|---|
.d-inline | display: inline; |
.d-inline-block | display: inline-block; |
.d-block | display: block; |
.d-grid | display: grid; |
.d-inline-grid | display: inline-grid; |
.d-table | display: table; |
.d-table-row | display: table-row; |
.d-table-cell | display: table-cell; |
.d-flex | display: flex; |
.d-inline-flex | display: inline-flex; |
.d-none | display: none; |
Utilities API
Display utilities are declared in scss/utilities/_index.scss using the utilities API.
"display": (
responsive: true,
container: true,
print: true,
dark: true,
property: display,
class: d,
values: inline inline-block block grid inline-grid table table-row table-cell flex inline-flex none
),