CSS grid Property
It is a CSS property that provides a grid-based layout system with rows and columns to make designing web pages without floats and positioning easier.
Syntax
grid: none | grid-template-rows | grid-template-columns | grid-template-areas | grid-template-rows | [grid-auto-flow] grid-auto-columns | [grid-auto-flow] grid-auto-rows | grid-template-columns | initial | inherit;
Example
x
<html>
<head>
<style>
.grid-container {
display: grid;
grid: 100px / auto auto auto;
grid-gap: 12px;
background-color: #00ab55;
padding: 12px;
}
.grid-container > div {
background-color: rgba(255, 255, 255, 0.8);
text-align: center;
padding: 12px 0;
}
</style>
</head>
<body>
<div class="grid-container">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>
</body>
</html>
Property Values
Value | Description |
---|---|
none | The default value. There is no set size for the columns or rows. |
grid-template-rows / grid-template-columns | The size(s) of the columns and rows are specified. |
grid-template-areas | The grid layout is specified using named items. |
grid-template-rows / grid-auto-columns | The size (height) of the rows and the auto size of the columns are specified. |
grid-auto-rows / grid-template-columns | Sets the grid-template-columns property and specifies the auto size of the rows. |
grid-template-rows / grid-auto-flow / grid-auto-columns | Specifies the size (height) of the rows, how auto-placed items should be placed, and the auto size of the columns. |
grid-auto-flow / grid-auto-rows / grid-template-columns | Sets the grid-template-columns property and specifies how to place auto-placed items, as well as the auto size of the rows. |
initial | This property is set to its default value. |
inherit | This property is inherited from its parent element. |
Supported Browsers
Property | Chrome | Firefox | Safari | Edge / IE | Opera |
---|---|---|---|---|---|
grid | 57.0 | 52.0 | 10.0 | 16.0 | 44.0 |