Skip to content
Tutorials Center
My learning

Topics

Lesson 11 of 37 ยท Components and Theming

Ionic Layout: Grid, Flexbox Utilities and Spacing

Lay out Ionic screens with ion-grid, ion-row and ion-col, the 12-column system, breakpoints, padding and margin utilities, and flex and display helpers.

Ionic gives you three layout tools: a responsive 12-column grid, a set of utility classes for padding, margin, flex and display, and plain CSS for everything else. Together they cover most screens without writing custom CSS. This lesson explains each, with the breakpoints and a calculator-style stand-in you can run to understand how columns share space.

The grid

HTML
<ion-grid>
  <ion-row>
    <ion-col>1 of 3</ion-col>
    <ion-col>2 of 3</ion-col>
    <ion-col>3 of 3</ion-col>
  </ion-row>
  <ion-row>
    <ion-col size="8">8</ion-col>
    <ion-col size="4">4</ion-col>
  </ion-row>
</ion-grid>
  • ion-grid is the container; ion-row a horizontal line; ion-col a column.
  • A row has 12 columns. size="4" means four of the twelve.
  • Columns without a size share the remaining space equally.
  • If the columns in a row add up to more than 12, the extra ones wrap to a new line.

Other column properties:

Property Effect
offset="2" Leaves two columns of empty space before this one
push="1", pull="1" Shifts a column left or right visually
size-sm="6", size-md="4", size-lg="3", size-xl="2" Different size from that breakpoint upward
size-auto Width fitted to content

Breakpoints

Breakpoints are minimum widths. A rule at a breakpoint applies at that width and above (mobile-first):

Name Min width Typical device
xs 0 Small phones
sm 576 px Large phones, landscape
md 768 px Tablets
lg 992 px Small laptops
xl 1200 px Desktops

So <ion-col size="12" size-md="6" size-lg="4"> is full width on phones, half width on tablets and a third on laptops: a card grid that adapts.

Stand-in: how a row wraps

This runnable stand-in lays out columns across 12 slots, wraps overflowing ones, and resolves breakpoint sizes. It mimics the rules; the real grid uses CSS flexbox.

JS Stand-in: a 12-column grid with wrapping

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Padding, margin and text utilities

Utility classes live in files such as padding.css and typography.css:

HTML
<ion-content class="ion-padding">...</ion-content>
<div class="ion-padding-horizontal ion-margin-bottom">...</div>
<p class="ion-text-center ion-text-uppercase">Welcome</p>
<p class="ion-text-wrap">Long text that should wrap inside an ion-item label.</p>
<ion-label class="ion-text-nowrap">...</ion-label>

Naming pattern:

  • ion-padding, ion-padding-top, -bottom, -start, -end, -horizontal, -vertical
  • ion-margin, ion-margin-top, ... and ion-no-padding, ion-no-margin
  • ion-text-start, ion-text-center, ion-text-end, ion-text-justify, plus responsive forms such as ion-text-md-center

Padding values come from CSS variables you can override: --ion-padding: 16px and --ion-margin: 16px.

Flexbox helpers

flex-utils.css provides classes that map to flexbox properties:

HTML
<div class="ion-justify-content-between ion-align-items-center" style="display:flex">
  <ion-text>Left</ion-text>
  <ion-button>Right</ion-button>
</div>
Class CSS
ion-justify-content-center justify-content: center
ion-align-items-start align-items: flex-start
ion-wrap flex-wrap: wrap
ion-nowrap flex-wrap: nowrap

Display helpers hide or show elements at breakpoints:

HTML
<div class="ion-hide-md-down">Visible on tablets and larger</div>
<div class="ion-hide-lg-up">Visible below the lg breakpoint</div>

Floats and other helpers

ion-float-start and ion-float-end float elements with right-to-left support. ion-hide, ion-hide-down, and ion-hide-up follow the same breakpoint naming. For anything more specific, use modern CSS, because grid and flexbox are widely supported:

CSS
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

Ionic's own grid is convenient for forms and simple responsive rows; CSS Grid is better for galleries and complex layouts. Mixing them is fine.

Split pane for tablets and desktops

Apps that run on tablets or the web often show a sidebar and a main area side by side. ion-split-pane does this and collapses the menu on narrow screens:

HTML
<ion-split-pane contentId="main">
  <ion-menu contentId="main">...</ion-menu>
  <div class="ion-page" id="main">...</div>
</ion-split-pane>

You will use it with the side menu.

A spacing calculator

Utilities scale from a single variable. This stand-in computes the pixels for common helper classes from a base, helping you see why changing --ion-padding once spaces everything consistently.

JS Stand-in: spacing from one variable

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How many columns does an ion-row have?

    Ionic's grid uses 12 columns per row; extra columns wrap.
  2. 2. What does size-md="6" mean?

    Breakpoints are minimum widths, so the value applies from md upward.
  3. 3. Which class adds padding on all sides of ion-content?

    ion-padding adds the standard padding from --ion-padding.
  4. 4. Which component shows a sidebar next to content on large screens?

    ion-split-pane displays a menu beside the main content at wider widths.

Summary

  • ion-grid, ion-row and ion-col form a 12-column responsive grid with size, offset and breakpoint variants.
  • Breakpoints are mobile-first minimum widths: sm 576, md 768, lg 992, xl 1200.
  • Padding, margin, text, flex and display utilities cover everyday spacing.
  • Use CSS Grid for galleries and ion-split-pane for sidebar layouts.

Next: Routing Basics and ion-router-outlet