country-flag-icons vs react-country-flag vs react-flags
Country Flag Icons in Web Development Comparison
1 Year
country-flag-iconsreact-country-flagreact-flagsSimilar Packages:
What's Country Flag Icons in Web Development?

Country flag icon libraries provide developers with a collection of vector or raster images representing the flags of different countries. These icons are commonly used in web applications, forms, and user interfaces to visually represent countries, especially in contexts like internationalization, location selection, or cultural representation. They can be implemented as image assets, SVGs, or icon fonts, and are often designed to be easily scalable and customizable to fit various design needs. Examples include country-flag-icons, which offers a comprehensive set of SVG flags, react-country-flag, a React component library for displaying flags, and react-flags, which provides a customizable flag component for React applications.

NPM Package Downloads Trend
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
country-flag-icons825,309-6.51 MB-15 days agoMIT
react-country-flag179,563-22.9 kB-2 years agoMIT
react-flags9,2378626.7 MB9-MIT
Feature Comparison: country-flag-icons vs react-country-flag vs react-flags

Flag Collection

  • country-flag-icons:

    country-flag-icons offers a vast collection of SVG flags for over 250 countries, territories, and regions. The flags are designed to be simple and recognizable, making them suitable for various applications, from websites to mobile apps.

  • react-country-flag:

    react-country-flag provides flags for all countries recognized by the ISO 3166-1 standard. The library focuses on providing high-quality SVG flags that are optimized for web use, ensuring fast loading times and crisp visuals.

  • react-flags:

    react-flags features a comprehensive set of flags for countries around the world, along with additional data such as country codes and names. This package is designed to be flexible, allowing developers to easily customize the flag display and access country-related information.

Customization

  • country-flag-icons:

    country-flag-icons allows for basic customization, such as changing the size and color of the flags using CSS. However, since the flags are provided as SVGs, developers can also edit the SVG files directly for more advanced customization.

  • react-country-flag:

    react-country-flag offers more extensive customization options, including the ability to set the flag size, rotate flags, and apply custom CSS classes. The component-based nature of the library makes it easy to integrate with React’s styling capabilities.

  • react-flags:

    react-flags is highly customizable, allowing developers to modify the flag display, add tooltips, and style the component using CSS. The package also supports passing additional props to enhance functionality and appearance, making it versatile for different design requirements.

Ease of Integration

  • country-flag-icons:

    country-flag-icons can be easily integrated into any web project by importing the SVG files or using them as CSS background images. The library does not require any special setup, making it straightforward to use in both static and dynamic applications.

  • react-country-flag:

    react-country-flag is designed specifically for React applications, providing a simple API for integrating country flags as components. The library’s documentation includes clear examples, making it easy for developers to implement it quickly.

  • react-flags:

    react-flags also targets React developers, offering a well-documented component that can be easily integrated into projects. Its flexibility and customization options are highlighted in the documentation, allowing for quick implementation and adaptation.

Performance

  • country-flag-icons:

    country-flag-icons is lightweight and optimized for performance, with SVG files that load quickly and consume minimal bandwidth. The library’s simplicity ensures that it does not add significant overhead to web applications, making it ideal for performance-sensitive projects.

  • react-country-flag:

    react-country-flag is efficient in terms of performance, especially when displaying a limited number of flags. The use of SVGs ensures that flags render quickly, and the component is designed to minimize re-renders, making it suitable for dynamic applications.

  • react-flags:

    react-flags is designed to be performant, but the level of customization and additional features may introduce some overhead. However, the impact on performance is generally minimal, and the package is suitable for most applications that require flag display with added functionality.

Code Example

  • country-flag-icons:

    Example of using country-flag-icons in HTML:

    <link rel="stylesheet" href="https://unpkg.com/country-flag-icons@1.0.0/css/flag-icons.min.css">
    
    <div>
      <span class="flag-icons flag-icon-us" title="United States"></span>
      <span class="flag-icons flag-icon-ca" title="Canada"></span>
      <span class="flag-icons flag-icon-gb" title="United Kingdom"></span>
    </div>
    
  • react-country-flag:

    Example of using react-country-flag in a React component:

    import React from 'react';
    import CountryFlag from 'react-country-flag';
    
    const FlagComponent = () => {
      return (
        <div>
          <CountryFlag countryCode="US" svg style={{ width: '50px', height: '50px' }} />
          <CountryFlag countryCode="CA" svg style={{ width: '50px', height: '50px' }} />
          <CountryFlag countryCode="GB" svg style={{ width: '50px', height: '50px' }} />
        </div>
      );
    };
    
    export default FlagComponent;
    
  • react-flags:

    Example of using react-flags in a React component:

    import React from 'react';
    import { Flag } from 'react-flags';
    
    const FlagComponent = () => {
      return (
        <div>
          <Flag country="US" size="32" />
          <Flag country="CA" size="32" />
          <Flag country="GB" size="32" />
        </div>
      );
    };
    
    export default FlagComponent;
    
How to Choose: country-flag-icons vs react-country-flag vs react-flags
  • country-flag-icons:

    Choose country-flag-icons if you need a simple, lightweight solution with a comprehensive collection of SVG flags. It’s ideal for projects where you want to include flags without the overhead of a complex library.

  • react-country-flag:

    Select react-country-flag if you are building a React application and need a straightforward way to display country flags with customizable styles. This package is great for projects that require React components and want to easily style flags using CSS.

  • react-flags:

    Opt for react-flags if you need a highly customizable React component for displaying flags, along with additional features like country codes and names. This package is suitable for applications that require more flexibility and customization in how flags are displayed.

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.