Guide to using Tailwind CSS in Capacitor mobile apps. Covers mobile-first design, touch targets, safe areas, dark mode, and performance optimization. Use this skill when users want to style Capacitor apps with Tailwind.
npx playbooks add skill cap-go/capacitor-skills --skill tailwind-capacitor
TRIGGER when:
tailwind.config.js edits have no effect (v4 is CSS-first)Do not use:
konsta-ui--ion-* variables: ionic-designsafe-area-handlingcapacitor-keyboardframework-to-capacitortailwindcss 4.x is latest (4.3.x); 3.4.x on v3-lts.tailwind.config.js is not read unless you add @config "./tailwind.config.js";.@property, color-mix(), cascade layers, oklch).Decision: if the iOS deployment target (or real user base) includes iOS < 16.4, ask the user: stay on Tailwind 3.4, or raise the minimum OS. Do not silently ship v4.
Use the selected project and its installed dependencies. Package installation and migration tools execute code; limit them to the requested setup or upgrade, preserve the lockfile and existing changes, and review generated edits before running changed build scripts.
npm ls tailwindcss, tailwind.config., postcss.config., bundler config, main CSS file, ios/App/App.xcodeproj IPHONEOS_DEPLOYMENT_TARGET, presence of Ionic or Konsta.Only load a reference when its topic is in play.
npm i tailwindcss @tailwindcss/vite
// vite.config.ts
import { defineConfig } from 'vite';
import tailwindcss from '@tailwindcss/vite';
export default defineConfig({ plugins: [tailwindcss() /* + framework plugin */] });
/* src/styles.css */
@import "tailwindcss";
@custom-variant dark (&:where(.dark, .dark *));
@custom-variant ios (&:where(.plt-ios, .plt-ios *));
@custom-variant android (&:where(.plt-android, .plt-android *));
@theme {
--color-brand: oklch(0.55 0.2 265);
--font-sans: system-ui, -apple-system, "Roboto", sans-serif;
}
@utility pt-safe { padding-top: env(safe-area-inset-top); }
@utility pb-safe { padding-bottom: env(safe-area-inset-bottom); }
@utility px-safe { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
Other toolchains: PostCSS (Angular, webpack, Next) -> npm i tailwindcss @tailwindcss/postcss and postcss.config.mjs { plugins: { "@tailwindcss/postcss": {} } }; standalone -> @tailwindcss/cli. Angular CLI 17+ reads .postcssrc.json.
// main.ts: platform class for ios:/android: variants
import { Capacitor } from '@capacitor/core';
document.documentElement.classList.add(`plt-${Capacitor.getPlatform()}`); // plt-ios | plt-android | plt-web
Add viewport-fit=cover to the viewport meta or the safe-area utilities resolve to 0.
.gitignore). Classes in node_modules or outside the project root need @source "../path";. Dynamic class names (` bg-${color}-500 `) are never generated; map to full class strings.hover: only applies on devices with (hover: hover), so sticky hover on touch is solved by default. Use active: for press feedback.currentColor, ring is 1px, shadow-sm/shadow and rounded-sm/rounded scales shifted, outline-none -> outline-hidden. The upgrade tool renames most; review visually.@layer theme, base, components, utilities; @import "tailwindcss/theme.css" layer(theme); @import "tailwindcss/utilities.css" layer(utilities);) or load Ionic CSS after Tailwind.konsta/<fw>/theme.css; follow konsta-ui instead of duplicating setup.100vh for full-screen layouts; use h-dvh (v4 has dvh/svh/lvh utilities) or a flex shell.env() as 0; Capacitor 8 SystemBars injects --safe-area-inset-*. For Android robustness, use @utility pt-safe { padding-top: var(--safe-area-inset-top, env(safe-area-inset-top)); } (see safe-area-handling).npm run build succeeds; built CSS contains your utilities: grep -c "pt-safe" dist/assets/*.css.npx cap sync and run on: oldest supported iOS version (check colors, gradients, shadows render), current iPhone, Android 15/16.ios:/android: variants by inspecting <html class>.grep -rn "@tailwind base\|@tailwind components\|@tailwind utilities\|require('tailwindcss')" src postcss.config.* 2>/dev/null returns nothing.| Error / symptom | Cause | Fix |
|-----------------|-------|-----|
| [postcss] It looks like you're trying to use tailwindcss directly as a PostCSS plugin. The PostCSS plugin has moved to a separate package | v3-style PostCSS config with v4 | Use @tailwindcss/postcss (or @tailwindcss/vite) |
| No styles at all | Missing @import "tailwindcss" or bundler plugin | Add both |
| Cannot apply unknown utility class in @apply | Custom class not defined via @utility, or CSS module / Vue <style> without theme reference | Define with @utility; add @reference "../styles.css"; in the scoped style |
| tailwind.config.js theme changes ignored | v4 does not auto-load JS config | Move to @theme, or add @config |
| Transparent/missing colors on some iPhones | iOS < 16.4 lacks features v4 uses | Raise min iOS or stay on 3.4 |
| dark: follows OS, ignores toggle | Default dark variant is media-based | Add @custom-variant dark (&:where(.dark, .dark *)); |
| Upgrade tool fails: requires Node | @tailwindcss/upgrade needs Node 20+ | Upgrade Node (Capacitor 9 needs 24+ anyway) |
Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.