Introduction
The display property controls how an element appears on the page. It helps decide if an element is shown, hidden, or arranged in a certain way.
Jump into concepts and practice - no test required
The display property controls how an element appears on the page. It helps decide if an element is shown, hidden, or arranged in a certain way.
selector {
display: value;
}block, inline, none, flex, or grid.p {
display: block;
}span {
display: inline;
}div {
display: none;
}nav {
display: flex;
}This page shows different display values:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Display Property Example</title> <style> .block-box { display: block; width: 10rem; height: 5rem; background-color: lightblue; margin-bottom: 1rem; text-align: center; line-height: 5rem; border: 1px solid #333; } .inline-box { display: inline; width: 10rem; /* ignored for inline */ height: 5rem; /* ignored for inline */ background-color: lightgreen; border: 1px solid #333; padding: 0.5rem; margin-right: 1rem; } .none-box { display: none; } .flex-container { display: flex; gap: 1rem; margin-top: 1rem; } .flex-item { background-color: lightcoral; padding: 1rem; color: white; border-radius: 0.5rem; } </style> </head> <body> <h1>Display Property Demo</h1> <div class="block-box">Block Box</div> <span class="inline-box">Inline Box 1</span> <span class="inline-box">Inline Box 2</span> <div class="none-box">You cannot see me!</div> <div class="flex-container"> <div class="flex-item">Flex 1</div> <div class="flex-item">Flex 2</div> <div class="flex-item">Flex 3</div> </div> </body> </html>
Using display: none hides the element and it does not take space on the page.
Inline elements ignore width and height settings.
Flex and grid displays help create modern layouts easily.
The display property controls how elements appear and behave on the page.
Common values are block, inline, none, flex, and grid.
Changing display helps with layout and visibility of webpage parts.
display: none; property do to an element on a webpage?display: none;visibility: hidden; which hides but keeps space, display: none; removes the element entirely.display: none; = hidden and no space [OK]: to assign values, not equals =.display and the value to create a flex container is flex.display: flex; [OK]<div class='container'>
<span>A</span>
<span>B</span>
<span>C</span>
</div>
.container {
display: flex;
flex-direction: column;
}display: flex; with flex-direction: column;flex-direction: column; stacks vertically [OK]p {
display: none;
}display: none; and visibility: hidden;display: none; removes element and space, visibility: hidden; hides element but keeps space.visibility: hidden; to hide content but preserve layout space.display: none; to visibility: hidden; -> Option Bvisibility: hidden; [OK]display: flex; on container creates a flexible row layout. justify-content: space-around; spaces items evenly with space around them.display: flex; on the container with justify-content: space-around;. -> Option A