Defining grids with fixed columns
Use this property to define a grid system that has a fixed number of columns.
Refer to these definitions to better understand how the property values are used.
Each reference to a grid line refers to the imaginary line on either side of grid cells.
For a layouts with N rows, there are N+1 horizontal grid lines — one at the top, one between each row, and one at the bottom.
For a layouts with M columns, there are M+1 vertical grid lines — one at the left edge, one between each column, and one at the right edge.
Grid lines are numbered starting at 1. For rows, the topmost line is 1 and the bottommost line is N+1. For columns, the leftmost line is 1 and the rightmost line is M+1. ** Arabic, Hebrew and other left-to-right writing systems, reverse everything.
Grid line aliases
For clarity and ease of use, each grid line can be aliased with an arbitrary name. That alias can be used with
grid-column-end property values.
Grid line aliases are defined when specifying
In addition, when a grid line alias is declared by the user within a
grid-template-areas definition, the browser implicitly defines two other names that can be used in those start/end properties. For example, if a
grid-template-areas defines an area named
|'foo-start'||grid-row-start||The topmost line of the area|
|'foo-start'||grid-column-start||The leftmost line of the area|
|'foo-end'||grid-row-end||The bottommost line of the area|
|'foo-end'||grid-column-end||The rightmost line of the area|
grid-template-columns property declares the width of each column in a grid system using any of these units:
- fractional units
- fitting functions
- fixed size units
More about units for specifying column widths . . .
Use a percentage or a factional unit:
|%||percentage||A percent of the grid container's width|
|fr||fractional||A fractonal portion of the grid container's remaining available width (where the sum of all the fractional declarations equals the whole)|
Or use a fitting function:
|min-content||The width of the element is the minimum amount necessary for any element in the grid column to have all its content fit without overflowing.|
|max-content||The width of the element is the maximum amount necessary for any element in the grid column to have all its content fit without overflowing.|
|minmax(H1, H2)||The width is not less than H1 and not more than H2|
|fit-content(H)||The width expands to whatever is needed to fit the contents of the element, but never more than H|
|auto||Use whatever space is available after all other column constraints have been met|
Or use any of these font-relative typographic units to set each grid template column width:
|rem||relative em||The |
|ch||"0"||The advance measure (the width) of the current font's "0" glyph|
|ic||ideograph count||The advance measure (the width) of the current font's "水" ideograph|
Or use any of these fixed size units which are independent of the current font:
|in||inch||A size equal 96px|
|px||pixels||A size equal to 1/96 inch|
|pt||point||A size equal 1in/72 = 1.33px|
|pc||pica||A size equal 1in/6 = 12pt = 16px|
|cm||centimeter||A size equal to 96px/2.54 = 37.8px|
|mm||millimeter||A size equal to 96px/25.4 = 3.8px|
|Q||quarter millimeter||A size equal to 96px/1016 = 0.94px|
Specify one value for each column in the container. For example, a container with 3 columns might look like:
Grid line aliases
Grid line aliases may be defined between the column widths, by specifying an arbitrary name enclosed in square brackets. These aliases may then be used in other CSS declarations that specify starting and ending lines for columns. Each grid line may be aliased with more than one name.
For example, this declaration defines convenient aliases for use in a classic menuarea, body, sidebar grid container.
Shorthand for similar sized columns
When several columns have the same width, it may be convenient to specify them using the
repeat() function, as in this example: