Codectionary / Developer documentation / CSS

display Property

The display property determines how an element generates boxes and participates in layout. block elements start on a new line and fill available width. inline elements flow within text and ignore width/height. inline-block combines inline flow with block-like sizing control. none removes the element from layout entirely.

Syntax

display: block | inline | inline-block | none | flex | grid;

Examples

block vs inline vs inline-block

The fundamental difference in how each value affects layout flow.

.block { display: block; width: 200px; }      /* own line, respects width */
.inline { display: inline; width: 200px; }     /* flows in text, IGNORES width */
.inline-block { display: inline-block; width: 200px; } /* flows in text, respects width */

Hiding Elements

display: none vs the related visibility: hidden.

.gone { display: none; }       /* removed from layout entirely - other elements shift to fill the space */
.invisible { visibility: hidden; } /* stays in layout, just invisible - still takes up space */

Parameters and values

  • block (keyword): Starts on a new line, fills available width
  • inline (keyword): Flows within text, ignores width/height
  • inline-block (keyword): Flows within text but respects width/height
  • none (keyword): Removes the element from layout entirely
  • flex / grid (keyword): Turns the element into a flex or grid container

Best practices

  • Use display: none to fully remove content from layout and accessibility tree; use visibility: hidden to hide visually while keeping the space reserved
  • Remember width/height have no effect on elements with display: inline - switch to inline-block or block if you need to size them
  • Default HTML elements already have sensible display values (div is block, span is inline) - only override when you have a specific layout need

At a glance

Purpose
Presentation and layout
File extension
.css
Runs in
Web browsers
Usually used with
HTML and JavaScript

Specifications & further reading

Related CSS documentation