Ionic App Development
General Ionic Framework development — core concepts, component reference, CLI usage, layout, theming, utilities, development workflow, and troubleshooting.
Prerequisites
- Node.js (latest LTS) installed.
- Ionic CLI installed globally (
npm install -g @ionic/cli). - An existing Ionic project. For creating a new Ionic app, use the
ionic-app-creationskill.
Agent Behavior
- Auto-detect the framework. Check
package.jsonfor@ionic/angular,@ionic/react, or@ionic/vueto determine the framework in use. Adapt code examples accordingly. - Route to reference files. This skill is an overview that routes agents to specific reference files for detailed component APIs and topic-specific guidance.
- Do not duplicate framework-specific skills. For Angular, React, or Vue specific patterns, refer to the respective framework skill.
Core Concepts
How Ionic Works
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).
- Components are custom HTML elements (Web Components) prefixed with
ion-(e.g.,<ion-button>,<ion-content>). - Platform modes: Ionic renders components differently based on the platform. iOS devices use the
iosmode; Android and all other platforms use themd(Material Design) mode. The<html>element receives a class (iosormd) that enables platform-specific styles. - Capacitor integration: Ionic apps use Capacitor to access native device features. Ionic handles the UI; Capacitor handles native APIs. See the
capacitor-app-developmentskill for Capacitor-specific guidance.
Page Lifecycle
Ionic provides lifecycle events on top of the framework's own lifecycle hooks. These fire when a page is navigated to or from:
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.
Component Reference
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.
Ionic CLI
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.
Installation
If upgrading from the legacy ionic package:
Key Commands
ionic serve Options
For framework-specific CLI options, pass them after --:
Layout
Read references/components-layout.md for the full API reference for layout components.
Grid System
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:
CSS Utility Classes
Ionic provides responsive CSS utility classes for common styling needs:
- Text:
.ion-text-center,.ion-text-start,.ion-text-end,.ion-text-wrap,.ion-text-nowrap,.ion-text-uppercase,.ion-text-lowercase,.ion-text-capitalize - Padding:
.ion-padding,.ion-padding-top,.ion-padding-bottom,.ion-padding-start,.ion-padding-end,.ion-padding-vertical,.ion-padding-horizontal,.ion-no-padding - Margin:
.ion-margin,.ion-margin-top,.ion-margin-bottom,.ion-margin-start,.ion-margin-end,.ion-margin-vertical,.ion-margin-horizontal,.ion-no-margin - Display:
.ion-display-none,.ion-display-block,.ion-display-flex,.ion-display-inline,.ion-display-grid - Float:
.ion-float-left,.ion-float-right,.ion-float-start,.ion-float-end - Flex:
.ion-justify-content-center,.ion-align-items-center,.ion-flex-row,.ion-flex-column,.ion-flex-wrap,.ion-flex-nowrap - Border:
.ion-no-border
All utility classes support responsive breakpoint suffixes: ion-text-{breakpoint}-center (e.g., .ion-text-md-center applies at 768px+).
Theming
Colors
Ionic provides nine default colors: primary, secondary, tertiary, success, warning, danger, light, medium, dark. Apply via the color attribute on components:
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:
To add a custom color, define the CSS variables and create a class:
Global CSS Variables
Dark Mode
Ionic supports three dark mode approaches:
1. System Preference (Default)
Automatically applies dark palette based on the user's OS setting:
2. Always Dark
Forces dark mode regardless of system settings:
3. CSS Class Toggle
Enables manual dark mode control via a CSS class:
Add .ion-palette-dark to the <html> element to activate:
Add this meta tag to adjust system UI elements (scrollbars, etc.):
Platform Styles
Ionic uses two modes for platform-specific styling:
To preview a specific mode in the browser, add ?ionic:mode=ios or ?ionic:mode=md to the URL:
Target mode-specific styles in CSS:
Developing
Previewing in the Browser
The primary development workflow is browser-based:
This starts a development server at http://localhost:8100 with live reload.
Use browser DevTools to simulate mobile devices:
- Chrome:
Cmd+Opt+I(Mac) /Ctrl+Shift+I(Windows/Linux), then toggle device toolbar - Safari:
Cmd+Opt+Rfor Responsive Design Mode - Firefox:
Cmd+Opt+M(Mac) /Ctrl+Shift+M(Windows/Linux)
Testing on Devices
For native functionality that requires a real device:
For live reload on a device:
Debugging Tips
- Use the
debuggerkeyword to set breakpoints in code. - Add
?ionic:mode=iosto the URL to preview iOS styles in the browser. - Use
ionic infoto collect environment info for troubleshooting.
Utilities
Animations
Ionic provides a framework-agnostic animation utility built on the Web Animations API. Import:
- JavaScript/TypeScript:
import { createAnimation } from '@ionic/core'; - Angular: Inject
AnimationControllerfrom@ionic/angular - React: Use
CreateAnimationcomponent from@ionic/react - Vue:
import { 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.
Gestures
Ionic provides a framework-agnostic gesture utility. Import:
- JavaScript/TypeScript:
import { createGesture } from '@ionic/core'; - Angular: Inject
GestureControllerfrom@ionic/angular - React:
import { createGesture } from '@ionic/react'; - Vue:
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.
Hardware Back Button (Android)
Ionic emits an ionBackButton event when the Android hardware back button is pressed. Handlers are priority-based:
For Capacitor apps, install @capacitor/app to enable hardware back button support. See the framework-specific skills for implementation patterns.
Error Handling
ionic: command not found: The Ionic CLI is not installed. Runnpm install -g @ionic/cli.- Port 8100 in use: Another process is using the default port. Run
ionic serve --port=<other-port>. - Components not rendering: Verify the Ionic CSS files are imported in the global stylesheet. For Angular:
@import '@ionic/angular/css/core.css';. For React/Vue: check the framework-specific import. - Platform styles not applied: Ensure
@ionic/angular,@ionic/react, or@ionic/vueis installed and configured. The<html>element should have aniosormdclass. - Dark mode not working: Verify the correct dark palette CSS import is present. For the class method, ensure
.ion-palette-darkis applied to the<html>element. - CSS custom properties not applying: Ionic components use Shadow DOM. Use the component's documented CSS custom properties (e.g.,
--background,--color) rather than targeting internal elements directly. Check the component reference file for available properties. - Live reload not working on device: Ensure the device and development machine are on the same network. Use the
--externalflag withnpx cap run. ionViewWillEnternot 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.
Related Skills
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.ionic-framework-mcp— Connect an MCP client to the current Ionic Framework documentation.


