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

  1. <ion-grid>
  2. <ion-row>
  3. <ion-col>
  4. <div>
  5. 1 of 3
  6. </div>
  7. </ion-col>
  8. <ion-col>
  9. <div>
  10. 2 of 3
  11. </div>
  12. </ion-col>
  13. <ion-col>
  14. <div>
  15. 3 of 3
  16. </div>
  17. </ion-col>
  18. </ion-row>
  19. </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 andcolumns by adding no-padding on 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.

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.

NameValueDescription
xs100%Don't set the grid width 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)

Grid attributes

The grid takes up full width and has padding added to it based on the screen size. There are twoattributes that can be used to adjust this behavior.

PropertyDescription
no-paddingRemoves padding from the grid and immediate children columns.
fixedSet a max width based on the screen size.

Default breakpoints

The default breakpoints are defined in the table below. Breakpoints can not be customized at this time. For more information on why they can't be customized, see Variables in Media Queries.

NameValueWidth PrefixOffset PrefixPush PrefixPull PrefixDescription
xs0size-offset-push-pull-Set columns when (min-width: 0)
sm576pxsize-sm-offset-sm-push-sm-pull-sm-Set columns when (min-width: 576px)
md768pxsize-md-offset-md-push-md-pull-md-Set columns when (min-width: 768px)
lg992pxsize-lg-offset-lg-push-lg-pull-lg-Set columns when (min-width: 992px)
xl1200pxsize-xl-offset-xl-push-xl-pull-xl-Set columns when (min-width: 1200px)

Auto-layout columns

Equal-width

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

  1. <ion-grid>
  2. <ion-row>
  3. <ion-col>
  4. <div>
  5. 1 of 2
  6. </div>
  7. </ion-col>
  8. <ion-col>
  9. <div>
  10. 2 of 2
  11. </div>
  12. </ion-col>
  13. </ion-row>
  14. <ion-row>
  15. <ion-col>
  16. <div>
  17. 1 of 3
  18. </div>
  19. </ion-col>
  20. <ion-col>
  21. <div>
  22. 2 of 3
  23. </div>
  24. </ion-col>
  25. <ion-col>
  26. <div>
  27. 3 of 3
  28. </div>
  29. </ion-col>
  30. </ion-row>
  31. </ion-grid>

Setting one column width

Set the width of one column and the others will automatically resize around it. This can be done using our predefined grid attributes. In the example below, the other columns will resize no matter the width of the center column.

  1. <ion-grid>
  2. <ion-row>
  3. <ion-col>
  4. <div>
  5. 1 of 3
  6. </div>
  7. </ion-col>
  8. <ion-col size="8">
  9. <div>
  10. 2 of 3 (wider)
  11. </div>
  12. </ion-col>
  13. <ion-col>
  14. <div>
  15. 3 of 3
  16. </div>
  17. </ion-col>
  18. </ion-row>
  19. <ion-row>
  20. <ion-col>
  21. <div>
  22. 1 of 3
  23. </div>
  24. </ion-col>
  25. <ion-col size="6">
  26. <div>
  27. 2 of 3 (wider)
  28. </div>
  29. </ion-col>
  30. <ion-col>
  31. <div>
  32. 3 of 3
  33. </div>
  34. </ion-col>
  35. </ion-row>
  36. </ion-grid>

Variable-width

By setting the size-{breakpoint} properties to "auto" the column can size itself based on the natural width of its content. This is extremely useful for setting a column width using pixels. The columns next to the variable-width column will resize to fill the row.

  1. <ion-grid>
  2. <ion-row>
  3. <ion-col>
  4. <div>
  5. 1 of 3
  6. </div>
  7. </ion-col>
  8. <ion-col size="auto">
  9. <div>
  10. Variable width content
  11. </div>
  12. </ion-col>
  13. <ion-col>
  14. <div>
  15. 3 of 3
  16. </div>
  17. </ion-col>
  18. </ion-row>
  19. <ion-row>
  20. <ion-col>
  21. <div>
  22. 1 of 4
  23. </div>
  24. </ion-col>
  25. <ion-col>
  26. <div>
  27. 2 of 4
  28. </div>
  29. </ion-col>
  30. <ion-col size="auto">
  31. <div>
  32. <ion-input placeholder="Variable width input"></ion-input>
  33. </div>
  34. </ion-col>
  35. <ion-col>
  36. <div>
  37. 4 of 4
  38. </div>
  39. </ion-col>
  40. </ion-row>
  41. </ion-grid>

Responsive attributes

All breakpoints

To customize a column's width for all devices and screens, set the size property. The value of this property determines how many columns this column should take up out of the total available columns.

  1. <ion-grid>
  2. <ion-row>
  3. <ion-col size="4">
  4. <div>
  5. 1 of 4
  6. </div>
  7. </ion-col>
  8. <ion-col size="2">
  9. <div>
  10. 2 of 4
  11. </div>
  12. </ion-col>
  13. <ion-col size="2">
  14. <div>
  15. 3 of 4
  16. </div>
  17. </ion-col>
  18. <ion-col size="4">
  19. <div>
  20. 4 of 4
  21. </div>
  22. </ion-col>
  23. </ion-row>
  24. </ion-grid>

Stacked to horizontal

Use a combination of width and breakpoint attributes to create a grid that starts out stacked on extra small screens before becoming horizontal on small screens.

  1. <ion-grid>
  2. <ion-row>
  3. <ion-col size="12" size-sm>
  4. <div>
  5. 1 of 4
  6. </div>
  7. </ion-col>
  8. <ion-col size="12" size-sm>
  9. <div>
  10. 2 of 4
  11. </div>
  12. </ion-col>
  13. <ion-col size="12" size-sm>
  14. <div>
  15. 3 of 4
  16. </div>
  17. </ion-col>
  18. <ion-col size="12" size-sm>
  19. <div>
  20. 4 of 4
  21. </div>
  22. </ion-col>
  23. </ion-row>
  24. </ion-grid>

Reordering

Offsetting columns

Move columns to the right by adding the offset property. This property increases the margin left of the column by the number of specified columns. For example, in the following grid the last column will be offset by 3 columns and take up 3 columns:

  1. <ion-grid>
  2. <ion-row>
  3. <ion-col size="3">
  4. <div>
  5. 1 of 2
  6. </div>
  7. </ion-col>
  8. <ion-col size="3" offset="3">
  9. <div>
  10. 2 of 2
  11. </div>
  12. </ion-col>
  13. </ion-row>
  14. </ion-grid>


Offsets can also be added based on screen breakpoints. Here's an example of a grid where the last column will be offset by 3 columns for md screens and up:

  1. <ion-grid>
  2. <ion-row>
  3. <ion-col size-md="3">
  4. <div>
  5. 1 of 3
  6. </div>
  7. </ion-col>
  8. <ion-col size-md="3">
  9. <div>
  10. 2 of 3
  11. </div>
  12. </ion-col>
  13. <ion-col size-md="3" offset-md="3">
  14. <div>
  15. 3 of 3
  16. </div>
  17. </ion-col>
  18. </ion-row>
  19. </ion-grid>

Push and 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. For example, in the following grid the column with the 1 of 2 description will actually be the last column and the 2 of 2 will be the first column.

  1. <ion-grid>
  2. <ion-row>
  3. <ion-col size="9" push="3">
  4. <div>
  5. 1 of 2
  6. </div>
  7. </ion-col>
  8. <ion-col size="3" pull="9">
  9. <div>
  10. 2 of 2
  11. </div>
  12. </ion-col>
  13. </ion-row>
  14. </ion-grid>


Push and pull can also be added based on screen breakpoints. In the following example, the column with the 3 of 3 column description will actually be the first column for md screens and up:

  1. <ion-grid>
  2. <ion-row>
  3. <ion-col size-md="6" push-md="3">
  4. <div>
  5. 1 of 3
  6. </div>
  7. </ion-col>
  8. <ion-col size-md="3" push-md="3">
  9. <div>
  10. 2 of 3
  11. </div>
  12. </ion-col>
  13. <ion-col size-md="3" pull-md="9">
  14. <div>
  15. 3 of 3
  16. </div>
  17. </ion-col>
  18. </ion-row>
  19. </ion-grid>

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.

  1. <ion-grid>
  2. <ion-row class="ion-align-items-start">
  3. <ion-col>
  4. <div>
  5. 1 of 4
  6. </div>
  7. </ion-col>
  8. <ion-col>
  9. <div>
  10. 2 of 4
  11. </div>
  12. </ion-col>
  13. <ion-col>
  14. <div>
  15. 3 of 4
  16. </div>
  17. </ion-col>
  18. <ion-col>
  19. <div>
  20. 4 of 4 <br>
  21. # <br>
  22. # <br>
  23. #
  24. </div>
  25. </ion-col>
  26. </ion-row>
  27. <ion-row class="ion-align-items-center">
  28. <ion-col>
  29. <div>
  30. 1 of 4
  31. </div>
  32. </ion-col>
  33. <ion-col>
  34. <div>
  35. 2 of 4
  36. </div>
  37. </ion-col>
  38. <ion-col>
  39. <div>
  40. 3 of 4
  41. </div>
  42. </ion-col>
  43. <ion-col>
  44. <div>
  45. 4 of 4 <br>
  46. # <br>
  47. # <br>
  48. #
  49. </div>
  50. </ion-col>
  51. </ion-row>
  52. <ion-row class="ion-align-items-end">
  53. <ion-col>
  54. <div>
  55. 1 of 4
  56. </div>
  57. </ion-col>
  58. <ion-col>
  59. <div>
  60. 2 of 4
  61. </div>
  62. </ion-col>
  63. <ion-col>
  64. <div>
  65. 3 of 4
  66. </div>
  67. </ion-col>
  68. <ion-col>
  69. <div>
  70. 4 of 4 <br>
  71. # <br>
  72. # <br>
  73. #
  74. </div>
  75. </ion-col>
  76. </ion-row>
  77. </ion-grid>


Columns can also align themselves differently than other columns by adding the alignment class directly to the column. For a list of available classes, see css utilities.

  1. <ion-grid>
  2. <ion-row>
  3. <ion-col class="ion-align-self-start">
  4. <div>
  5. 1 of 4
  6. </div>
  7. </ion-col>
  8. <ion-col class="ion-align-self-center">
  9. <div>
  10. 2 of 4
  11. </div>
  12. </ion-col>
  13. <ion-col class="ion-align-self-end">
  14. <div>
  15. 3 of 4
  16. </div>
  17. </ion-col>
  18. <ion-col>
  19. <div>
  20. 4 of 4 <br>
  21. # <br>
  22. # <br>
  23. #
  24. </div>
  25. </ion-col>
  26. </ion-row>
  27. </ion-grid>

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.

  1. <ion-grid>
  2. <ion-row class="ion-justify-content-start">
  3. <ion-col size="3">
  4. <div>
  5. 1 of 2
  6. </div>
  7. </ion-col>
  8. <ion-col size="3">
  9. <div>
  10. 2 of 2
  11. </div>
  12. </ion-col>
  13. </ion-row>
  14. <ion-row class="ion-justify-content-center">
  15. <ion-col size="3">
  16. <div>
  17. 1 of 2
  18. </div>
  19. </ion-col>
  20. <ion-col size="3">
  21. <div>
  22. 2 of 2
  23. </div>
  24. </ion-col>
  25. </ion-row>
  26. <ion-row class="ion-justify-content-end">
  27. <ion-col size="3">
  28. <div>
  29. 1 of 2
  30. </div>
  31. </ion-col>
  32. <ion-col size="3">
  33. <div>
  34. 2 of 2
  35. </div>
  36. </ion-col>
  37. </ion-row>
  38. <ion-row class="ion-justify-content-around">
  39. <ion-col size="3">
  40. <div>
  41. 1 of 2
  42. </div>
  43. </ion-col>
  44. <ion-col size="3">
  45. <div>
  46. 2 of 2
  47. </div>
  48. </ion-col>
  49. </ion-row>
  50. <ion-row class="ion-justify-content-between">
  51. <ion-col size="3">
  52. <div>
  53. 1 of 2
  54. </div>
  55. </ion-col>
  56. <ion-col size="3">
  57. <div>
  58. 2 of 2
  59. </div>
  60. </ion-col>
  61. </ion-row>
  62. </ion-grid>

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.

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.

  1. --ion-grid-columns: 12;

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

  1. --ion-grid-padding: 5px;
  2. --ion-grid-padding-xs: 5px;
  3. --ion-grid-padding-sm: 5px;
  4. --ion-grid-padding-md: 5px;
  5. --ion-grid-padding-lg: 5px;
  6. --ion-grid-padding-xl: 5px;

Grid width

To customize the width values of the fixed grid based on the screen size, override the values of —ion-grid-width-{breakpoint} for each breakpoint.

  1. --ion-grid-width-xs: 100%;
  2. --ion-grid-width-sm: 540px;
  3. --ion-grid-width-md: 720px;
  4. --ion-grid-width-lg: 960px;
  5. --ion-grid-width-xl: 1140px;

Column Padding

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.

  1. --ion-grid-column-padding: 5px;
  2. --ion-grid-column-padding-xs: 5px;
  3. --ion-grid-column-padding-sm: 5px;
  4. --ion-grid-column-padding-md: 5px;
  5. --ion-grid-column-padding-lg: 5px;
  6. --ion-grid-column-padding-xl: 5px;