The CSS Display property
How to work with the `display` property in CSS
The display property of an object determines how it is rendered by the browser.
It’s a very important property, and probably the one with the highest number of values you can use.
Those values include:
blockinlinenonecontentsflowflow-roottable(and all thetable-*ones)flexgridlist-iteminline-blockinline-tableinline-flexinline-gridinline-list-item
plus others you will not likely use, like ruby.
Choosing any of those will considerably alter the behavior of the browser with the element and its children.
In this post I’ll analyze the most important ones not covered elsewhere:
blockinlineinline-blocknone
I cover others in separate posts:
tablein the Tables guideflexin the Flexbox guidegridin the CSS Grid guide
inline
Inline is the default display value for every element in CSS.
All the HTML tags are displayed inline out of the box except some elements like div, p and section, which are set as block by the user agent (the browser).
Inline elements don’t have any margin or padding applied.
Same for height and width.
You can add them, but the appearance in the page won’t change - they are calculated and applied automatically by the browser.
inline-block
Similar to inline, but with inline-block width and height are applied as you specified.
block
As mentioned, normally elements are displayed inline, with the exception of some elements, including
divpsectionul
which are set as block by the browser.
With display: block, elements are stacked one after each other, vertically, and every element takes up 100% of the page.
The values assigned to the width and height properties are respected, if you set them, along with margin and padding.
none
Using display: none makes an element disappear. It’s still there in the HTML, but just not visible in the browser.
download all my books for free
- javascript handbook
- typescript handbook
- css handbook
- node.js handbook
- astro handbook
- html handbook
- next.js pages router handbook
- alpine.js handbook
- htmx handbook
- react handbook
- sql handbook
- git cheat sheet
- laravel handbook
- express handbook
- swift handbook
- go handbook
- php handbook
- python handbook
- cli handbook
- c handbook
subscribe to my newsletter to get them
Terms: by subscribing to the newsletter you agree the following terms and conditions and privacy policy. The aim of the newsletter is to keep you up to date about new tutorials, new book releases or courses organized by Flavio. If you wish to unsubscribe from the newsletter, you can click the unsubscribe link that's present at the bottom of each email, anytime. I will not communicate/spread/publish or otherwise give away your address. Your email address is the only personal information collected, and it's only collected for the primary purpose of keeping you informed through the newsletter. It's stored in a secure server based in the EU. You can contact Flavio by emailing flavio@flaviocopes.com. These terms and conditions are governed by the laws in force in Italy and you unconditionally submit to the jurisdiction of the courts of Italy.