</> Code Corner

CSS · CSS Grid · Lesson 63

CSS Grid Container

grid-template-columns, rows, fr units and repeat().

Grid container properties define the columns and rows of the grid.

Example

<style>
.grid { display: grid; grid-template-columns: 1fr 2fr 1fr; grid-template-rows: 80px 120px; gap: 10px; background: #2196F3; padding: 10px; }
.grid div { background: rgba(255,255,255,.85); text-align: center; padding: 10px; }
.auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; margin-top: 12px; }
.auto div { background: #04AA6D; color: white; padding: 20px; text-align: center; }
</style>
<div class="grid"><div>1fr</div><div>2fr</div><div>1fr</div><div>4</div><div>5</div><div>6</div></div>
<div class="auto"><div>A</div><div>B</div><div>C</div><div>D</div><div>E</div></div>
Property / unit Use
grid-template-columns Number and width of columns
grid-template-rows Height of rows
fr A fraction of the free space
repeat(n, size) Repeat a track pattern
minmax(min, max) A size range
justify-content / align-content Align the whole grid

Keep reading “CSS Grid Container”

Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.

Chat with us 👋