Vector country flag icons in 3:2 aspect ratio.
1 KB per flag)./react subpackage).The .svg files could be found in /3x2/ subfolder of the npm package.
If you're a javascript developer:
npm install country-flag-icons --save
cd ./node_modules/country-flag-icons/3x2
If you are not a javascript developer, you could download a .zip archive with all flags, or browse the /3x2/ subfolder online for individual .svg files.
Those're the only valid options to get the .svg files. Don't download the .svg files from any other source. For example, don't download them from the github repository or the gitlab repository because the .svg files are not "minified" there.
After obtaining the .svg files, you could include them in your apps or in your design mock-ups, etc. For web usage, if you'd prefer to not go through the hassle of hosting the .svg files yourself, consider using the github mirror or the gitlab mirror.
hasFlag(countryCode: string): booleanTells 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
One could either manually host the .svg files or use the existing github mirror or gitlab mirror.
<img
alt="United States"
src="https://purecatamphetamine.github.io/country-flag-icons/3x2/US.svg"/>
Flags could 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" and the flag icon height could 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;
}
React components for all flags are available in the /react/3x2 subpackage.
import { US } from 'country-flag-icons/react/3x2'
<US title="United States" className="..."/>
Or they could be imported individually, if your bundler doesn't support "tree shaking":
import US from 'country-flag-icons/react/3x2/US'
<US title="United States" className="..."/>
There's an experimental component for Vue 3.
The SVG code of all flags is available in the /string/3x2 subpackage:
import { US } from 'country-flag-icons/string/3x2'
console.log(US) // > '<svg xmlns="http://www.w3.org/2000/svg" ...</svg>'
Or each flag could be imported individually, 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" ...'
Unicode flag icons are available in the /unicode subpackage.
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.
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 UnionIC β Canary IslandsAdditionally, this library includes the flags for the "unofficial" two-letter codes used by libphonenumber-js:
AC β Ascension Island
AC is an "exceptional reservation" of the ISO-3166-1 standard.SH-AC.TA β Tristan da Cunha
TA is an "exceptional reservation" of the ISO-3166-1 standard.SH-TA.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.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.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.XC β Northern 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.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 β BonaireBQ-SA β SabaBQ-SE β Sint EustatiusGB β United Kingdom
GB-ENG β EnglandGB-NIR β Northern IrelandGB-SCT β ScotlandGB-WLS β WalesES β Spain
ES-CT β CataloniaOn 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.
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.