CSS Layout – The display Property

The display property decides how an element behaves in the layout. Every element has a default display type, and CSS can change it.

ValueBehaviour
blockStarts on a new line, takes the full width. Width and height work
inlineStays in the text line. Width and height do not work
inline-blockStays in the line, but width, height, padding and margin work
noneThe element is removed and takes no space
flexFlexbox container, see Flexbox
gridGrid container, see Grid
span.box { display: inline-block; width: 100px; height: 40px; background: #81d4fa; }
li { display: inline; }      /* list items in one line */
.hidden { display: none; }
Three inline-block boxes in one line

one two three


display: none or visibility: hidden?

RuleResult
display: noneHidden, and takes no space. The other elements move up
visibility: hiddenHidden, but its space stays empty
Note: Block elements like div can be shown in a line with inline-block, and inline elements like a can get a width and height the same way.

Summary

  • block = full line, inline = flows with text, inline-block = both.
  • display: none removes the element from the layout.
  • Next: CSS Position.

Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.