Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

CSS grid-template-columns Property

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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: 

html




<!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:

 CSS grid-template-columns example1 gfg 

Example 2: 

html




<!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:

 CSS grid-template-columns example2 

Supported Browsers: The browser supported by grid-template-columns property are listed below:

  • Google Chrome 57.0 and above
  • Edge 16.0 and above
  • Internet Explorer 10.0 and above
  • Firefox 52.0 and above
  • Opera 44.0 and above
  • Safari 10.1 and above

My Personal Notes arrow_drop_up
Last Updated : 05 Jun, 2023
Like Article
Save Article
Similar Reads
Related Tutorials