grid
====

Baseline Widely available
-------------------------

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2020.

* Learn more
* See full compatibility
* Report feedback
La propiedad CSS **`grid`** es un shorthand que permite definir todas las propiedades *grid* explícitas (`grid-template-rows`, `grid-template-columns`, y `grid-template-areas`), implícitas (`grid-auto-rows`, `grid-auto-columns`, y `grid-auto-flow` (en-US)), y relativas a *gutter* (`grid-column-gap` y `grid-row-gap` (en-US)) en una sola declaración.


```css
/\* <'grid-template'> values \*/
grid: none;
grid: "a" 100px "b" 1fr;
grid: [linename1] "a" 100px [linename2];
grid: "a" 200px "b" min-content;
grid: "a" minmax(100px, max-content) "b" 20%;
grid: 100px / 200px;
grid: minmax(400px, min-content) / repeat(auto-fill, 50px);

/\* <'grid-template-rows'> /
 [ auto-flow && dense? ] <'grid-auto-columns'>? values \*/
grid: 200px / auto-flow;
grid: 30% / auto-flow dense;
grid: repeat(3, [line1 line2 line3] 200px) / auto-flow 300px;
grid: [line1] minmax(20em, max-content) / auto-flow dense 40%;

/\* [ auto-flow && dense? ] <'grid-auto-rows'>? /
 <'grid-template-columns'> values \*/
grid: auto-flow / 200px;
grid: auto-flow dense / 30%;
grid: auto-flow 300px / repeat(3, [line1 line2 line3] 200px);
grid: auto-flow dense 40% / [line1] minmax(20em, max-content);

/\* Global values \*/
grid: inherit;
grid: initial;
grid: unset;
```


**Nota:** Sólo se pueden especificar las propiedades explícitas ***o bien*** las propiedades implícitas en una sola declaración `grid`. Las sub-propiedades que no se especifican se definen a su valor inicial, como es normal para shorthands. También, las propiedades relativas a gutter se redefinen mediante este shorthand, incluso cuando no pueden ser definidas mediante el mismo.

|  |  |
| --- | --- |
| Valor inicial | as each of the properties of the shorthand:* `grid-template-rows`: `none`
* `grid-template-columns`: `none`
* `grid-template-areas`: `none`
* `grid-auto-rows`: `auto`
* `grid-auto-columns`: `auto`
* `grid-auto-flow` (en-US): `row`
* `grid-column-gap`: `0`
* `grid-row-gap` (en-US): `0`
* `column-gap`: `normal`
* `row-gap` (en-US): `normal`
 |
| Applies to | grid containers |
| Heredable | no |
| Percentages | as each of the properties of the shorthand:* `grid-template-rows`: refer to corresponding dimension of the content area
* `grid-template-columns`: refer to corresponding dimension of the content area
* `grid-auto-rows`: refer to corresponding dimension of the content area
* `grid-auto-columns`: refer to corresponding dimension of the content area
 |
| Valor calculado | as each of the properties of the shorthand:* `grid-template-rows`: as specified, but with relative lengths converted into absolute lengths
* `grid-template-columns`: as specified, but with relative lengths converted into absolute lengths
* `grid-template-areas`: como se especifica
* `grid-auto-rows`: the percentage as specified or the absolute length
* `grid-auto-columns`: the percentage as specified or the absolute length
* `grid-auto-flow` (en-US): como se especifica
* `grid-column-gap`: the percentage as specified or the absolute length
* `grid-row-gap` (en-US): the percentage as specified or the absolute length
* `column-gap`: as specified, with <length>s made absolute, and normal computing to zero except on multi-column elements
* `row-gap` (en-US): as specified, with <length>s made absolute, and normal computing to zero except on multi-column elements
 |
| Animation type | as each of the properties of the shorthand:* `grid-template-rows`: simple list of length, percentage, or calc, provided the only differences are in the values of the length, percentage, or calc components in the list
* `grid-template-columns`: simple list of length, percentage, or calc, provided the only differences are in the values of the length, percentage, or calc components in the list
* `grid-template-areas`: discrete
* `grid-auto-rows`: by computed value type
* `grid-auto-columns`: by computed value type
* `grid-auto-flow` (en-US): discrete
* `grid-column-gap`: a length
* `grid-row-gap` (en-US): a length
* `column-gap`: a length, percentage or calc();
* `row-gap` (en-US): a length, percentage or calc();
 |

Sintaxis
--------

### Valores

`<'grid-template'>`

Define el `grid-template` (en-US) incluyendo `grid-template-columns`, `grid-template-rows` y `grid-template-areas`.

`<'grid-template-rows'> / [ auto-flow && dense? ] <'grid-auto-columns'>?`

 Implementa un *auto-flow* asignando los *row tracks* explícitamente mediante `grid-template-rows` (definiendo `grid-template-columns` en `none`) y especificando como auto-repetir los *column tracks* mediante `grid-auto-columns` (definiendo `grid-auto-rows` en `auto`). `grid-auto-flow` (en-US) es seteado en `column` en consecuencia, con `dense` si se especifica.
 Todas las otras sub-propiedades de `grid` se redefinen a sus valores iniciales.


`[ auto-flow && dense? ] <'grid-auto-rows'>? / <'grid-template-columns'>`

 Implementa un *auto-flow* asignando los *column tracks* explícitamente mediante `grid-template-columns` (definiendo `grid-template-rows` en `none`) y especificando como auto-repetir los *row tracks* mediante `grid-auto-rows` (definiendo `grid-auto-columns` en `auto`). `grid-auto-flow` (en-US) es seteado en `row` en consecuencia, con `dense` si se especifica.
 Todas las otras sub-propiedades de `grid` se redefinen a sus valores iniciales.


### Sintaxis formal
```

grid =   
  <'grid-template'>                                   |  
  <'grid-template-rows'> / [ auto-flow && dense? ] <'grid-auto-columns'>?  |  
  [ auto-flow && dense? ] <'grid-auto-rows'>? / <'grid-template-columns'>    
  
```

Ejemplo
-------

### HTML


```html
<div id="container">
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
</div>
```

### CSS


```css
#container {
  display: grid;
  grid: repeat(2, 60px) / auto-flow 80px;
}

#container > div {
  background-color: #8ca0ff;
  width: 50px;
  height: 50px;
}
```

### Resultado

Especificaciones
----------------

| Specification |
| --- |
| CSS Grid Layout Module Level 2 # grid-shorthand |

Compatibilidad con navegadores
------------------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

Ver también
-----------

* Propiedades CSS relacionadas: `grid-template` (en-US), `grid-template-rows`, `grid-template-columns`, `grid-template-areas`, `grid-auto-columns`, `grid-auto-rows`, `grid-auto-flow` (en-US)
* Grid Layout Guide: *Line-based placement with CSS Grid (en-US)*
* Grid Layout Guide: *Grid template areas - Grid definition shorthands (en-US)*