The Wayback Machine - https://web.archive.org/web/20240616163232/https://www.geeksforgeeks.org/css-display-property/
Open In App

CSS Display property

Last Updated : 13 Jun, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The display property in CSS plays a important role in shaping the layout of web pages. You can create flexible and responsive designs by understanding their behaviour and using them effectively. It specifies an element’s display behaviour (the type of rendering box). It defines how an element is rendered in the layout, determining its positioning and interaction within the document’s flow and structure.

Syntax: 

display: value;

Display Property Values:

ValueDescription
inlineIt is used to display an element as an inline element.
blockIt is used to display an element as a block element
contentsIt is used to disappear the container.
flexIt is used to display an element as a block-level flex container.
gridIt is used to display an element as a block-level grid container.
inline-blockIt is used to display an element as an inline-level block container.
inline-flexIt is used to display an element as an inline-level flex container.
inline-gridIt is used to display an element as an inline-level grid container.
inline-tableIt is used to display an inline-level table
list-itemIt is used to display all the elements in <li> element.
run-inIt is used to display an element inline or block level, depending on the context.
tableIt is used to set the behavior as <table> for all elements.
table-captionIt is used to set the behavior as <caption> for all elements.
table-column-groupIt is used to set the behavior as <column> for all elements.
table-header-groupIt is used to set the behavior as <header> for all elements.
table-footer-groupIt is used to set the behavior as <footer> for all elements.
table-row-groupIt is used to set the behavior as <row> for all elements.
table-cellIt is used to set the behavior as <td> for all elements.
table-columnIt is used to set the behavior as <col> for all elements.
table-rowIt is used to set the behavior as <tr> for all elements.
noneIt is used to remove the element.
initialIt is used to set the default value.
inheritIt is used to inherit property from its parents’ elements.

Example : This example uses 3 divs to demonstrate the CSS display property.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>CSS Display property</title>
    <style>
        #geeks1 {
            height: 100px;
            width: 200px;
            background: teal;
            display: block;
        }

        #geeks2 {
            height: 100px;
            width: 200px;
            background: cyan;
            display: block;
        }

        #geeks3 {
            height: 100px;
            width: 200px;
            background: green;
            display: block;
        }

        .gfg {
            margin-left: 20px;
            font-size: 42px;
            font-weight: bold;
            color: #009900;
        }

        .geeks {
            font-size: 25px;
            margin-left: 30px;
        }

        .main {
            margin: 50px;
            text-align: center;
        }
    </style>
</head>

<body>
    <div class="gfg">GeeksforGeeks</div>
    <div class="geeks">display: block; property</div>
    <div class="main">
        <div id="geeks1">Block 1</div>
        <div id="geeks2">Block 2</div>
        <div id="geeks3">Block 3</div>
    </div>
</body>

</html>

Understanding the Display Property

The display property defines how an HTML element should be displayed. It controls the box type generated by an element, affecting its positioning and behavior within the document flow. Let’s dive into the key values:

1. Using Display Block

This is the default property for <div> elements. It places them vertically, one after another. You can adjust the height and width of a block-level element.

Example: Use the given CSS in above example.

#geeks1 {
background: teal;
display: block;
}
#geeks2 {
background: cyan;
display: block;
}
#geeks3 {
background: green;
display: block;
}

Output: 

display block property

2. Using Inline Display

Use this property to display an element inline. It doesn’t start a new line and respects the content flow.

Example: Use the given CSS in above example.

#geeks1 {
background: teal;
display: inline;
}
#geeks2 {
background: cyan;
display: inline;
}
#geeks3 {
background: green;
display: inline;
}

Output: 

display inline property example output

3. Using Display Inline-block

Combining characteristics of both block and inline, this value allows elements to flow inline while still having block-level properties. It’s useful for creating responsive layouts.

Example: Use the given CSS in above example.

#geeks1 
{
background: teal;
display: inline-block;
}
#geeks2 {
background: cyan;
display: inline-block;
}
#geeks3 {
background: green;
display: inline-block;
}

Output: 

display inline block example output

4. Using Display None:

This property hides the div or the container which use this property. Using it on one of the div it will make working clear. 

Example: Use the given CSS in above example. 

#geeks2 {
background: cyan;
display: none;
}

Output: Display none property on block 2

display none property

5. Using display flex and display grid:

These values introduce powerful layout options. Flexbox (display: flex) enables flexible, one-dimensional layouts, while CSS Grid (display: grid) provides two-dimensional grid-based layouts.

Supported Browsers:

The browsers supported by the Display property are listed below: 



Previous Article
Next Article

Similar Reads

What is the difference between display: inline and display: inline-block in CSS?
The display property in CSS is a very useful and commonly used property that contains many values. The display property defines how an HTML element should be displayed on the webpage. The property also specifies the type of box used for an HTML element and how it should be laid out on the page. If we need to display the elements that are laid out a
4 min read
How display: inline is different from display: inline-block in CSS ?
In this article, we will know about the display property in CSS, along with understanding the 2 different property values for display property, i.e., display: inline &amp; display: inline-block properties, &amp; will understand their basic differences &amp; implementation through the examples. The display property facilitates setting the element by
3 min read
What is the difference between display:inline-flex and display:flex in CSS ?
In this article, we will see the display property &amp; its values, i.e. the inline-flex &amp; flex, in order to specify the display behavior of an element, along with understanding their basic differences &amp; will illustrate them through the examples. Both CSS display: inline-flex and display: flex properties are used to create flexible layouts.
3 min read
CSS | font-display property
While using web fonts, the text will be invisible until either web font is loaded or three seconds are passed, at which point the fallback font is used. Font-display allows customizing how web fonts are displayed when the page is being rendered. It is applied using @font-face rule which defines custom fonts in a style sheet. Syntax: @font-face { fo
2 min read
How to apply Transition on CSS Display Property ?
This article will guide the implementation of basic Transition on CSS Display Property, aiming to achieve seamless and aesthetically pleasing transitions when altering the visibility of an element. Upon clicking the button, the image smoothly transitions to create a visually engaging effect. Table of Content Opacity and Display Transition Technique
5 min read
What is the Default Value of the display Property in CSS?
The display property in CSS determines how an element is rendered in the document flow. Each HTML element has a default display value that defines its initial rendering behavior. Default ValueThe default value of the display property varies for different HTML elements. However, most elements have a default display value of block, inline, or inline-
1 min read
How to Apply Transitions to the Display Property in CSS ?
In CSS, transitions allow you to change property values smoothly over a specified duration. However, the display property is not animatable, which means you cannot directly apply transitions to it like you can with properties such as opacity or transform. This limitation is because the display property does not support values between its states (e.
3 min read
What is display Property in CSS ?
The display property in CSS is a fundamental property that defines how an HTML element should be displayed in the layout. It controls the box type generated by an element and, consequently, its positioning and behavior within the document flow. Syntax:/* Example of using the display property */.element { display: value;}Common display Property Valu
2 min read
Display a Resized and Cropped Image using CSS
It helps to resize and crop any image dynamically for pre-defined position on a web page. The resized and cropped image is used in the web pages. There is a way where we can move the cropped image around within the div. Regular width and height that squeeze the image to fit in that pre-defined position. Example: &lt;!DOCTYPE html&gt; &lt;html&gt;
2 min read
Display div element on hovering over &lt;a&gt; tag using CSS
In this article, we will know how to render the div element by hovering over the &lt;a&gt; tag using CSS, &amp; will understand its implementation through the example. We can apply an adjacent sibling CSS selector property to the &lt;a&gt; tag that will display the hidden div element's content while hovering over it. The Adjacent sibling selector i
2 min read