CSS Display

CSS Display

  • The display property is the most important CSS property for controlling layout.
  • Specifies if/how an element is displayed.
  • Every HTML element has a default display value depending on what type of element it is.
  • The default display value for most elements is block or inline.

Block-level Elements

Always starts on a new line and takes up the full width available (stretches out to the left and right as far as it can).

Examples of block-level elements: <div>, <h1> - <h6>, <p>, <form>, <header>, <footer>, <section>.

Inline Elements

Does not start on a new line and only takes up as much width as necessary.

Examples of inline elements: <span>, <a>, <img>.

Override The Default Display Value

//a common example is making inline <li> elements for horizontal menus

li {
  display: inline;

Changing an inline element to a block element, or vice versa, can be useful for making the page look a specific way, and still follow the web standards.

Setting the display property of an element only changes how the element is displayed, NOT what kind of element it is. So, an inline element with display: block; is not allowed to have other block elements inside it.

Hide an Element - display:none or visibility:hidden

h1.hidden {
  display: none;

h1.hidden {
  visibility: hidden;

Hiding an element can be done by setting the display property to none. The element will be hidden, and the page will be displayed as if the element is not there.

visibility:hidden; also hides an element. However, the element will still take up the same space as before. .

CSS Display — Structure map

Clickable & Draggable!

CSS Display — Related pages: