---
title: "Country Flag"
description: "Shows the flag of a country from its two-letter code, as a rectangle, a circle, or a square. An unknown code shows a globe, and a badge can mark the pick."
url: https://gelatinui.com/components/country-flag
markdown_url: https://gelatinui.com/components/country-flag.md
access: free
install: "npx shadcn@latest add @gelatin-ui/country-flag"
registry_item: https://gelatinui.com/r/country-flag.json
version: "2026-11-09"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Country Flag

> Shows the flag of a country from its two-letter code, as a rectangle, a circle, or a square. An unknown code shows a globe, and a badge can mark the pick.

Page: https://gelatinui.com/components/country-flag

## When to use it

Best for: A country flag next to a country, a language, a currency, or a phone number.

- Pass the ISO 3166-1 alpha-2 code as `code` (`"DE"`, any case).
- Use `variant="circle"` in pickers and cards, and the 3:2 `rectangle` in text, tables, and fields.
- Add `named` when the flag stands alone, so it says the country name.
- Put a `CountryFlagBadge` inside to mark the selected country.

## When not to use it

- For a picture of a person or a workspace, use [Avatar](https://gelatinui.com/components/avatar.md).
- To pick a country, use the flags inside a [Combobox](https://gelatinui.com/components/combobox.md).

## Notes for agents

- The flags load once per page in their own chunk (47 KB gzip). The box keeps its size while they load.
- An empty code, a value that is not a code, or a code with no flag shows a globe.
- A subdivision works with `-` or `_` (`GB-SCT`).
- Next to a written country name, leave `named` off: the flag is then decorative.

## Anatomy

```text
CountryFlag
└─ CountryFlagBadge (0..n)
```

## API reference

### CountryFlag

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `size` | `"default" \| "lg" \| "sm" \| "xl" \| "xs"` | "default" |  |
| `variant` | `"circle" \| "rectangle" \| "square"` | "rectangle" |  |
| `code` | `string \| null` |  | ISO 3166-1 alpha-2 ("DE", any case), or a subdivision ("GB-ENG"). Unknown: a globe. |
| `named` | `boolean` | false | Name the flag with the country name in `locale` ("Germany"): an image with that name. Default `false`: the flag is decorative, for a flag next to a written name. An `aria-label` wins. |
| `locale` | `string` |  | The language of the name (`Intl.DisplayNames`). Default: the `DisplayLocaleProvider` locale. |
| `pop` | `boolean` | false | Pop the art in when `code` changes: scale 0.9 to 1 and a fade on the popup clock. |

### CountryFlagBadge

No props of its own: `className`, `children`, and every other prop go to the element it renders.

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| CountryFlag | `country-flag` | `data-loading`, `data-pop` | `--radius` | `motion-timing` |
| CountryFlagBadge | `country-flag-badge` | `data-loading`, `data-pop` | `--radius` | `motion-timing` |

## Usage

Pass a country code. Put a `CountryFlagBadge` inside the flag of the selected choice, so the check sits on the flag.

The sample also uses `choice-card`, `radio-group`, which this add does not write. One command adds them with this item:

```bash
npx shadcn@latest add @gelatin-ui/country-flag @gelatin-ui/choice-card @gelatin-ui/radio-group
```

```tsx title="site-language.tsx"
import { useState } from "react";

import { ChoiceCard, ChoiceCardList, ChoiceCardTitle } from "@/components/ui/choice-card";
import { CountryFlag, CountryFlagBadge } from "@/components/ui/country-flag";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";

const LANGUAGES = [
  { value: "en-US", code: "US", name: "English" },
  { value: "de-DE", code: "DE", name: "Deutsch" },
  { value: "ja-JP", code: "JP", name: "日本語" },
];

export function SiteLanguage() {
  const [language, setLanguage] = useState("de-DE");
  return (
    <RadioGroup aria-label="Site language" value={language} onValueChange={setLanguage}>
      <ChoiceCardList className="grid grid-cols-3 gap-2">
        {LANGUAGES.map((item) => {
          return (
            <ChoiceCard key={item.value} lang={item.value}>
              <RadioGroupItem value={item.value} className="sr-only absolute" />
              <CountryFlag code={item.code} variant="circle" size="lg">
                {item.value === language ? <CountryFlagBadge /> : null}
              </CountryFlag>
              <ChoiceCardTitle>{item.name}</ChoiceCardTitle>
            </ChoiceCard>
          );
        })}
      </ChoiceCardList>
    </RadioGroup>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui/country-flag
```

It adds 9 registry items: 8 files, 1501 lines, and the npm packages `@phosphor-icons/react`, `country-flag-icons`, `tailwind-merge`, `tailwind-variants`.

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Avatar](https://gelatinui.com/components/avatar.md)
- [Combobox](https://gelatinui.com/components/combobox.md)
- [Phone Display](https://gelatinui.com/components/phone-display.md)

## Accessibility

With `named`, the flag is an image named with the country name in the page language.

With no `named`, the flag is decorative, for a flag next to a written name.

The badge is decorative: the control around it says it is selected.

## Motion

| Part | Motion |
| --- | --- |
| Change | popup · with `pop`, a new flag scales from 0.9 to 1 and fades in |
