npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

country-flag-icons

v1.6.4

Published

Vector (*.svg) country flag icons in 3x2 aspect ratio.

Readme

country-flag-icons

npm version npm downloads

Vector country flag icons in 3:2 aspect ratio.

  • Optimized for small size on screen (little detail, minimalism).
  • Small file size (generally 1 KB per flag).
  • Exports a React component for each flag (from /react subpackage).

See the flags

Install

npm install country-flag-icons --save

API

hasFlag(countryCode: string): boolean

Tells whether there's a flag for a given country code.

import { hasFlag } from 'country-flag-icons'

hasFlag('US') === true
hasFlag('ZZ') === false

countries: string[]

The list of supported country codes.

import { countries } from 'country-flag-icons'

countries.includes('US') === true
countries.includes('ZZ') === false

Web

Flags can be linked directly from this library's gitlab pages website, or from a github pages mirror, which seems a tiny bit faster.

<img
  alt="United States"
  src="https://purecatamphetamine.github.io/country-flag-icons/3x2/US.svg"/>

Flags can also be used in the form of CSS classes imported from country-flag-icons/3x2/flags.css where all flag icons are inlined as background-image data URLs. CSS flag icon height can be set via --CountryFlagIcon-height CSS variable.

In that case, the default flag icon height is 1em, and to change it, just set a font-size:

/* Set flag icon height to 24px. */
[class*=' flag:'], [class^='flag:'] {
  font-size: 24px;
}

Unicode

Unicode flag icons are available under the /unicode export.

import getUnicodeFlagIcon from 'country-flag-icons/unicode'

getUnicodeFlagIcon('US') === '🇺🇸'
getUnicodeFlagIcon('ZZ') === '🇿🇿'

Unicode flag icons ("Regional Indicator Symbols") were introduced in 2010 in Unicode version 6.0.

Older operating systems might not support Unicode flags, either rendering "missing" (rectangle) characters (if their system doesn't support country flags), or displaying two-letter country codes instead of emoji flag images. For example, Windows 10 currently (01.01.2020) doesn't support Unicode country flags, and displays two-letter country codes instead of emoji flag images.

React

React components for all flags are available at /react/3x2 export.

import { US } from 'country-flag-icons/react/3x2'

<US title="United States" className="..."/>

Or directly, if your bundler doesn't support tree shaking:

import US from 'country-flag-icons/react/3x2/US'

<US title="United States" className="..."/>

Vue

There's an experimental component for Vue 3.

String

All flags can also be imported as strings:

import { US } from 'country-flag-icons/string/3x2'

console.log(US) // > '<svg xmlns="http://www.w3.org/2000/svg" ...</svg>'

Or directly, if your bundler doesn't support tree shaking:

import US from 'country-flag-icons/string/3x2/US'

console.log(US) // > '<svg xmlns="http://www.w3.org/2000/svg" ...'

Country Code

This library includes the flags for all ISO-3166-1 country codes such as US, CA, etc.

Additionally, this library includes the flags for the following "exceptional reservations" of the ISO-3166-1 standard, which are not official ISO-3166-1 country codes, but still there have been requests to include them:

  • EU — European Union
  • IC — Canary Islands

Additionally, this library includes the flags for the "unofficial" two-letter codes used by libphonenumber-js:

  • AC — Ascension Island
  • TA — Tristan da Cunha
  • XK — Kosovo
    • XK is a "user-assigned" code in the ISO-3166-1 standard meaning that it can be freely assigned to any region by any application or organization for its own purposes.
    • This "user-assigned" code may potentially be changed or removed at any time.
    • The last official ISO-3166-2 "subdivision code" assigned to Kosovo region is RS-KM.
  • XA — Abkhazia
    • XA is a "user-assigned" code in the ISO-3166-1 standard meaning that it can be freely assigned to any region by any application or organization for its own purposes.
    • This "user-assigned" code may potentially be changed or removed at any time.
    • The last official ISO-3166-2 "subdivision code" assigned to Abkhazia region is GE-AB.
  • XO — South Ossetia
    • XO is a "user-assigned" code in the ISO-3166-1 standard meaning that it can be freely assigned to any region by any application or organization for its own purposes.
    • This "user-assigned" code may potentially be changed or removed at any time.
    • South Ossetia region has not ever been assigned any official ISO-3166-2 "subdivision code".
  • XCNorthern Cyprus
    • XC is a "user-assigned" code in the ISO-3166-1 standard meaning that it can be freely assigned to any region by any application or organization for its own purposes.
    • This "user-assigned" code may potentially be changed or removed at any time.
    • Northern Cyprus region has not ever been assigned any official ISO-3166-2 "subdivision code".

Additionally, this library includes the flags for certain official ISO-3166-2 "subdivision codes" because there have been requests to include them:

  • BQ — Caribbean Netherlands
    • BQ-BO — Bonaire
    • BQ-SA — Saba
    • BQ-SE — Sint Eustatius
  • GB — United Kingdom
    • GB-ENG — England
    • GB-NIR — Northern Ireland
    • GB-SCT — Scotland
    • GB-WLS — Wales
  • ES — Spain

GitHub

On March 9th, 2020, GitHub, Inc. silently banned my account (erasing all my repos, issues and comments) without any notice or explanation. Because of that, all source codes had to be promptly moved to GitLab. The GitHub repo is now only used as a backup (you can star the repo there too), and the primary repo is now the GitLab one. Issues can be reported in any repo.

Alternatives

Credits

I used Google image search for flag references, and various country flag packs (including FlagKit / flagpack) for design ideas. Sometimes there was no need to re-draw a flag — usually in cases when a flag is just a set of colored stripes and there already is an SVG version of it somewhere at Wikipedia or some other free flag pack, so in those cases I simply copied those flags (because they look the same in every flag pack).

Some countries officially use their "mother" country flag (those used to be colonies). For example, BV (Bouvet Island) and SJ (Svalbard and Jan Mayen) use the flag of Norway; GP (Guadeloupe) and RE (Réunion) use the flag of France.

CSS flag icons feature has been submitted by @mindplay-dk.