The CSS display property determines how an element is displayed on a webpage, defining its layout behavior and how it interacts with other elements.
- It specifies the type of rendering box an element generates.
- Controls whether an element is shown as a block, inline, flex, grid, etc.
- Affects the layout structure and overall page flow.
<html>
<head>
<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">GeeksforGeeksdiv>
<div class="geeks">display: block; propertydiv>
<div class="main">
<div id="geeks1">Block 1div>
<div id="geeks2">Block 2div>
<div id="geeks3">Block 3div>
div>
body>
html>
Syntax:
display: value;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.
1. Using Display Block
This is the default property for Output: Use this property to display an element inline. It doesn’t start a new line and respects the content flow. Output: 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. Output: This property hides the div or the container which use this property. Using it on one of the div it will make working clear. Output: Display none property on block 2 Flexbox and Grid are modern CSS layout systems used to create flexible and structured layouts.#geeks1 {
background: teal;
display: block;
}
#geeks2 {
background: cyan;
display: block;
}
#geeks3 {
background: green;
display: block;
}

2. Using Inline Display
#geeks1 {
background: teal;
display: inline;
}
#geeks2 {
background: cyan;
display: inline;
}
#geeks3 {
background: green;
display: inline;
}

3. Using Display Inline-block
#geeks1
{
background: teal;
display: inline-block;
}
#geeks2 {
background: cyan;
display: inline-block;
}
#geeks3 {
background: green;
display: inline-block;
}

4. Using Display None
#geeks2 {
background: cyan;
display: none;
}

5. Using Display Flex and Display Grid
Display Property Values
Value Description inline Used to display an element as an inline element. block Used to display an element as a block element contents Used to disappear the container. flex Used to display an element as a block-level flex container. grid Display an element as a block-level grid container. inline-block Display an element as an inline-level block container. inline-flex Display an element as an inline-level flex container. inline-grid Display an element as an inline-level grid container. inline-table It is used to display an inline-level table list-item It is used to display all the elements in run-in It is used to display an element inline or block level, depending on the context. table It is used to set the behavior as for all elements.
table-caption It is used to set the behavior as table-column-group Set the behavior as table-header-group Set the behavior as table-footer-group Set the behavior as table-row-group It is used to set the behavior as table-cell It is used to set the behavior as for all elements. table-column It is used to set the behavior as table-row To set the behavior as for all elements. none Used to remove the element. initial Used to set the default value. inherit Used to inherit property from its parents' elements.