CSS The display Property

CSS Tutorial

CSS display Property – Complete Beginner Guide

The display property is one of the most important CSS properties. It controls how elements appear and behave in layout.

If you want to:

  • Align elements

  • Create navigation menus

  • Build layouts

  • Hide or show content

  • Use Flexbox or Grid

You must understand display.

In this beginner-friendly, you’ll learn:

  • What the display property does

  • Block vs inline elements

  • Inline-block

  • None

  • Flex

  • Grid

  • Best practices

  • Common mistakes

Let’s dive in


What Is the CSS display Property?

The display property determines how an element is rendered in the document flow.

Basic syntax:

Different values change layout behavior.


Default Display Values

HTML elements have default display types.

Examples:

ElementDefault Display
<div>block
<p>block
<span>inline
<a>inline
<li>list-item

Understanding default behavior is important.


display: block

Block elements:

  • Take full width

  • Start on a new line

  • Respect width and height

Example:

Now <span> behaves like <div>.


display: inline

Inline elements:

  • Do NOT start on new line

  • Only take required width

  • Ignore width and height

Example:

Now <div> behaves like <span>.


display: inline-block

Inline-block combines both:

  • Stays inline

  • But respects width and height

Example:

Used for:

  • Navigation menus

  • Buttons

  • Cards


display: none

Hides element completely.

Element:

  • Is removed from layout

  • Takes no space

Different from:

Which hides but still keeps space.


display: flex (Flexbox)

Flexbox is modern layout system.

Allows:

  • Horizontal layouts

  • Vertical centering

  • Equal spacing

  • Responsive design

Example:

Flexbox is widely used in modern web design.


display: grid

Grid is powerful 2D layout system.

Allows:

  • Complex layouts

  • Row and column control

  • Responsive grids


display: list-item

Used for list elements.

Adds bullet automatically.


Block vs Inline vs Inline-Block

FeatureBlockInlineInline-Block
New lineYesNoNo
Width controlYesNoYes
Height controlYesNoYes

Real-World Example – Navigation Menu

Without display change:

Items appear vertically.

Using Flexbox:

Now horizontal menu.


Real-World Example – Centering Content

Centers content vertically and horizontally.


display in CSS Frameworks

Frameworks like:

  • Bootstrap

  • Tailwind CSS

Use display utilities.

Example (Tailwind):

Example (Bootstrap):


Responsive Display

You can change display in media queries.

Example:

Used for:

  • Mobile menus

  • Responsive layouts


Common Beginner Mistakes

  •  Using inline when width is needed
  •  Forgetting display: flex before using flex properties
  •  Confusing display: none with visibility: hidden
  •  Using tables for layout instead of flex/grid

Best Practices

  •  Use flex for one-dimensional layouts
  •  Use grid for two-dimensional layouts
  •  Avoid unnecessary display changes
  •  Understand default display behavior
  •  Use display: none carefully

Accessibility Consideration

Using display: none hides content from screen readers.

If content should be visually hidden but accessible:

Use other techniques like:


Frequently Asked Questions (FAQs)

1. What does the display property do in CSS?

It controls how an element is rendered and behaves in layout.


2. What is the difference between block and inline?

Block starts on new line and takes full width; inline stays within line.


3. What is inline-block used for?

It allows elements to stay inline while respecting width and height.


4. What is display: none?

It completely removes element from layout.


5. When should I use flex or grid?

Use flex for simple layouts and grid for complex layouts.


Conclusion

The CSS display property is fundamental to layout design.

You learned:

  • Block vs inline

  • Inline-block

  • None

  • Flexbox

  • Grid

  • Responsive techniques

Mastering display gives you control over layout and structure.

You may also like...