Concept Explanation
The service worker gives your site powers. The manifest gives it an identity.
It is a single JSON file answering the questions a phone asks before it is willing to put your site on the home screen: What is your name? What icon should I draw? What colour is your title bar? When someone taps the icon, which URL opens, and should it open in a browser or in its own window?
Without it, your site is a bookmark. With it, your site is an app the operating system is willing to treat like any other.
Syntax or Core Structure
manifest.webmanifest
{
"name": "Recipe Keeper",
"short_name": "Recipes",
"description": "Save and cook your favourite recipes offline.",
"start_url": "/?source=pwa",
"scope": "/",
"display": "standalone",
"orientation": "portrait",
"background_color": "#ffffff",
"theme_color": "#7c3aed",
"icons": [
{ "src": "/icon-192.png", "sizes": "192x192", "type": "image/png" },
{ "src": "/icon-512.png", "sizes": "512x512", "type": "image/png" },
{ "src": "/icon-mask.png", "sizes": "512x512", "type": "image/png",
"purpose": "maskable" }
],
"shortcuts": [
{ "name": "Add recipe", "url": "/new", "icons": [
{ "src": "/add-96.png", "sizes": "96x96" } ] }
]
}
Linking it
<link rel="manifest" href="/manifest.webmanifest" />
<meta name="theme-color" content="#7c3aed" />
Key Features
| Field | What it controls |
|---|---|
name / short_name | Install dialog title / home-screen label (keep under ~12 chars) |
start_url | The page that opens on launch. Add a query param to measure PWA traffic |
scope | Which URLs stay inside the app window; anything outside opens a browser |
display | standalone (no browser UI), fullscreen, minimal-ui, or browser |
theme_color | Title bar and Android task-switcher colour |
background_color | The splash screen colour shown before your CSS loads |
purpose: "maskable" | Lets Android crop the icon to its own shape without white borders |
shortcuts | Long-press menu actions, like "Add recipe" |
Real World Example
Why installed apps look broken on Android without a maskable icon. Android crops home-screen icons into a circle or squircle. Feed it a normal square icon and it either letterboxes it inside a white blob or slices the corners off your logo. The fix is a second icon with 20% padding around the artwork and "purpose": "maskable", so the system has room to crop. This single field is the difference between an icon that looks first-party and one that looks like a shortcut someone hacked together.
Common Mistakes
- Only shipping one icon size. Chrome wants 192 and 512 before it will offer installation.
- A
start_urloutsidescope. The app launches straight into a browser tab, defeating the point. - Serving the manifest with the wrong content type. It should be
application/manifest+json; some hosts need explicit configuration. - A
short_namethat is too long. The launcher truncates it and your app is called "Recipe Kee…". - Forgetting
theme_coloras a meta tag too. The manifest value applies to the installed app; the meta tag applies while browsing. - Assuming a manifest alone makes it installable. You still need HTTPS and a service worker with a fetch handler.
Best Practices
- Add
?source=pwatostart_urlso analytics can separate installed sessions from browser ones. - Match
background_colorto your app's actual first-paint background, otherwise the splash screen flashes. - Use
beforeinstallpromptto show your own install button at a sensible moment instead of relying on the browser's. - Validate with Lighthouse and with the Application panel's Manifest view on a real device.
Practice Exercises
- The ID Card: Write a complete manifest for a project of yours, including a maskable icon, and confirm Lighthouse reports it as installable.
- The Scope Test: Set
scopeto/app/, then navigate to/aboutfrom inside the installed app and observe what happens to the window. - The Custom Prompt: Capture
beforeinstallprompt, stash the event, and trigger it from your own "Install" button after the user completes one action.