CSS | grid-template-columns Property
The grid-template-columns property in CSS is used to set the number of columns and size of the columns of the grid. This property accepts more than one values. The number of columns is set by the number of values given to this property.
Syntax:
grid-template-columns: none|auto|max-content|min-content|length| initial|inherit;
Property Values:
- none: It is the default value of grid-template-columns property. The grid doesn’t contain any columns unless needed.
Syntax:grid-template-columns: none;
- length: It sets the grid-template-columns property in length. The length can be set in form of px, em, percentage, etc specifies the size of the columns.
Syntax:grid-template-columns: length;
- auto: The size of columns is set automatically based on the content and element size.
Syntax:grid-template-columns: auto;
- min-content: It sets the size of column based on the largest minimum content size.
Syntax:grid-template-columns: min-content;
- max-content: It sets the size of column based on the largest maximum content size.
Syntax:grid-template-columns: max-content;
- initial: It sets the grid-template-columns property to default value.
Syntax:grid-template-columns: initial;
- inherit: It sets the grid-template-columns property from its parent element.
Syntax:grid-template-columns: inherit;
Example 1:
<!DOCTYPE html> <html> <head> <title> CSS grid-template-columns Property </title> <style> .geeks { background-color:green; padding:30px; display: grid; grid-template-columns: auto auto 200px 150px; grid-gap: 10px; } .GFG { background-color: white; border: 1px solid white; font-size: 30px; text-align: center; } </style> </head> <body> <div class="geeks"> <div class="GFG">A</div> <div class="GFG">B</div> <div class="GFG">C</div> <div class="GFG">D</div> <div class="GFG">E</div> <div class="GFG">F</div> <div class="GFG">G</div> <div class="GFG">H</div> </div> </body> </html> |
Output:

Example 2:
<!DOCTYPE html> <html> <head> <title> CSS grid-template-columns Property </title> <style> .geeks { background-color:green; padding:30px; display: grid; grid-template-columns: min-content max-content 400px min-content; grid-gap: 10px; } .GFG { background-color: white; border: 1px solid white; font-size: 30px; text-align: center; } </style> </head> <body> <div class="geeks"> <div class="GFG">Geeks</div> <div class="GFG">GFG</div> <div class="GFG">C</div> <div class="GFG">D</div> <div class="GFG">E</div> <div class="GFG">F</div> <div class="GFG">G</div> <div class="GFG">H</div> </div> </body> </html> |
Output:

Supported Browsers: The browser supported by grid-template-columns property are listed below:
- Google Chrome 57.0
- Internet Explorer 16.0
- Firefox 52.0
- Opera 44.0
- Safari 10.0
Recommended Posts:
- CSS | transition-property Property
- CSS | nav-right property
- CSS | nav-down property
- CSS | top Property
- CSS | right Property
- CSS | all Property
- CSS border Property
- CSS | columns Property
- CSS | align-self Property
- Web API | DOMRectReadOnly y property
- CSS | flex Property
- CSS | resize Property
- CSS | bleed property
- CSS | grid-gap Property
- CSS | grid-row Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



