Country Flag Icon Libraries Comparison
country-flag-icons vs react-country-flag vs react-flags
1 Year
country-flag-iconsreact-country-flagreact-flagsSimilar Packages:
What's Country Flag Icon Libraries?

Country flag icon libraries are essential tools for web developers looking to incorporate national flags into their applications. These libraries provide a variety of flag icons that can be easily integrated into web projects, enhancing user experience and providing visual context for internationalization. They often come with different styles, formats, and customization options, allowing developers to choose the best fit for their design needs. Using these libraries can significantly reduce the time and effort required to source and implement flag icons, ensuring consistency and quality across applications.

NPM Package Downloads Trend
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
country-flag-icons811,544-6.51 MB-5 months agoMIT
react-country-flag172,577-22.9 kB-2 years agoMIT
react-flags10,2458626.7 MB9-MIT
Feature Comparison: country-flag-icons vs react-country-flag vs react-flags

Icon Format

  • country-flag-icons:

    This package provides SVG icons for all flags, ensuring high quality and scalability without loss of resolution. SVG format is lightweight and can be styled with CSS, making it versatile for modern web applications.

  • react-country-flag:

    It primarily uses SVG format for flags, allowing for easy scaling and customization. The package also supports CSS styling, enabling developers to adapt the flags to fit their application's design seamlessly.

  • react-flags:

    This package offers both SVG and PNG formats for flags, giving developers flexibility in choosing the best format for their needs. The inclusion of multiple formats ensures compatibility across different browsers and devices.

Customization Options

  • country-flag-icons:

    Customization is primarily done through CSS, allowing developers to easily change the size, color, and other styles of the flags. This makes it easy to integrate the flags into various design systems without additional overhead.

  • react-country-flag:

    This package allows for props-based customization, where developers can specify the size and other attributes directly in the React component. This makes it straightforward to adjust flags dynamically based on application state or user preferences.

  • react-flags:

    Offers extensive customization options, including the ability to create flag dropdowns and integrate with form elements. The package is designed for interactive use, making it suitable for applications that require user input.

Ease of Use

  • country-flag-icons:

    This package is straightforward to use; simply import the SVG files and use them as needed. It requires minimal setup, making it ideal for quick implementations without complex configurations.

  • react-country-flag:

    Designed specifically for React, this package provides a simple API for rendering flags as components. It is easy to integrate into existing React applications, reducing the learning curve for developers familiar with React.

  • react-flags:

    While slightly more complex due to its additional features, this package is still user-friendly. It provides a clear API for integrating flags into forms and dropdowns, making it suitable for developers who need interactivity.

Community and Support

  • country-flag-icons:

    This package has a growing community and is regularly updated, but it may not have extensive documentation or support compared to larger libraries. It is suitable for developers comfortable with self-guided implementation.

  • react-country-flag:

    This package has a dedicated user base within the React community, with good documentation and examples available. It is actively maintained, ensuring compatibility with the latest React versions and best practices.

  • react-flags:

    This package boasts a strong community and comprehensive documentation, making it easier for developers to find support and examples. Its popularity in projects requiring flag selection enhances its reliability and longevity.

Performance

  • country-flag-icons:

    Being an SVG-based library, it offers excellent performance with minimal impact on load times. SVG files are lightweight and can be cached effectively, ensuring fast rendering in web applications.

  • react-country-flag:

    This package is optimized for performance within React applications, leveraging React's rendering lifecycle to minimize unnecessary re-renders. It is suitable for applications where performance is a critical factor.

  • react-flags:

    While it provides more features, this package may have a slightly larger footprint due to its interactive components. However, it is designed to be efficient, and performance can be optimized through careful implementation.

How to Choose: country-flag-icons vs react-country-flag vs react-flags
  • country-flag-icons:

    Choose this package if you need a comprehensive set of SVG flag icons that are lightweight and easy to use. It is ideal for projects that require a large number of flags without the overhead of additional features.

  • react-country-flag:

    Opt for this package if you are using React and want a simple, customizable component for displaying flags. It offers easy integration with React applications and supports various flag formats and sizes, making it suitable for dynamic applications.

  • react-flags:

    Select this package if you require a more feature-rich solution that includes flag selection and additional functionalities like localization support. It is perfect for applications that need user interaction with flags, such as dropdowns or selection menus.

README for country-flag-icons

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.
  • Comes with React components for all flags (exported from /react subpackage).

See 3:2 flags

Install

npm install country-flag-icons --save

API

hasFlag(country: string): boolean

Tells whether there's a flag for a country.

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

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

countries: string[]

The list of supported countries.

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="http://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.

What if my project doesn't use CSS variables?

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" ...'

Criteria for inclusion

See Criteria for inclusion section on the ISO-3166-1 standard Wikipedia page.

This library includes the flags for all countries, territories, or areas of geographical interest that have an officially assigned code in the ISO-3166-1 standard.

Additionally, this library includes a European Union (EU) flag because it's part of the "exceptional reservations" of the ISO-3166-1 standard and there have been requests to do so.

So, the full list is all of the 249 officially assigned ISO-3166-1 codes, plus:

  • AC — Ascension Island. Exceptional reservation. Has it's own phone numbering plan.
  • TA — Tristan da Cunha. Exceptional reservation. Has it's own phone numbering plan.
  • IC — Canary Islands. Exceptional reservation. Doesn't have its own phone numbering plan.
  • EU — European Union. Exceptional reservation. Doesn't have its own phone numbering plan.
  • XK — Kosovo. Disputed territory. Not an officially assigned code. Has it's own phone numbering plan.

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.