🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Expert Masterclasses.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEcss

css Documentation

LOADING ENGINE...

CSS Template Columns

Master the grid. Learn to define columns, understand the fr unit, and create flexible layouts with grid-template-columns.

style.css
.container {
display: grid;
grid-template-columns:
repeat(3, 1fr);
}
grid.css
1 / 8
🏗️

Tutor:The grid-template-columns property defines the line names and track sizing functions of the grid columns.


Grid Mastery

Unlock nodes by learning column layout techniques.

Concept 1: Defining Columns

To create columns in a grid container, we use grid-template-columns. You can define columns using standard CSS units like pixels (px), percentages (%), or rem.

System Check

Which property defines vertical tracks?


Community Grids

Share Layouts

Built a complex grid layout? Share your template columns strategy.

Enjoying this guide?

Codesyllabus is 100% free and open-source. Support our mission, pay for server infrastructure, and fuel new tutorials by buying us a coffee!

CSS Grid Template Columns

Author

Pascual Vila

Frontend Instructor.

The grid-template-columns property is the heart of defining the vertical tracks (columns) of a CSS Grid layout. It allows you to specify the number of columns and their widths using various units.

Fractional Units (fr)

The fr unit is unique to CSS Grid. It represents a fraction of the available free space in the grid container. For example, 1fr 1fr creates two equal columns, while 2fr 1fr makes the first column twice as wide as the second.

The repeat() Function

When creating grids with many columns of the same size, writing out the units can get repetitive. The repeat() function simplifies this. repeat(3, 1fr) is equivalent to 1fr 1fr 1fr.

Mixing Units

You can mix different units in a single declaration. For instance, 200px 1fr 2fr creates a fixed 200px column, and divides the remaining space between the other two columns in a 1:2 ratio.

Best Practices

Use fr units for fluid layouts that adapt to screen sizes. Use fixed units (px) for elements that must maintain specific dimensions, like sidebars or ad slots.

Grid Glossary

grid-template-columns
CSS property used to define the line names and track sizing functions of the grid columns.
fr (Fractional Unit)
Represents a fraction of the available space in the grid container.
repeat()
CSS function that represents a recurring track list, allowing the definition of a large number of columns in a compact form.
Track
The space between two adjacent grid lines. Essentially a column or a row.