| title | Display block | |||||||
|---|---|---|---|---|---|---|---|---|
| description | Learn the behavior of block-level elements in CSS, including how they occupy full width, stack vertically, and fully respect all Box Model properties. | |||||||
| keywords |
|
|||||||
| tags |
|
|||||||
| sidebar_label | block |
The display: block value is one of the three fundamental values of the CSS display property, defining how an element interacts with the rest of the layout.
Elements that default to display: block are known as block-level elements. They are designed to structure the main content of a page, such as paragraphs, headers, lists, and sections.
Block elements follow three strict rules that govern their behavior in the document flow:
By default, a block element will automatically stretch horizontally to occupy
A block element always begins on a new line, effectively pushing any content or elements that came before it onto the previous line. They naturally stack vertically.
Block elements fully respect all components of the Box Model:
widthandheight: Can be explicitly set (e.g.,width: 200px;).marginandpadding: All four sides (top,right,bottom,left) are fully applied and affect the flow.
The following HTML elements default to display: block:
<div>(The generic container)<p>(Paragraph)<h1>through<h6>(Headings)<ul>,<ol>,<li>(Lists and list items)<header>,<section>,<footer>,<nav>,<article>(Semantic HTML5 elements)<form>
You can force any element (even one that is inline by default, like a <span>) to behave like a block element using CSS:
span.full-width-text {
/* This turns the <span> from inline into a block element */
display: block;
/* Now it starts a new line and takes full width */
margin-bottom: 10px;
}In the demo below, you can see how the two elements stack vertically and how they automatically span the entire width of their parent container. If you reduce the width of the purple box, notice that it still begins on a new line and occupies its own vertical space.