CSS display Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Layout

What You’ll Learn

The display property is one of the most important CSS properties for layout. It controls whether an element behaves as a block, flows inline with text, becomes a flex or grid container, or disappears from the page entirely.

01

Block vs inline

Core box types.

02

Syntax

One property, many values.

03

inline-block

Best of both worlds.

04

display: none

Hide elements.

05

Flex & Grid

Modern layouts.

06

Defaults

HTML element types.

Introduction

The display property in CSS is one of the most powerful and commonly used properties. It specifies the display behavior of an element, determining how an element is displayed on the web page.

The display property can change an element’s box type, enabling it to switch between being a block-level element, an inline element, or even not being displayed at all.

Definition and Usage

Every visible element on a page has a display type. Block elements stack vertically and stretch to the container width. Inline elements sit in a line with surrounding text. Layout systems like Flexbox and Grid begin when you set display: flex or display: grid on a container.

💡
Beginner Tip

Before learning Flexbox or Grid in depth, understand block, inline, and inline-block. They explain why some elements stack and others sit side by side.

📝 Syntax

The syntax for the display property is simple and can be applied to any HTML element.

syntax.css
element {
  display: value;
}

Basic Example

display-inline.css
div {
  display: inline;
}
display: block; display: inline; display: inline-block; display: none; display: flex; display: grid;

Default Value

The default value of the display property depends on the HTML element. For example, the default value for a <div> element is block, while the default value for a <span> element is inline.

Syntax Rules

  • Changing display overrides the browser’s default for that element type.
  • The property is not inherited — each element uses its own display value unless you set it explicitly.
  • display: none removes the element from layout; use it for hiding content visually.
  • flex and grid turn an element into a layout container for its children.
  • Prefer semantic HTML first, then adjust display when you need a different visual layout.

⚡ Quick Reference

QuestionAnswer
Initial valueDepends on the element (block for div, inline for span, etc.)
Applies toAll elements
InheritedNo
AnimatableNo (discrete property)
Most common valuesblock, inline, inline-block, none, flex, grid

💎 Property Values

The display property accepts many keyword values. These are the most important ones for beginners:

ValueDescription
blockThe element generates a block-level box. It starts on a new line and takes the full width available.
inlineThe element generates an inline-level box. It flows with surrounding content on the same line.
inline-blockThe element generates a block box that is flowed with surrounding content as an inline box. You can set width and height.
noneThe element is completely removed from the document flow and will not be displayed.
flexThe element generates a block-level flex container box.
inline-flexThe element generates an inline-level flex container box.
gridThe element generates a block-level grid container box.
inline-gridThe element generates an inline-level grid container box.
tableThe element generates a block-level table box.
inline-tableThe element generates an inline-level table box.
list-itemThe element generates a block-level box formatted as a list item (with a marker).
run-inThe element generates a block or inline box, depending on context. Limited browser support.
initialSets the property to its default value for that element type.
inheritInherits the property value from its parent element.

Block vs Inline vs Inline-Block

Behaviorblockinlineinline-block
Starts on new lineYesNoNo
Full width by defaultYesNoNo (unless you set width)
Respects width & heightYesNoYes
Common HTML defaultdiv, p, h1span, a, strongNone (set with CSS)

👀 Live Preview

See how block, inline, and inline-block change layout on the same page:

block block
inline inline inline
inline-block inline-block inline-block

Examples Gallery

In this example, we’ll demonstrate the display property by changing a block-level <div> to an inline element — plus inline-block, hiding content, and a simple flex layout.

📄 Basic Display Types

Start with the reference example — compare block and inline boxes on div elements.

Example 1 — Block vs Inline

Change a div from its default block behavior to inline so it flows beside other content.

display-block-inline.html
<style>
  .block-element {
    display: block;
    background-color: lightblue;
    padding: 10px;
    margin-bottom: 10px;
  }

  .inline-element {
    display: inline;
    background-color: lightgreen;
    padding: 10px;
  }
</style>

<h1>Display Property Example</h1>
<div class="block-element">I am a block element</div>
<div class="inline-element">I am an inline element</div>
Try It Yourself

How It Works

The first div stacks on its own line because display: block takes the full row. The second div with display: inline sits in the text flow on the same line.

Example 2 — Inline-Block Buttons

Use inline-block when you want items side by side but still need width, height, and vertical spacing control.

display-inline-block.css
.tag {
  display: inline-block;
  padding: 0.4rem 0.75rem;
  margin: 0.25rem;
  background: #e0e7ff;
  border-radius: 999px;
}
Try It Yourself

How It Works

Tags sit in a row like inline text, but padding and margins apply predictably because each tag is still a block box on the inside.

🛠 Visibility & Layout Containers

Use display: none to hide elements and display: flex to build flexible row or column layouts.

Example 3 — Hide with display: none

Remove an element from the layout completely while keeping it in the HTML source.

display-none.css
.hidden-banner {
  display: none;
}
Try It Yourself

How It Works

Unlike visibility: hidden, display: none removes the element from layout so surrounding content collapses as if the element were not there.

Example 4 — Flex Container

Turn a wrapper into a flex container to align child items in a row with even spacing.

display-flex.css
.toolbar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}
Try It Yourself

How It Works

display: flex makes the container a flex formatting context. Child elements become flex items that can be aligned and distributed with properties like justify-content and align-items.

♿ Accessibility

  • Avoid hiding important content with display: none unless it is truly not needed visually and for assistive tech.
  • Prefer semantic elements — use <nav>, <button>, and <ul> instead of only changing div display types.
  • Do not rely on display alone for responsive menus — pair hidden mobile menus with keyboard focus management.
  • Screen readers and display: none — hidden content is usually skipped, but test critical UI like error messages carefully.
  • Use hidden attribute or ARIA when you need more precise control over visibility for assistive technologies.

🧠 How display Works

1

Browser reads HTML

Each element gets a default display type based on its tag name.

Defaults
2

CSS display overrides the box type

Your stylesheet can turn a div inline, a span into a flex container, or hide anything with none.

CSS rule
3

Layout engine positions boxes

Block boxes stack, inline boxes flow in lines, and flex/grid containers arrange their children with new layout rules.

Rendering
=

Structured page layout

Elements appear where you expect — stacked, inline, aligned, or hidden.

🖥 Browser Compatibility

The display property is supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. It is a fundamental property in CSS, and its various values are widely recognized across different browser versions. Testing your website across different browsers is always recommended to ensure consistent behavior.

Baseline · Universal support

Display everywhere

Core values like block, inline, none, flex, and grid work in all modern browsers. Older values like run-in have limited support.

99% Universal support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions
Full support
Opera All modern versions
Full support
display property 99% supported

Bottom line: Standard display values are safe everywhere. Test flex and grid in the browsers your audience uses — support is excellent in all current versions.

🎉 Conclusion

The display property is an essential tool for web developers, providing control over how elements are rendered on a page. By understanding and using the different values of the display property, you can create complex and responsive layouts.

Experiment with different display values to see how they can affect the layout and presentation of your web projects. Start with block and inline, then explore flex and grid for modern layout patterns.

💡 Best Practices

✅ Do

  • Learn block, inline, and inline-block before advanced layout systems
  • Use display: flex or grid for component and page layouts
  • Use semantic HTML elements that match your intended structure
  • Hide decorative or conditional UI with display: none when appropriate
  • Test layouts in multiple browsers and screen sizes

❌ Don’t

  • Abuse display: none on content that should remain accessible
  • Convert everything to div with custom display values when semantic tags exist
  • Use tables (display: table) for page layout when flex or grid is clearer
  • Assume inline elements respect width and height without inline-block
  • Forget that display is not inherited by child elements

Key Takeaways

Knowledge Unlocked

Five things to remember about display

Use these points when building any CSS layout.

5
Core concepts
02

block

Stacks full width.

Default
03

inline

Flows in a line.

Common
🚫 04

none

Hides element.

Visibility
🛠 05

flex / grid

Modern layout.

Layout

❓ Frequently Asked Questions

The display property controls how an element is rendered in the layout. It can make an element block-level, inline, a flex or grid container, or remove it from the page entirely with display: none.
It depends on the HTML element. div, p, and h1 default to block. span, a, and strong default to inline. You can override either with CSS.
Block elements start on a new line and take the full available width. Inline elements flow with text on the same line and only use as much width as their content needs.
Use inline-block when you want elements to sit side by side like inline content but still accept width, height, and vertical margin or padding like a block box.
No. The element stays in the HTML document but is not visible and does not take up layout space. Screen readers may still announce it unless you also use accessibility attributes appropriately.

Practice in the Live Editor

Open the HTML editor, switch a div between block and inline, and see how layout changes instantly.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful