display PropertyThe display property in CSS is the foundation of layout and rendering. It controls how elements are visually formatted, how they participate in the document flow, and how they interact with other elements. Mastery of display is essential for building any web layout, from simple pages to complex applications.
<div>, <h1>, <p>, <ul><span>, <a>, <strong>inline (flows in line), but you can set width, height, margin, and padding. Useful for buttons, badges, and custom controls.Other values: flex (for flexible box layouts), grid (for grid layouts), table (for table-like layouts), and more. These advanced values enable powerful, responsive designs.
display Affects Layoutdisplay to adjust layout as needed.display: none—it hides content from all users, including screen readers.inline-block or flex for custom controls and layouts./* Block-level */
.block-demo .demo-box {
display: block;
}
/* Inline-level */
.inline-demo .demo-box {
display: inline;
}
/* Inline-block */
.inline-block-demo .demo-box {
display: inline-block;
}
/* None */
.none-demo .demo-box {
display: none;
}
Block starts on a new line, inline flows, inline-block is inline but sized.
Try toggling the display type of each demo using the buttons, or inspect the elements to see how display changes their layout and visibility.