Open In App

CSS grid-template-columns Property

The grid-template-columns property in CSS is used to set the number of columns and the size of the columns of the grid. This property accepts more than one value. 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:

Syntax:



grid-template-columns: none;

Syntax:

grid-template-columns: length;

Syntax:

grid-template-columns: auto;

Syntax:

grid-template-columns: min-content;

Syntax:

grid-template-columns: max-content;

Syntax:

grid-template-columns: initial;

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:


Article Tags :