Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

Web Development - CSS Display


CSS Display

The display property determines how an element is shown on a web page. It defines whether elements appear on a new line, share a line, or are hidden entirely.


Default Display Values

Every HTML element has a default display value depending on its type:

  • Block-level elements start on a new line and take up the full width. Examples: <div>, <p>, <h1>, <section>
  • Inline elements stay within the flow of text. Examples: <span>, <a>, <strong>, <em>

Example

Default display behavior:

<p>This is a paragraph (block element).</p>
<span>This is a span (inline element).</span>
<span>It continues on the same line.</span>
Try it Yourself »

display: block

Block elements start on a new line and stretch to fill the container's width.

Example

Block elements:

div {
  display: block;
  background: lightblue;
  padding: 10px;
  margin: 10px 0;
}
Try it Yourself »

display: inline

Inline elements do not start on a new line and only take as much width as needed. Margins and padding only affect the left and right sides.

Example

Inline elements:

span {
  display: inline;
  background: lightgreen;
  padding: 5px;
}
Try it Yourself »

display: inline-block

Inline-block elements act like inline elements but respect all box model properties (width, height, margin, padding).

Example

Inline-block boxes:

.box {
  display: inline-block;
  width: 150px;
  height: 100px;
  margin: 5px;
  background-color: coral;
}
Try it Yourself »

This allows multiple boxes to appear next to each other, like buttons or cards.


display: none

The display: none property completely removes an element from the layout (it takes no space).

Example

Hide an element:

.hidden {
  display: none;
}
Try it Yourself »

Note: Elements with display: none are not visible and do not take up space - unlike visibility: hidden.


visibility: hidden

The visibility property hides an element but still keeps its space reserved.

Example

Hidden but occupies space:

.invisible {
  visibility: hidden;
}
Try it Yourself »

Changing Display Type

You can change an element's display behavior to fit your design.

Example

Make inline elements behave like blocks:

a {
  display: block;
  padding: 8px;
  background: lightblue;
  margin: 5px 0;
}
Try it Yourself »

This is often used to make navigation links stack vertically.


display: flex and display: grid

Modern layouts use flex and grid to create advanced, responsive designs. You will learn about these in later chapters.

Example

Basic flex container:

.container {
  display: flex;
  gap: 10px;
}

Summary

  • display defines how an element behaves in the layout.
  • Block elements start on a new line, inline elements do not.
  • inline-block supports box model while staying inline.
  • display: none removes the element; visibility: hidden hides it but keeps its space.
  • Modern layouts use display: flex and display: grid.

Next, you'll learn about CSS Position - how to move and position elements precisely on your web page.

Next » CSS Position


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.