General Ionic Framework development — core concepts, component reference, CLI usage, layout, theming, utilities, development workflow, and troubleshooting.
npm install -g @ionic/cli).ionic-app-creation skill.package.json for @ionic/angular, @ionic/react, or @ionic/vue to determine the framework in use. Adapt code examples accordingly.Ionic Framework is a UI toolkit for building cross-platform apps using web technologies (HTML, CSS, JavaScript/TypeScript). It provides a library of pre-built UI components that adapt their styling to the platform ( ios or md mode).
ion- (e.g., <ion-button>, <ion-content>).ios mode; Android and all other platforms use the md (Material Design) mode. The <html> element receives a class ( ios or md) that enables platform-specific styles.capacitor-app-development skill for Capacitor-specific guidance.Ionic provides lifecycle events on top of the framework's own lifecycle hooks. These fire when a page is navigated to or from:
EventDescriptionionViewWillEnterFires when the page is about to enter and become active.ionViewDidEnterFires when the page has fully entered and is now active.ionViewWillLeaveFires when the page is about to leave and become inactive.ionViewDidLeaveFires when the page has fully left and is now inactive.
These are in addition to the framework-specific lifecycle hooks (e.g., Angular's ngOnInit, React's useEffect, Vue's onMounted). Use Ionic lifecycle events for tasks that should run each time a page becomes visible (e.g., refreshing data), since some navigation strategies cache pages.
Ionic provides 80+ UI components. Detailed API documentation for each component is organized into reference files by category. Each reference file covers properties, events, methods, slots, CSS shadow parts, and CSS custom properties.
When the user needs help with a specific component, read the corresponding reference file.
CategoryReference FileComponents CoveredAction & Buttonsreferences/components-action.mdaction-sheet, button, fab, fab-button, fab-list, ripple-effectData Displayreferences/components-data-display.mdaccordion, accordion-group, badge, card, card-content, card-header, card-subtitle, card-title, chip, item, item-divider, item-group, item-sliding, item-options, item-option, label, list, list-header, note, textFormreferences/components-form.mdcheckbox, datetime, datetime-button, input, input-otp, input-password-toggle, picker, radio, radio-group, range, searchbar, select, select-option, segment, segment-button, segment-content, segment-view, textarea, toggleLayoutreferences/components-layout.mdapp, content, grid, col, row, header, footer, toolbar, title, buttons, back-button, split-paneMediareferences/components-media.mdavatar, icon, img, thumbnailNavigationreferences/components-navigation.mdbreadcrumb, breadcrumbs, menu, menu-button, menu-toggle, nav, nav-link, router, router-link, router-outlet, route, route-redirect, tabs, tab, tab-bar, tab-buttonOverlayreferences/components-overlay.mdalert, loading, modal, popover, toast, backdropScroll & Virtualreferences/components-scroll.mdinfinite-scroll, infinite-scroll-content, refresher, refresher-content, reorder, reorder-groupProgressreferences/components-progress.mdprogress-bar, skeleton-text, spinner
The Ionic CLI is the primary tool for developing Ionic apps. Below are the most commonly used commands. Run ionic --help for the full and always up-to-date command list.
bash
npm install -g @ionic/cli
If upgrading from the legacy ionic package:
bash
npm uninstall -g ionic
npm install -g @ionic/cli
CommandDescriptionionic serveStart a local dev server with live reload.ionic serve --externalServe on all network interfaces (for testing on devices).ionic serve --port=<port>Serve on a custom port (default: 8100).ionic serve --prodServe with production build configuration.ionic buildBuild the web app for production.ionic generateGenerate pages, components, services (framework-dependent).ionic doctor checkCheck the project for common issues.ionic infoPrint system/environment info for bug reports.ionic repairRemove and recreate dependencies and platform files.
ionic serve Options#OptionDescription--sslEnable HTTPS (experimental).--no-livereloadServe without automatic reloading.--no-openDo not open a browser window automatically.--consolelogsPrint app console output in terminal.--browser=<browser>Open in a specific browser (safari, firefox, google chrome).--browseroption=<path>Open a specific URL path (e.g., /#/tab/dash).
For framework-specific CLI options, pass them after --:
bash
ionic serve -- --proxy-config proxy.conf.json
Read references/components-layout.md for the full API reference for layout components.
Ionic uses a 12-column flexbox grid system ( ion-grid, ion-row, ion-col). Columns expand to fill the row evenly unless a size attribute is specified (1-12).
Responsive breakpoints:
BreakpointMin WidthCSS Class Prefixxs0(default)sm576pxsizeSm``md768pxsizeMd``lg992pxsizeLg``xl1200pxsizeXl
Ionic provides responsive CSS utility classes for common styling needs:
.ion-text-center, .ion-text-start, .ion-text-end, .ion-text-wrap, .ion-text-nowrap, .ion-text-uppercase, .ion-text-lowercase, .ion-text-capitalize.ion-padding, .ion-padding-top, .ion-padding-bottom, .ion-padding-start, .ion-padding-end, .ion-padding-vertical, .ion-padding-horizontal, .ion-no-padding.ion-margin, .ion-margin-top, .ion-margin-bottom, .ion-margin-start, .ion-margin-end, .ion-margin-vertical, .ion-margin-horizontal, .ion-no-margin.ion-display-none, .ion-display-block, .ion-display-flex, .ion-display-inline, .ion-display-grid.ion-float-left, .ion-float-right, .ion-float-start, .ion-float-end.ion-justify-content-center, .ion-align-items-center, .ion-flex-row, .ion-flex-column, .ion-flex-wrap, .ion-flex-nowrap.ion-no-borderAll utility classes support responsive breakpoint suffixes: ion-text-{breakpoint}-center (e.g., .ion-text-md-center applies at 768px+).
Ionic provides nine default colors: primary, secondary, tertiary, success, warning, danger, light, medium, dark. Apply via the color attribute on components:
html
<ion-button color="primary">Primary</ion-button>
<ion-button color="danger">Danger</ion-button>
Each color has six CSS custom properties:
--ion-color-{name} — Base color value--ion-color-{name}-rgb — Base color in RGB format--ion-color-{name}-contrast — Text color for readability--ion-color-{name}-contrast-rgb — Contrast color in RGB format--ion-color-{name}-shade — Darker variant (active/pressed states)--ion-color-{name}-tint — Lighter variant (hover states)To customize a color, override all six variables in :root:
css
:root {
--ion-color-primary: #3880ff;
--ion-color-primary-rgb: 56, 128, 255;
--ion-color-primary-contrast: #ffffff;
--ion-color-primary-contrast-rgb: 255, 255, 255;
--ion-color-primary-shade: #3171e0;
--ion-color-primary-tint: #4c8dff;
}
To add a custom color, define the CSS variables and create a class:
css
:root {
--ion-color-favorite: #69bb7b;
--ion-color-favorite-rgb: 105, 187, 123;
--ion-color-favorite-contrast: #ffffff;
--ion-color-favorite-contrast-rgb: 255, 255, 255;
--ion-color-favorite-shade: #5ca56c;
--ion-color-favorite-tint: #78c288;
}
.ion-color-favorite {
--ion-color-base: var(--ion-color-favorite);
--ion-color-base-rgb: var(--ion-color-favorite-rgb);
--ion-color-contrast: var(--ion-color-favorite-contrast);
--ion-color-contrast-rgb: var(--ion-color-favorite-contrast-rgb);
--ion-color-shade: var(--ion-color-favorite-shade);
--ion-color-tint: var(--ion-color-favorite-tint);
}
VariableDescription--ion-background-colorBackground color of the app--ion-text-colorText color of the app--ion-font-familyFont family of the app--ion-statusbar-paddingStatusbar padding top of the app--ion-safe-area-topAdjust safe area inset top--ion-safe-area-rightAdjust safe area inset right--ion-safe-area-bottomAdjust safe area inset bottom--ion-safe-area-leftAdjust safe area inset left--ion-marginDefault margin for margin utility classes--ion-paddingDefault padding for padding utility classes--ion-placeholder-opacityOpacity of placeholder text in inputs
Ionic supports three dark mode approaches:
Automatically applies dark palette based on the user's OS setting:
css
@import '@ionic/angular/css/palettes/dark.system.css';
/* or @ionic/react, @ionic/vue */
Forces dark mode regardless of system settings:
css
@import '@ionic/angular/css/palettes/dark.always.css';
Enables manual dark mode control via a CSS class:
css
@import '@ionic/angular/css/palettes/dark.class.css';
Add .ion-palette-dark to the <html> element to activate:
html
<html class="ion-palette-dark">
Add this meta tag to adjust system UI elements (scrollbars, etc.):
html
<meta name="color-scheme" content="light dark" />
Ionic uses two modes for platform-specific styling:
PlatformDefault ModeStyleiOSiosApple iOS designAndroidmdMaterial DesignOther / WebmdMaterial Design
To preview a specific mode in the browser, add ?ionic:mode=ios or ?ionic:mode=md to the URL:
text
http://localhost:8100/?ionic:mode=ios
Target mode-specific styles in CSS:
css
.ios ion-toolbar {
--background: #f8f8f8;
}
.md ion-toolbar {
--background: #ffffff;
}
The primary development workflow is browser-based:
bash
ionic serve
This starts a development server at http://localhost:8100 with live reload.
Use browser DevTools to simulate mobile devices:
Cmd+Opt+I (Mac) / Ctrl+Shift+I (Windows/Linux), then toggle device toolbarCmd+Opt+R for Responsive Design ModeCmd+Opt+M (Mac) / Ctrl+Shift+M (Windows/Linux)For native functionality that requires a real device:
bash
npx cap run android
npx cap run ios
For live reload on a device:
bash
npx cap run android --livereload --external
npx cap run ios --livereload --external
debugger keyword to set breakpoints in code.?ionic:mode=ios to the URL to preview iOS styles in the browser.ionic info to collect environment info for troubleshooting.Ionic provides a framework-agnostic animation utility built on the Web Animations API. Import:
import { createAnimation } from '@ionic/core';AnimationController from @ionic/angularCreateAnimation component from @ionic/reactimport { createAnimation } from '@ionic/vue';Key methods: addElement(), duration(), easing(), fromTo(), keyframes(), play(), pause(), stop(), onFinish().
Animations support grouping (parent-child), chaining (via play() promises), and integration with gestures.
For performance, prefer animating transform and opacity over height and width.
Ionic provides a framework-agnostic gesture utility. Import:
import { createGesture } from '@ionic/core';GestureController from @ionic/angularimport { createGesture } from '@ionic/react';import { createGesture } from '@ionic/vue';Configuration options: el, gestureName, threshold, direction ( x/ y), maxAngle, gesturePriority, disableScroll, passive.
Callbacks: canStart, onWillStart, onStart, onMove, onEnd, notCaptured.
The GestureDetail object provides startX/ startY, currentX/ currentY, deltaX/ deltaY, and velocityX/ velocityY.
Ionic emits an ionBackButton event when the Android hardware back button is pressed. Handlers are priority-based:
PriorityHandler100Overlays99Menu0Navigation
For Capacitor apps, install @capacitor/app to enable hardware back button support. See the framework-specific skills for implementation patterns.
ionic: command not found: The Ionic CLI is not installed. Run npm install -g @ionic/cli.ionic serve --port=<other-port>.@import '@ionic/angular/css/core.css';. For React/Vue: check the framework-specific import.@ionic/angular, @ionic/react, or @ionic/vue is installed and configured. The <html> element should have an ios or md class..ion-palette-dark is applied to the <html> element.--background, --color) rather than targeting internal elements directly. Check the component reference file for available properties.--external flag with npx cap run.ionViewWillEnter not firing: This lifecycle event only fires with Ionic's routing components ( ion-router-outlet). It does not fire with standard framework routers unless Ionic's routing integration is used.ionic-app-creation — Create a new Ionic app.ionic-angular — Ionic with Angular (framework-specific patterns).ionic-react — Ionic with React (framework-specific patterns).ionic-vue — Ionic with Vue (framework-specific patterns).ionic-app-upgrades — Upgrade Ionic to a newer major version.capacitor-app-development — General Capacitor development.capacitor-plugins — Capacitor plugins installation and configuration.