Responsive Grid
The grid is a powerful mobile-first flexbox system for building custom layouts. It is composed of three units — a grid, row(s) and column(s). Columns will expand to fill their row, and will resize to fit additional columns. It is based on a 12 column layout with different breakpoints based on the screen size. The number of columns can be customized using CSS.
How it works
<ion-grid>
<ion-row>
<ion-col>
<div>1 of 3</div>
</ion-col>
<ion-col>
<div>2 of 3</div>
</ion-col>
<ion-col>
<div>3 of 3</div>
</ion-col>
</ion-row>
</ion-grid>
- Grids act as a container for all rows and columns. Grids take up the full width of their container,
but adding the
fixed
attribute will specify the width per screen size, see grid size below. - Rows are horizontal groups of columns that line the columns up properly.
- Content should be placed within columns, and only columns may be immediate children of rows.
- The
size-{breakpoint}
attributes indicate the number of columns to use out of the default 12 per row. So,size="4"
can be added to a column in order to take up 1/3 of the grid, or 4 of the 12 columns. - Columns without a value for size will automatically have equal widths. For example, four instances of
size-sm
will each automatically be 25% wide for the small breakpoint and up. - Column widths are set as a percentage, so they’re always fluid and sized relative to their parent element.
- Columns have padding between individual columns, however, the padding can be removed from the grid and
columns by adding the
ion-no-padding
class to the grid. See the CSS Utilities for more styles that can be applied to the grid. - There are five grid tiers, one for each responsive breakpoint: all breakpoints (extra small), small, medium, large, and extra large.
- Grid tiers are based on minimum widths, meaning they apply to their tier and all those larger than them
(e.g.,
size-sm="4"
applies to small, medium, large, and extra large devices). - Grids can easily be customized via CSS variables. See customizing the grid.
Live Example
You can view a live example of this in Angular here and for React here.
Grid size
By default, the grid will take up 100% width. To set a specific width based on the screen size, add the fixed
attribute. The width of the grid for each breakpoint is defined in the --ion-grid-width-{breakpoint}
CSS variables. For more information, see customizing the grid.
Name | Value | Description |
---|---|---|
xs | 100% | Don't set the grid width for xs screens |
sm | 540px | Set grid width to 540px when (min-width: 576px) |
md | 720px | Set grid width to 720px when (min-width: 768px) |
lg | 960px | Set grid width to 960px when (min-width: 992px) |
xl | 1140px | Set grid width to 1140px when (min-width: 1200px) |