Getting Started with Ionic and Capacitor
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
Ionic Framework is an open-source UI toolkit for building mobile and desktop-class apps with web technologies — HTML, CSS and TypeScript — and Capacitor is the native runtime that packages that web app as a real iOS
and Android application. Together they let one web codebase ship to the App Store, Google Play and the browser.
This section is written against Ionic Framework 9.0.10 (@ionic/angular and @ionic/core), Ionic CLI
7.2.1, Capacitor 8.6.0 (@capacitor/core and @capacitor/cli) and Angular 22.2.5 using standalone
components and signals. Every page builds one running app, Trailhead, a hiking journal with a trail list and
search, a trail detail page, favourites, a "log a hike" form with a camera photo and a GPS position, and an
offline cache of trails. The app talks to a REST API at https://api.example.com/v1, its application id is
com.example.trailhead and its package name is trailhead.
This page covers the mental model and the toolchain. The next pages go deeper: Architecture and the Native Bridge, Components and Theming, Navigation and Routing and Capacitor Plugins. The wider family of cross-platform approaches is introduced on Hybrid Apps, and the editor and device tooling on Hybrid Apps: IDEs & Tools.
Ionic and Capacitor: Two Projects, One Workflow
The two names are often used as one, but they are separate layers with separate jobs.
| Project | Responsibility |
|---|---|
Ionic Framework |
A library of UI web components ( |
Capacitor |
A native runtime and CLI. It creates and maintains real |
Ionic CLI |
A convenience command ( |
Capacitor does not require Ionic: it can wrap any web app, built with any framework or none. Ionic does not require Capacitor either: an Ionic app is a normal web app that runs in a browser or as a progressive web app. Using both is the common path because the UI toolkit looks native and the runtime gives the app real device access. Capacitor is the spiritual successor of Cordova and keeps a compatibility layer for Cordova plugins; see Architecture and the Native Bridge.
Where This Approach Fits
An Ionic and Capacitor app is a WebView hybrid: the user interface is web content rendered by the platform’s web engine inside a native shell. That is a different trade-off from the alternatives.
| Ionic + Capacitor | React Native | Flutter and Dart | Progressive web app | |
|---|---|---|---|---|
UI rendering |
Web content in a WebView (WKWebView, Android System WebView) |
Real native views driven by JavaScript |
Own rendering engine draws every pixel |
Browser tab or installed web window |
Native API access |
Plugins, plus custom Kotlin and Swift |
Native modules |
Platform channels and packages |
Only what browsers expose |
Choose Ionic and Capacitor when the team already knows web technologies, when most screens are forms, lists and content rather than heavy custom graphics, and when one codebase must serve the browser, iOS and Android. It is a weaker fit for graphics-intensive games, or for apps that need a continuous 60 or 120 frames per second custom animation layer, where a game engine or a natively rendered UI is a better choice. The framework-neutral background on the web side is on Web Development, and this section assumes Angular as explained in the Angular reference.
Prerequisites
Capacitor 8 sets the toolchain floor for the native projects. Install these before creating a project.
| Tool | Requirement |
|---|---|
Node.js |
22 or newer, with npm. |
Xcode (macOS only) |
26.0 or newer, for iOS builds. The iOS deployment target is 15.0. |
Android Studio |
Otter 2025.2.1 or newer. Android uses |
Package manager for iOS |
New iOS projects use Swift Package Manager by default. CocoaPods remains available with
|
A device or simulator |
An iOS Simulator, an Android Virtual Device, or a physical phone with developer mode enabled. |
Verify the basics with node --version, npm --version, xcodebuild -version (macOS only) and adb version.
Installing the Ionic CLI
The Ionic CLI is installed globally from npm:
npm install -g @ionic/cli
ionic --version # 7.2.1 at the time of writing
ionic info # prints versions of Ionic, Capacitor, Angular, Node and the native toolchains
ionic info is the first command to run when something does not work, and the output is the first thing to
attach to a bug report. Every command also works without a global install through npx @ionic/cli.
Creating the Trailhead Project
ionic start generates a project from a template. The Angular standalone variant uses no NgModule at all:
ionic start trailhead tabs --type=angular --capacitor
cd trailhead
The first argument is the project name, the second a starter template (blank, list, sidemenu or tabs),
and --type=angular selects the Angular integration. Angular projects are generated with standalone components
by default, which is the style used throughout this section. Run ionic start with no arguments to answer the
prompts interactively, which also asks for the framework and the template.
Ionic supports three official front-end frameworks. The Capacitor and native steps below are identical for all of them; only the UI code and the router differ.
-
Angular —
@ionic/angular, with standalone imports from@ionic/angular/standaloneand the Angular Router. -
React —
@ionic/reactand@ionic/react-router, with React Router. -
Vue —
@ionic/vueand@ionic/vue-router, with Vue Router.
Choose the framework the team already knows. This section uses Angular, so the Angular reference pages on routing and the rest of the Angular section apply directly.
After creation, set the application identity in capacitor.config.ts. This is the id that becomes the Android
applicationId and the iOS bundle identifier, so choose it before the first native build:
import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
appId: 'com.example.trailhead',
appName: 'trailhead',
webDir: 'www',
};
export default config;
webDir must match the folder the web build writes to. Current Angular builds write to dist/<project>/browser,
so the starter’s Angular configuration and webDir have to agree; check the value generated for your template
rather than assuming it.
The Generated Project Layout
trailhead/
src/
app/ # Angular standalone components, routes and services
assets/ # static files copied into the build
theme/variables.scss # Ionic CSS variables for theming
global.scss # global styles and Ionic CSS imports
index.html
main.ts # bootstrapApplication entry point
angular.json # Angular build configuration, defines the output folder
capacitor.config.ts # appId, appName, webDir and plugin settings
ionic.config.json # Ionic CLI project settings
package.json
www/ or dist/ # web build output that Capacitor copies into the native apps
android/ # native Android Studio project (after npx cap add android)
ios/ # native Xcode project (after npx cap add ios)
The android/ and ios/ folders are real native projects and, unlike a throwaway build artifact, they are
committed to source control. They hold native settings such as permissions, icons, signing configuration and
any custom Kotlin or Swift code. The web build output folder is generated and ignored by git. The reasoning is
explained on Architecture and the Native Bridge.
Running in the Browser with ionic serve
Most development happens in the browser, because the web dev server rebuilds in a fraction of a second:
ionic serve
This starts the Angular dev server and opens http://localhost:8100. Browser developer tools work as usual, and
the device-toolbar mode shows how iOS and Material Design styling differ. Plugins that need hardware fall back to
web implementations or a clear error: the Camera plugin shows a file picker, Geolocation uses the browser’s
position API, and a plugin with no web implementation throws when called.
Adding the Native Platforms
Build the web app once, then add the platforms. The ionic cap prefix runs the Capacitor CLI with the Ionic
build step available:
ionic build # builds the web app into webDir
ionic cap add android # creates android/
ionic cap add ios # creates ios/ (Swift Package Manager by default)
ionic cap sync # copies web assets and updates native dependencies
cap sync is the command used most often after the first run. It does two things: copy the contents of
webDir into the native projects, and update the native projects so installed Capacitor plugins are linked.
Run it after every web build that should reach a device, and always after installing or removing a plugin.
The related commands are npx cap copy (assets and config only), npx cap update (native dependencies only),
npx cap open android|ios (open the native IDE) and npx cap doctor (check the installation).
Running on a Device or Emulator
ionic cap run builds, syncs and launches in one step:
ionic cap run android
ionic cap run ios
ionic cap run android --list # list available devices and emulators
With no target the command prompts for one. The first run compiles the full native project and can take a few
minutes; later runs reuse Gradle and Xcode caches. Open the native IDE with npx cap open whenever a native
debugger, a signing setting or a Gradle sync is needed.
Live reload on a device
Rebuilding the native app for every CSS tweak is slow. Live reload points the WebView at the dev server running on the development machine instead of the bundled assets:
ionic cap run android -l --external
ionic cap run ios -l --external
-l enables live reload and --external binds the dev server to a network address so the phone can reach it.
The phone and computer must be on the same network. Saving a file rebuilds the web app and the WebView reloads.
Live reload is for development only: it sets a server URL in the generated native configuration, and a release
build must come from a normal ionic build followed by cap sync. Native changes — a new plugin, a changed
permission — still require a rebuild.
A First Trailhead Page
The home page of the generated Angular project is a standalone component. Replace it with a small Trailhead hello
page to confirm that the toolchain, the Ionic components and the native shell all work. Ionic components are
imported one by one from @ionic/angular/standalone and listed in the component’s imports:
// src/app/home/home.page.ts
import { Component, signal } from '@angular/core';
import {
IonButton,
IonContent,
IonHeader,
IonTitle,
IonToolbar,
} from '@ionic/angular/standalone';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
imports: [IonHeader, IonToolbar, IonTitle, IonContent, IonButton],
})
export class HomePage {
protected readonly hikes = signal(0);
protected logHike(): void {
this.hikes.update((count) => count + 1);
}
}
<!-- src/app/home/home.page.html -->
<ion-header>
<ion-toolbar>
<ion-title>Trailhead</ion-title>
</ion-toolbar>
</ion-header>
<ion-content class="ion-padding">
<h1>Hello, hiker</h1>
<p>Your hiking journal, on every screen.</p>
<ion-button (click)="logHike()">Hikes logged: {{ hikes() }}</ion-button>
</ion-content>
Run ionic serve and the page appears in the browser. Run ionic cap run android -l --external and the same page
appears on the device, rendered in Material Design mode, with the hike counter updating as the button is tapped.
That one codebase now runs in the browser, on iOS and on Android.
What Comes Next
Continue with Architecture and the Native Bridge, then build real screens with Components and Theming and Navigation and Routing. The later pages cover Data, Storage and Networking, Platform Integration, Testing and Building and Releasing, and Ionic Cheat Sheet collects the commands in one place.