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.
Fundamentals
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.
Foundation
📝 Syntax
The syntax for the display property is simple and can be applied to any HTML element.
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.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Initial value
Depends on the element (block for div, inline for span, etc.)
Applies to
All elements
Inherited
No
Animatable
No (discrete property)
Most common values
block, inline, inline-block, none, flex, grid
Reference
💎 Property Values
The display property accepts many keyword values. These are the most important ones for beginners:
Value
Description
block
The element generates a block-level box. It starts on a new line and takes the full width available.
inline
The element generates an inline-level box. It flows with surrounding content on the same line.
inline-block
The element generates a block box that is flowed with surrounding content as an inline box. You can set width and height.
none
The element is completely removed from the document flow and will not be displayed.
flex
The element generates a block-level flex container box.
inline-flex
The element generates an inline-level flex container box.
grid
The element generates a block-level grid container box.
inline-grid
The element generates an inline-level grid container box.
table
The element generates a block-level table box.
inline-table
The element generates an inline-level table box.
list-item
The element generates a block-level box formatted as a list item (with a marker).
run-in
The element generates a block or inline box, depending on context. Limited browser support.
initial
Sets the property to its default value for that element type.
inherit
Inherits the property value from its parent element.
Context
Block vs Inline vs Inline-Block
Behavior
block
inline
inline-block
Starts on new line
Yes
No
No
Full width by default
Yes
No
No (unless you set width)
Respects width & height
Yes
No
Yes
Common HTML default
div, p, h1
span, a, strong
None (set with CSS)
Preview
👀 Live Preview
See how block, inline, and inline-block change layout on the same page:
blockblock
inlineinlineinline
inline-blockinline-blockinline-block
Hands-On
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><divclass="block-element">I am a block element</div><divclass="inline-element">I am an inline element</div>
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: 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.
A11y
♿ 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.
Compatibility
🖥 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 ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions
Full support
OperaAll modern versions
Full support
display property99% 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.
Wrap Up
🎉 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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about display
Use these points when building any CSS layout.
5
Core concepts
🗃01
Box type
Controls rendering.
Purpose
▦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.