`grid-template-columns` CSS property
The grid-template-columns CSS property defines the line names and track sizing functions of the grid columns.
The **`grid-template-columns`** [CSS](/docs/Web/CSS) property defines the line names and track sizing functions of the grid columns.
CSS Demo: grid-template-columns
```css interactive-example-choice
grid-template-columns: 60px 60px;
```
```css interactive-example-choice
grid-template-columns: 1fr 60px;
```
```css interactive-example-choice
grid-template-columns: 1fr 2fr;
```
```css interactive-example-choice
grid-template-columns: 8ch auto;
```
```html interactive-example
<section class="default-example" id="default-example">
<div class="example-container">
<div class="transition-all" id="example-element">
<div>One</div>
<div>Two</div>
<div>Three</div>
<div>Four</div>
<div>Five</div>
</div>
</div>
</section>
```
```css interactive-example
#example-element {
border: 1px solid #c5c5c5;
display: grid;
grid-auto-rows: 40px;
grid-gap: 10px;
width: 200px;
}
#example-element > div {
background-color: rgb(0 0 255 / 0.2);
border: 3px solid blue;
}
```
## Syntax
```css
/* Keyword value */
grid-template-columns: none;
/* <track-list> values */
grid-template-columns: 100px 1fr;
grid-template-columns: [line-name] 100px;
grid-template-columns: [line-name1] 100px [line-name2 line-name3];
grid-template-columns: minmax(100px, 1fr);
grid-template-columns: fit-content(40%);
grid-template-columns: repeat(3, 200px);
grid-template-columns: subgrid;
/* <auto-track-list> values */
grid-template-columns: 200px repeat(auto-fill, 100px) 300px;
grid-template-columns:
minmax(100px, max-content)
repeat(auto-fill, 200px) 20%;
grid-template-columns:
[line-name1] 100px [line-name2]
repeat(auto-fit, [line-name3 line-name4] 300px)
100px;
grid-template-columns:
[line-name1 line-name2] 100px
repeat(auto-fit, [line-name1] 300px) [line-name3];
/* Global values */
grid-template-columns: inherit;
grid-template-columns: initial;
grid-template-columns: revert;
grid-template-columns: revert-layer;
grid-template-columns: unset;
```
### Values
- `none`
- : Indicates that there is no explicit grid. Any columns will be implicitly generated and their size will be determined by the grid-auto-columns property.
- `[line-name]`
- : A custom-ident specifying a name for the line in that location. The ident may be any valid string other than the reserved words `span` and `auto`. Lines may have multiple names separated by a space inside the square brackets, for example `[line-name-a line-name-b]`.
- <length>
- : A non-negative length, giving the width of the column.
- <percentage>
- : A non-negative <percentage> value relative to the inline size of the grid container. If the size of the grid container depends on the size of its tracks, the browser treats the percentage as `auto`.
The browser may adjust the intrinsic size contributions of the track to the size of the grid container and may increase the final size of the track by the minimum amount that would result in honoring the percentage.
- <flex>
- : Is a non-negative dimension with the unit `fr` specifying the track's flex factor. Each `<flex>`-sized track takes a share of the remaining space in proportion to its flex factor.
When appearing outside a `minmax()` notation, it implies an automatic minimum (i.e., `minmax(auto, <flex>)`).
- max-content
- : Is a keyword representing the largest [maximal content contribution](https://drafts.csswg.org/css-sizing-3/#max-content) of the grid items occupying the grid track. For example, if the first element of the grid track contains the sentence _"Repetitio est mater studiorum"_ and the second element contains the sentence _"Dum spiro, spero"_, maximal content contribution will be defined by the size of the largest sentence among all of the grid elements - _"Repetitio est mater studiorum"_.
- min-content
- : Is a keyword representing the largest [minimal content contribution](https://drafts.csswg.org/css-sizing-3/#min-content) of the grid items occupying the grid track. For example, if the first element of the grid track contains the sentence _"Repetitio est mater studiorum"_ and the second element contains the sentence _"Dum spiro, spero"_, minimal content contribution will be defined by the size of the largest word among all of the sentences in the grid elements - _"studiorum"_.
- minmax(min, max)
- : Is a functional notation that defines a size range greater than or equal to _min_ and less than or equal to _max_. If _max_ is smaller than _min_, then _max_ is ignored and the function is treated as _min_. As a maximum, a `<flex>` value sets the track's flex factor. It is invalid as a minimum.
- `auto`
- : As a maximum value, it represents the largest max-content size of the items in that track.
As a minimum value, it represents the largest minimum size of items in that track (specified by the min-width/min-height properties of the items). This often corresponds to the min-content size, but not always.
If used outside of minmax() notation, `auto` represents the range between the minimum and maximum values described above. In most cases, this behaves similarly to `minmax(min-content,max-content)`.
> [!NOTE]
> `auto` track sizes (and only `auto` track sizes) can be stretched by the align-content and justify-content properties. Therefore, by default, an `auto`-sized track will take up any remaining space in the grid container.
- fit-content( [ <length> | <percentage> ] )
- : Represents the formula `max(minimum, min(limit, max-content))`, where _minimum_ represents an `auto` minimum (which is often, but not always, equal to a min-content minimum), and _limit_ is the track sizing function passed as an argument to fit-content(). This is essentially calculated as the smaller of `minmax(auto, max-content)` and `minmax(auto, limit)`.
- repeat( [ <positive-integer> | auto-fill | auto-fit ] , <track-list> )
- : Represents a repeated fragment of the track list, allowing a large number of columns that exhibit a recurring pattern to be written in a more compact form.
- [`subgrid`](/docs/Web/CSS/Guides/Grid_layout/Subgrid)
- : The `subgrid` value indicates that the grid will adopt the spanned portion of its parent grid in that axis. Rather than being specified explicitly, the sizes of the grid rows/columns will be taken from the parent grid's definition.
## Formal definition
## Formal syntax
## Examples
### Specifying grid column sizes
#### HTML
```html
<div id="grid">
<div id="areaA">A</div>
<div id="areaB">B</div>
</div>
```
#### CSS
```css
#grid {
display: grid;
width: 100%;
grid-template-columns: 50px 1fr;
}
#areaA {
background-color: lime;
}
#areaB {
background-color: yellow;
}
```
#### Result
100%
## Specifications
## Browser compatibility
## See also
- grid-template-rows
- grid-template-areas
- grid-template
- [Basic concepts of grid layout: grid tracks](/docs/Web/CSS/Guides/Grid_layout/Basic_concepts#grid_tracks)
- Video: [Defining a grid](https://gridbyexample.com/video/series-define-a-grid/)
- [Subgrid](/docs/Web/CSS/Guides/Grid_layout/Subgrid)
Cite this
"`grid-template-columns` CSS property". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/grid-template-columns JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy