All nuances about the display property
Tags: css, beginners, tutorial, webdev
Published: 2021-12-20 19:33:00

In my experience, the display property raises a lot of questions for novice developers. Yes, to be honest, I often met confusion from experienced developers too. 

I created a [live cheat sheet](https://codepen.io/melnik909/full/LYyXreW) for fixing this situation. Also I talk about most of the nuances of the property in this article.

## display: block
### Default behavior
**1.** The width property of elements with display: block fills up all available space by the text direction. The height property of elements with display: block is calculated automatically depending on the content.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ubaqzf0ppxos4atjdx4.png)

If the content of elements with display: block doesn't fit on one line then browsers will move it to a new line.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uvxlwjx05sve86uuzs31.png)

**2.** The elements with dispay: block always start on a new line.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6uhwcbfanamf5jicgajw.png)

### Box model features
**3.** The width and height properties can be set to elements with dispay: block.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/whsaa3i3i9vqgtmv1du9.png)

**4.** The padding and border properties can be applied too.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/htfucntkorw3q02g1fq8.png)

But surprises wait for us when using margins because they might end up outside the parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pf8tf1yo9leyulj2txcw.png)

And if we set the border or padding property for the parent, margins stop to end up outside it.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ikqilw64a0c2duew5x99.png)

That will work in the case when using vertical paddings or borders but doesn't with horizontal.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tl4xfit2tps9grzzfguz.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0qi3agcpcgyfh7u0jt40.png)

When adding padding or borders with only one side margins will stop ending up outside the parent with this side but will still with the opposite.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/25fahe5gkls6318vpddo.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/smoj2h474w6myhfj42uq.png)

Margins stop to end up outside the parent after adding the overflow property with a value that's different from visible.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/erk9mkq3b2wg4q8xofvp.png)

In the case of the parent with a few items margins before the first and after the last element end up outside the parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wypmibfv1cbkpwloy7co.png)

In this case, adding the border, padding and overflow property for the parent ceases this margin behavior.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g7448baf9zjkx7gycdgs.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w5ce0mdc51h6a1a30sn5.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p79et0pu5mb2eig5jqra.png)

The margins of adjacent elements with display: block collapse too. The browsers choose the biggest between the two.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/740j1537tqfrojhzewbj.png)

The padding, border and overflow properties can't change it.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/225ojdk3vvkbolxzlmt5.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ue47ro7l8uh9zqo8g161.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gc99f48sl004mtcfyggl.png)

## display: inline
### Default behavior
**1.** The width and height properties of elements with display: inline are calculated automatically depending on the content.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/98xfz0ax0ls6674sa886.png)

If the content of elements with display: inline doesn't fit on one line then browsers will move it to a new line. The width will be calculated depending on the maximum line length.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38xf4p1s2wlknok9wqh7.png)

**2.** If there is space elements with display: inline will be on the same line. If no, browsers will move the part of them to a new line.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y5luoav9ex4cxwegk32t.png)

### Box model features
**3.** The width and height properties can't be set to elements with display: inline.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rq166l5vh1k7gl4m77f0.png)

**4.** You can set paddings, borders and margins. Vertical values will end up outside the parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rg6i3eoym08ekde0rlj4.png)

Also, paddings, borders and margins can overlap paddings and borders of the parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ojfi6g6zvxrvs1lzmebq.png)

Paddings, borders and margins overlap each other if elements with display: inline are in multiple rows.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iwu36ptygpz1zffi5uvi.png)

In the case with multiline elements margins can end up outside by horizontal.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gyn5qpbtp3dytdjks4pj.png)

The overflow property crops margins if a value is different from the visible value.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qiin6grpmur3qu9f1zd0.png)

There's no point using margin: auto for elements with display: inline because it won't work.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9sts0ao86wzf4a5o7gur.png)

## display: flex
### Default behavior
**1.** The the width property of elements with display: flex fills up all available space by the text direction. The height property is calculated automatically depending on the content height.

If the element has display: block by default we won't see any changes after changing the block value on flex.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wjshdichlo2q59jjtqbs.png)

And they happen for elements with display: inline. The width property stops depending on the content after the inline value on flex.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bim8z7sglxyoauo84dp5.png)

If the content of elements with display: flex doesn't fit on one line then browsers will move it to a new line. The width property will equal the width property of the parent.

If we change the block value on flex then we won't see changes as with the width property.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g74n86gpq1rrpdl8v9vl.png)

And if we change the inline value to flex the width property stops depending on the maximum line length.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h2yuyz1hd5c0gyn3hnsr.png)

**2.** By default elements with display: flex are positioned in a column. So if we change the block value to flex elements will save its position.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8h4siq1kkft3gv60mxkv.png)

And if we change the inline value to flex we will get that they are positioned in a column.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vtq3sevx40v1n4exlzb5.png)

### Box model features
**3.** The width and height properties can be set to elements with display: flex. Therefore we don't notice changes when changing the block value to flex.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s54jz5761k5oq8ogejnx.png)

The width and height properties start to apply after changing the inline value to flex.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0qcl23ft9nnlafdoxas1.png)

**4.** The padding and border properties can be set for elements with display: flex. If the element has display: block by default we won't see any changes after changing the block value on flex.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zviehkuyrkxkqp3bbpe4.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhiasolmtpu958qs2guw.png)

And we'll see them after changing the inline value to flex because vertical paddings and borders stop ending up outside the parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hcc56x4wey2fvaqu0kok.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ucxdmkw0pf694i5s3fvg.png)

The margin property works with a few specificities. Since vertical margins of elements with display: block might end up outside the parent, this behavior saves after changing the block value to flex.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ue06d471m4sb1hm9wt0i.png)

However, as with elements with display: block adding the border or padding properties to the parent stops this margins behavior.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dntc3m3udoatiz2iz5kv.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j5mvigjbvcjon2987qhv.png)

If the parent has a few elements with display: block top margins will end up outside it from the first element and the bottom from the last. Changing the block value to flex doesn't cancel that.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wjx5oufickoo6wxu3v3g.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y7qat1qpvunwpkijn331.png)

As with a single item case, adding the padding or border properties to the parent stops this behavior for elements with display: flex too.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hq5k7ysda166puxjwffc.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t13mzdmrtn9736w6aoml.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oai7ity6l5x1p8m2gdua.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n64112rf84xii9cfpplj.png)

Also, margins between adjacent elements continue collapsing when changing the block value to flex Also. The gap between elements will equal the largest.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sigzs7phsohaleronws7.png)

And collapsing is saved after adding the padding or border properties.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dc8f5neoydivjl2jbugq.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vnubuo22bumytgx6i845.png)

Since vertical margins of elements with display: inline might end up outside the parent, this behavior saves after changing the inline value to flex.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/to7nlzwyuqzt4stiule1.png)

When changing the inline value to flex, margins don't overlap paddings or margins that are set to the parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e8ekkyoll8aq507bpo2a.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1iwrqju8j6v80luc8lwe.png)

When we change the inline to flex and the parent has multiline elements top margins will end up outside it for only the first element and bottom margins for the last.

Margins from other elements stop overlapping siblings by vertical. They will be collapsed.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tqvy6zepb9b8hoczwgms.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ln4smyu0m25bl5vgr4ws.png)

### Default behavior of flex items
*Note! Flex items are childs of the element with display: flex or display: inline-flex*

**5.** Flex items always are blockified. It means all block values are saved.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mdo7s02q188cfe4mwmhk.png)

All inline values will be changed on block values. So the inline and inline-block values will be changed to block, inline-flex -> flex, inline-grid -> grid and inline-table -> table.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5tekql6p4cr43zjlqasx.png)

**6.** The width property of flex items depending on the flex-direction property. If flex-direction: row (default value) the width property is calculated automatically depending on the content and the height property of flex items is equal to the height property of the parent.

Thus the width property stops to be equal to the width property of the parent for elements with display: block. It's calculated depending on the content. The height property doesn't depend on the content and becomes to equal the height property of the parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9t8wd7myp11q8797vuzp.png)

In the case of elements with display: inline we will get the height property is equal to the height property of the parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/akxzw3gebwtbc23q6b3f.png)

When flex-direction: column the width property of flex items fills up all available space by the text direction and the height property is calculated automatically depending on the content.

As a result, this behavior is the same as the behavior of elements with display: block.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3eacgrpgwwyjg16nomz8.png)

There are changes for elements with display: inline. The width property becomes to be equal to the width parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l9m9tcbn9e7wekp0stc7.png)

If the content of a flex item doesn't fit on one line then browsers will move it to a new line. The width property will equal the width property of the parent. It doesn't matter that a value is set to the flex-direction property.

As a result, the content of elements with display: block will be displayed the same after adding display: flex to its parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ypq1owsmpm0klb1pgm1a.png)

The width property of the element with display: inline stops to be calculated depending on the maximum line length.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0wagv4n05yplsdc64bin.png)

**7.** By default flex items position on the same line. If there isn't space, browsers will squeeze them depending on its content.

For this reason elements with display: block stop positioning in a column.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1x6svp5lk8vvucc9jdym.png)

The single change for elements with display: inline is they are squeezed.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7pfb0foolvkr3zv3hggl.png)

Also, a position might be changed using the flex-direction property. If we set the column value flex items will be stacked and stop squeeze.

This behavior repeats for elements with display: block.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eekzbyop6bf0vadygcd3.png)

In the case of elements with display: inline they stop to be on the same line and will display in a column.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w36casmn47hhwloypskn.png)

### Box model features of flex items

**8.** The width and height properties can be set to flex items. It doesn't matter which the value is used for the flex-direction.

It's why we won't see some changes after becoming the element with display: block to a flex item.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yk8yubhilavljr3hjwre.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/okqiodw6i80go6n1hqqf.png)

When it comes to elements with display: inline we already can set the width and height properties after adding display: flex to the parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kult9f0lw0vuug9j2ehp.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/odyxfn44vi82eb19t822.png)

**9.** The padding and border properties can be set too. They will work without changes for elements with display: block.
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6v35c7xzvosltqq3t6ss.png)

When it comes to elements with display: inline vertical paddings and borders stop ending up outside the parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mxtlo3nsth76gsgw1134.png)

The padding and border properties for elements with display: block save their behavior when adding flex-direction: column to the parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uei9300dhouwxxkv00a5.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/blpy7npitrx6fl7ju5fq.png)

Adding flex-direction: column doesn't affect the behavior of properties for elements with display: inline in comparison with flex-direction: row.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z0dq00m6n1jnaceikzgx.png)

Pay attention vertical margins don't end up outside the parent. That behavior doesn't depend on the flex-direction property. If we set the row or column value we will get an equal result.

That leads to we'll see changes if we use elements with display: block.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gn5zgc48wsdrr6ihvwun.png)

Also, that applies to elements with display: inline.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g3tqoguikfm8mja2gegh.png)

If the parent has two elements with display: block margins stop ending up outside it from the first element and the bottom from the last.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oa5l6loazm7w80hdy239.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4299pq5qlkho2k55yf76.png)

In the case, we set margins for adjacent elements with display: block they stop collapsing.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/so7590107npmk5l2h6fm.png)

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j2qye99jalnsbc0oxfoh.png)

## display: grid
### Default behavior
**1.** The the width property of elements with display: grid fills up all available space by the text direction. The height property is calculated automatically depending on the content.

If the element has display: block by default we won't see any changes after changing the block value on grid.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ixjmr86k8jqlw668isb3.png)

And they happen for elements with display: inline. The width property stops depending on the content after the inline value on grid.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/czx3kmr4vm2pn2non067.png)

If the content of elements with display: grid doesn't fit on one line then browsers will move it to a new line. The width property will equal the width property of the parent.

If we change the block value on grid then we won't see changes as with the width property.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8gxnmcc34nwuz8crtd3f.png)

And if we change the inline value to grid the width property stops depending on the maximum line length.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7qp307iku15as54ilivc.png)

**2.** By default elements with display: grid are positioned in a column. So if we change the block value to grid elements will save its position.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/so87pnl7l5vx1r6jqhis.png)

And if we change the inline value to grid we will get they are positioned in a column.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gqrytr6plgxhpllqoeeo.png)

**3.** The width and height properties can be set to elements with display: grid. Therefore we don't notice changes when changing the block value to grid.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zzn5kp7z4mdd6gad99az.png)

The width and height properties start to apply after changing the inline value to grid.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7fcn9k9jxwqq24x0zlmd.png)

**4.** The padding and border properties can be set for elements with display: grid. If the element has display: block by default we won't see any changes after changing the block value on grid.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/04ud7elbisdebrw50huj.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7j9756lnxa1rc79436o4.png)

And we'll see them after changing the inline value to grid because vertical paddings and borders stop ending up outside the parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m6kdmlgl2vrn1tsh4crb.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/328de6ysrtq7ibe5wsxt.png)

Since vertical margins of elements with display: block might end up outside the parent, this behavior stops after changing the block value to grid.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q422z5jmb0bxwvbis79m.png)

However, as with elements with display: block adding the border or padding properties to the parent stops this margins behavior.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/39re9brcrdne14xkne7k.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1i7b9kgdcbfe8j8b2xrv.png)

As with elements with display: block adding to the parent the overflow property with a value that's different from visible cancels margins behavior.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3y5dkje2i487e5hjyfr4.png)

If the parent has a few elements with display: block top margins will end up outside it from the first element and the bottom from the last. Changing the block value to grid doesn't cancel that.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5e4cz0byviij39jzs60e.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/osd7sekort49iok90n2t.png)

As with a single item case, adding the padding, border or overflow properties to the parent stops this behavior for elements with display: grid too.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tom9pgskiqa8gu017yjt.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nqcgtfkhrp1ze8sgpve3.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6wd3iw33je5g91d03c4u.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lvp1sx6yvr5zxdrilzkr.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4x40kbqwvg2sy5a1y9jr.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qa9j0ztlkdhstqyvtlq0.png)

Also, margins between adjacent elements continue collapsing when changing the block value to grid Also. The gap between elements will equal the largest.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/casjts5mbczdhtgrdr4v.png)

And collapsing is saved after adding the padding, border and overflow properties.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m5t0y0ehoyecyxo9xdo7.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tvrahdguly5o1ojqjtk3.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/728rgxmsknhax1moe4l9.png)

Since vertical margins of elements with display: inline might end up outside the parent, this behavior saves after changing the inline value to grid.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/939j0y4k6rmbondjf65v.png)

When changing the inline value to grid, margins don't overlap paddings or margins that are set to the parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yz6rdb2tm7opjspgfxep.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ifc0cdvvvtxdv4dw6vgc.png)

When we change the inline to grid and the parent has multiline elements top margins will end up outside it for only the first element and bottom margins for the last.

Margins from other elements stop overlapping siblings by vertical. They will be collapsed.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e67ttf2umou22ij4b22y.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jgu8taxbf0lh2n5ab38g.png)

Also, changing the inline value to grid leads margins again displays when the overflow is applied. The value should be different from the visible.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yg4hb0j6d9w7aptkd29e.png)

If we define margin: auto to elements with display: block or display: inline that continues doesn't work after adding display: grid.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f4y2y00dmc4i8fdgs7zo.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2c5lc23ocqcj2tj8ji2t.png)

Defining the width property to elements with display: block allows work of margins horizontal. That saves after changing the block value on grid.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/njcuem4vr4xs6wjk621h.png)

In addition, changing the inline value on grid allows using margin: auto if the width property is defined to them.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lgj8zl6bcifg3imxvmgz.png)

### Default behavior of grid items
*Note! grid items are childs of the element with display: grid or display: inline-grid*

**5.** Grid items always are blockified. It means all block values are saved.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v17xxmtkjnv4oke0ma82.png)

All inline values will be changed on block values. So the inline and inline-block values will be changed to block, inline-grid -> grid, inline-grid -> grid and inline-table -> table.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ornlzfe0kgsfukabxnrr.png)

**6.** The width property of grid items is equal to the width property of the parent. The height property tries to fill all space.

Thus the width property keeps being equal to the width property of the parent for childs with display: block. The height property stops depending on the content but looks the same when the height property isn't defined to the parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i8zz3wx4hvllx0tsvtiv.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lnyxz9y3j54bcbrxgyu1.png)

In this case, if it's defined filling all space of the height property is more noticeable.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ucwtd108iiq4699dlmhy.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/alk6807v8n7qia3pu5dp.png)

In the case of childs with display: inline we will get the width property stops depending on the content. The height property looks the same like before if the height property isn't defined to the parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9tli33n3mmgafvusbna9.png)

If the height property is defined to the parent we will better see how the property stretches.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/woiyrh74pj8u1tm1ancz.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7dakywp3w1wq3vyobwn8.png)

If the content of a grid item doesn't fit on one line then browsers will move it to a new line. The width property will equal the width property of the parent.

As a result, the content of childs with display: block will be displayed the same after adding display: grid to its parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vbux9xfzlwlrv0ehf9dn.png)

The width property of the childs with display: inline stops to be calculated depending on the maximum line length.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hvjnvrj5fa2j8eh1136u.png)

By default, grid items start on a new line. For this reason childs with display: block still saves position.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ll71dcpn7yi2mqkp2dfa.png)

In contrast to the case with childs with display: block, childs with display: inline changes default position.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lmmu0gb4ghtzdythzc3e.png)

#### Box model features of grid items
**8.** The width and height properties can be set to grid items. It's why we won't see some changes after changing the display property of the parent with the block value to grid.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vpf27bvley4tis9vd6h3.png)

When considering childs with display: inline we already can set the width and height properties after adding display: grid to the parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eeqd3j23tu2pa4y4c01u.png)

**9.** The padding and border properties can be set too. They will work without changes for childs with display: block.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bb4q2ac06muht9c4fo9p.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u2bg14fg1vs39byguz98.png)

When it comes to childs with display: inline vertical paddings and borders stop ending up outside the parent.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ixis6rl1zoy3wtss8xcv.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ll5b1h8guy52zowdt99t.png)

Pay attention, vertical margins don't end up outside the parent. That leads to we'll see changes if display: block is set to childs.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xz4e1t0c9ht42m8zq5yq.png)

If the parent has two childs with display: block margins stop ending up outside it from the first child and the bottom from the last.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kb669m6sdvlo7faefxz7.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c8fuy21hx8amd8z7o224.png)

In the case, we set margins for adjacent childs with display: block they stop collapsing.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wzkoa0g2t215b493ofnj.png)

Vertical margins of childs with display: inline cease to end up outside the parent when adding display: grid to it.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2e2zf5797f199lqkoj1v.png)

Also, margins cease to overlap paddings and borders.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jf1066lm4e01yign3okc.png)
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fop8n9sfm58ortcn7h6c.png)

When applying margin: auto the width and height properties of the childs are calculated depending on the content after adding display: grid to the parent. All space between the childs and the parent's borders will be shared evenly.

We'll see the width property stops to be equal to the width property of the parent after changing the block value on grid.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0mgmptsf14yzso56lier.png)

The width and height properties keep behavior after changing the inline value on grid.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fgk5wqj7e17wt561g3vn.png)

Adding margin: auto to grid items stops filling all space of the width and height properties.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/505bfum1rem07jbcj1jh.png)

**P.S.**
💪 Get more free tips about CSS [directly to your inbox](https://cssisntmagic.substack.com/archive)

❤ Thank you so much, my sponsors: Ben Rinehart, Jesse Willard, Tanya Ten, Konstantinos Kapenekakis.