Skip to main content
Version: v7 (beta)

ion-grid

shadow

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 the 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.

Overview

  • Grids act as a container for all rows and columns. Grids take up the full width of their container, but adding the fixed property will set the width based on the screen size, see Fixed Grid 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 property indicates 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 columns will each automatically be 25% wide.
  • Column widths are set as a percentage, so they’re always fluid and sized relative to their parent element.
  • There is 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 be customized via CSS variables. See Customizing the Grid.

Default Breakpoints

The default breakpoints for the grid and the corresponding properties are defined in the table below. Breakpoint values can not be customized at this time. For more information on why they can't be customized, see Variables in Media Queries.

NameValueWidth PropertyOffset PropertyPush PropertyPull PropertyDescription
xs0sizeoffsetpushpullSet columns when (min-width: 0)
sm576pxsizeSmoffsetSmpushSmpullSmSet columns when (min-width: 576px)
md768pxsizeMdoffsetMdpushMdpullMdSet columns when (min-width: 768px)
lg992pxsizeLgoffsetLgpushLgpullLgSet columns when (min-width: 992px)
xl1200pxsizeXloffsetXlpushXlpullXlSet columns when (min-width: 1200px)

Basic Usage

By default, columns will take up equal width inside of a row for all devices and screen sizes.

Fixed Grid

Grids take up 100% width of their container. By adding the fixed property to the grid, the width will be set based on the screen size. The width of the grid for each breakpoint is listed in the table below, but it can be customized. For more information, see Customizing the Grid. Open the below example in StackBlitz and resize the screen to see the grid width change.

NameValueDescription
xs100%Width is 100% for xs screens
sm540pxSet grid width to 540px when (min-width: 576px)
md720pxSet grid width to 720px when (min-width: 768px)
lg960pxSet grid width to 960px when (min-width: 992px)
xl1140pxSet grid width to 1140px when (min-width: 1200px)

Column Size

Columns can be set to specific sizes to take up a certain number out of the total number of columns, or resize their width based on the content. The default number of columns is 12, but this can be customized. See the Number of Columns section below for more information.

Content-based size

By setting the size to "auto" the column can size itself based on the natural width of its content. This is necessary when setting a column to an absolute width, such as a specific number of pixels. The columns next to the auto-width column will resize to fill the row.

Specified size

Set the size of a column and the others will automatically resize around it. If a size is specified on all of the columns and it doesn't add up to the total number of columns, there will be empty space after the columns.

Responsive size

The size property will change the column width for all breakpoints. Column also provides several size properties with the breakpoint name appended to the end of "size". These properties can be used to change the width of the column based on the screen size. Open the below example in StackBlitz and resize the screen to see the column widths change.

Column Offset

Columns can be offset to shift to the right by a certain number of columns out of the total number of columns.

Specified offset

Columns can be moved to the right by using the offset property. This property increases the left margin of the column by the number of specified columns. It also shifts the columns to the right of it, if any exist.

Responsive offset

The offset property will change the column's left margin for all breakpoints. Column also provides several offset properties with the breakpoint name appended to the end of "offset". These properties can be used to change the offset of the column based on the screen size. Open the below example in StackBlitz and resize the screen to see the column offsets change.

Column Push & Pull

Columns can be pushed to to the right or pulled to the left by a certain number of columns out of the total number of columns.

Specified push & pull

Reorder the columns by adding the push and pull properties. These properties adjust the left and right of the columns by the specified number of columns making it easy to reorder columns. This will cause columns to overlap if they are shifted to where another column is positioned.

Responsive push & pull

The push and pull properties will change the column's position for all breakpoints. Column also provides several push and pull properties with the breakpoint name appended to the end of "push" / "pull". These properties can be used to change the position of the column based on the screen size. Open the below example in StackBlitz and resize the screen to see the column positions change.

Alignment

Vertical Alignment

All columns can be vertically aligned inside of a row by adding different classes to the row. For a list of available classes, see css utilities.

Horizontal Alignment

All columns can be horizontally aligned inside of a row by adding different classes to the row. For a list of available classes, see css utilities.

Customizing the Grid

Using our built-in CSS variables, it’s possible to customize the predefined grid attributes. Change the values of the padding, the number of columns, and more.

Fixed Width

The width of a fixed grid can be set for all breakpoints with the --ion-grid-width CSS variable. To override individual breakpoints, use the --ion-grid-width-{breakpoint} CSS variables. The default value for each of the breakpoints can be found in the Fixed Grid section. Open the below example in StackBlitz and resize the screen to see the grid width change.

Number of Columns

The number of grid columns can be modified with the --ion-grid-columns CSS variable. By default there are 12 grid columns, but this can be changed to any positive integer and be used to calculate the width of each individual column.

Padding

The padding on the grid container can be set for all breakpoints with the --ion-grid-padding CSS variable. To override individual breakpoints, use the --ion-grid-padding-{breakpoint} CSS variables.

The padding on the columns can be set for all breakpoints with the --ion-grid-column-padding CSS variable. To override individual breakpoints, use the --ion-grid-column-padding-{breakpoint} CSS variables.

プロパティ

fixed

DescriptionIf true, the grid will have a fixed width based on the screen size.
Attributefixed
Typeboolean
Defaultfalse

イベント

No events available for this component.

メソッド

No public methods available for this component.

CSS Shadow Parts

No CSS shadow parts available for this component.

CSSカスタムプロパティ

NameDescription
--ion-grid-paddingPadding for the Grid
--ion-grid-padding-lgPadding for the Grid on lg screens
--ion-grid-padding-mdPadding for the Grid on md screens
--ion-grid-padding-smPadding for the Grid on sm screens
--ion-grid-padding-xlPadding for the Grid on xl screens
--ion-grid-padding-xsPadding for the Grid on xs screens
--ion-grid-widthWidth of the fixed Grid
--ion-grid-width-lgWidth of the fixed Grid on lg screens
--ion-grid-width-mdWidth of the fixed Grid on md screens
--ion-grid-width-smWidth of the fixed Grid on sm screens
--ion-grid-width-xlWidth of the fixed Grid on xl screens
--ion-grid-width-xsWidth of the fixed Grid on xs screens

Slots

No slots available for this component.