Environment Badge

Marks the page, tab title and favicon with the environment, so nobody edits production thinking it is staging.

StopsEdited production thinking it was staging

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/environment-badge.json

The files land in your project. They're yours to edit.

Usage

environment-badge-usage.tsx
import { EnvironmentBadge, useEnvironmentGuard } from "@/components/ui/environment-badge"

<EnvironmentBadge env={env} detail="ap-south-1 · orders-db" prefixTitle={markTab} markFavicon={markTab} />

What it catches

  • Working in production by mistake, via page, tab title and favicon marks
  • Environment names like "eu-prod-2", recognised word by word
  • Unknown environments, which are never shown as safe
  • Production-only confirmation through the hook

Props

EnvironmentBadge props
PropTypeDefault
env* (required)

The environment this app is running in. Accepts aliases like "prod", "uat", "local" or "prod-eu-1".

string—
fallback

How to treat a name that matches no known alias. Defaults to staging, so an unknown env is never shown as safe.

Environment"staging"
labels

Display names per environment, e.g. to translate them. The short tags (PROD, STG, DEV) stay as they are.

Partial<Record<Environment, string>>—
envSuffix

Read after the name by screen readers: "Production environment".

string"environment"
unknownMessage

Strip message for a name that matched no alias; the name itself is shown as the label.

string"Unrecognised environment, so treat it as live"
variant

`strip` is a full-width bar for the top of an admin layout, `ribbon` a corner sash, `badge` an inline pill.

"strip" | "ribbon" | "badge""strip"
message

What the environment means, shown in the strip after its name.

string—
detail

Extra detail shown in the strip, e.g. a region or database name. Hidden on small screens.

string—
prefixTitle

Prefix the tab title with the environment, e.g. "[PROD] Orders". Kept when the app changes the title; removed on unmount.

booleanfalse
markFavicon

Paint a colored band onto the favicon so the tab itself shows where you are. Restored on unmount.

booleanfalse

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

Accessibility

  • The environment is written out in text; short codes are aria-hidden
  • The production confirmation is a native <dialog> labelled by its title, with the safe button focused
  • Production uses a hatch pattern as well as colour

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

This is a UX guard rail. Enforce on the server: Separate credentials and permissions per environment on the server; a badge is a reminder, not access control.

  • Only as accurate as the env value you pass
  • Marks the browser UI; it doesn't stop API calls made against production

What it stops

Edited production thinking it was staging

Also known as

environment banner · prod badge · staging · dev · favicon · tab title · admin panel · env indicator

Dependencies

Pairs well with