CSS | grid-auto-columns Property
The grid-auto-columns property in CSS is used to specify the size for the columns of implicitly generated grid containers.
Syntax:
grid-auto-columns: auto|max-content|min-content|length|percentage|minmax(min, max)|initial|inherit;
Property Values:
- auto: It is the default value. The size is determined implicitly according to the size of the container.
Example 1:
<!DOCTYPE html><html><head><title>CSS grid-auto-column Property</title><style>.main {display: grid;grid-template-areas: "a a";grid-gap: 20px;padding: 30px;background-color: green;grid-auto-columns: auto;}.GFG {text-align: center;font-size: 35px;background-color: white;padding: 20px 0;}</style></head><body><divclass="main"><divclass="GFG">1</div><divclass="GFG">2</div><divclass="GFG">3</div><divclass="GFG">4</div><divclass="GFG">5</div></div></body></html>chevron_rightfilter_noneOutput:
- length: It is used to specify the size as integer length. Negative values are not allowed.
Example:
<!DOCTYPE html><html><head><title>CSS grid-auto-column Property</title><style>.main {display: grid;grid-template-areas: "a a";grid-gap: 20px;padding: 30px;background-color: green;grid-auto-columns: 8.5cm;}.GFG {text-align: center;font-size: 35px;background-color: white;padding: 20px 0;}</style></head><body><divclass="main"><divclass="GFG">1</div><divclass="GFG">2</div><divclass="GFG">3</div><divclass="GFG">4</div><divclass="GFG">5</div></div></body></html>chevron_rightfilter_noneOutput:
- percentage: It specifies the size as percentage value.
Example:
<!DOCTYPE html><html><head><title>CSS grid-auto-column container Property</title><style>.main {display: grid;grid-template-areas: "a a";grid-gap: 20px;padding: 30px;background-color: green;grid-auto-columns: 30%;}.GFG {text-align: center;font-size: 35px;background-color: white;padding: 20px 0;}</style></head><body><divclass="main"><divclass="GFG">1</div><divclass="GFG">2</div><divclass="GFG">3</div><divclass="GFG">4</div><divclass="GFG">5</div></div></body></html>chevron_rightfilter_noneOutput:
- max-content: It specifies the size depending on the largest item in the container.
- min-content: It specifies the size depending on the smallest item in the container.
- minmax(min, max): It specifies the size in the range of [min, max]. greater than or equal to min and less than or equal to max.
Example:
<!DOCTYPE html><html><head><title>CSS grid-auto-column Property</title><style>.main {display: grid;grid-template-areas: "a a";grid-gap: 20px;padding: 30px;background-color: green;grid-auto-columns: minmax(100px, 4cm);}.GFG {text-align: center;font-size: 35px;background-color: white;padding: 20px 0;}</style></head><body><divclass="main"><divclass="GFG">1</div><divclass="GFG">2</div><divclass="GFG">3</div><divclass="GFG">4</div><divclass="GFG">5</div></div></body></html>chevron_rightfilter_noneOutput:
- initial: It sets the grid-auto-columns property to its default value.
Example:
<!DOCTYPE html><html><head><title>CSS grid-auto-column Property</title><style>.main {display: grid;grid-template-areas: "a a";grid-gap: 20px;padding: 30px;background-color: green;grid-auto-columns: initial;}.GFG {text-align: center;font-size: 35px;background-color: white;padding: 20px 0;}</style></head><body><divclass="main"><divclass="GFG">1</div><divclass="GFG">2</div><divclass="GFG">3</div><divclass="GFG">4</div><divclass="GFG">5</div></div></body></html>chevron_rightfilter_noneOutput:
- inherit: It sets the grid-auto-columns property from its parent element.
Example:
<!DOCTYPE html><html><head><title>CSS grid-auto-column Property</title><style>.main {display: grid;grid-template-areas: "a a";grid-gap: 20px;padding: 30px;background-color: green;grid-auto-columns: inherit;}.GFG {text-align: center;font-size: 35px;background-color: white;padding: 20px 0;}</style></head><body><divclass="main"><divclass="GFG">1</div><divclass="GFG">2</div><divclass="GFG">3</div><divclass="GFG">4</div><divclass="GFG">5</div></div></body></html>chevron_rightfilter_noneOutput:
Supported Browsers: The browser supported by grid-auto-columns property are listed below:
- Chrome 57.0
- Edge 16.0
- Firefox 52.0
- Safari 10.0
- Opera 44.0
Recommended Posts:
- CSS | transition-property Property
- CSS | top Property
- CSS | right Property
- CSS | all Property
- CSS | bottom Property
- CSS | max-width Property
- CSS | column-gap Property
- CSS | animation-name Property
- CSS | height Property
- CSS | left Property
- CSS | perspective Property
- CSS | Display property
- CSS | transition Property
- CSS | grid Property
- CSS | border-top 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.



