A beautiful svg + png + sass + css collection of 264 flags by Yefferson Marín.
- Every ISO 3166-1 alpha-2 country, plus England, Scotland, Wales, Northern Ireland, Shetland, California and 8 extras (continents, EU, World, Pride).
- Optimized
svg, andpngat1x,2xand3x. - Plain CSS, or Sass with variables and mixins to ship only the flags you need.
flags.jsonwith every code and name, for selects and pickers.
CDN (no install):
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/yammadev/flag-icons@3.1.0/css/flag-icons.min.css">npm:
npm install @yammadev/flag-iconsimport '@yammadev/flag-icons/css/flag-icons.min.css';Manual: download the repository and copy the css and svg folders side by side into your project (the CSS loads the images from ../svg/).
<link rel="stylesheet" href="/css/flag-icons.min.css">Add the class flag-icons followed by the flag code. Works on any element (<i>, <span>, <div>, …):
<i class="flag-icons CO"></i> <!-- 4:3 rectangle -->
<i class="flag-icons square CO"></i> <!-- square box, flag keeps its proportions -->
<i class="flag-icons square fill CO"></i> <!-- square box, flag fills it (crops the sides) -->Codes are uppercase, as listed in the Reference.
Flags are 1em high, so they follow the font-size of their parent:
<i class="flag-icons CO" style="font-size: 2rem"></i>Or set the size directly:
.flag-icons { height: 2em; width: 2.6667em; line-height: 2em; }
.flag-icons.square { width: 2em; }Configure the library with the module system:
@use "@yammadev/flag-icons/sass/flag-icons" with (
$flag-icons-path: "/assets/flags", // where the .svg files are served from
$flag-icons-flags: ("CO", "MX", "ES"), // only generate these classes
$flag-icons-height: 1.25em
);Use a flag on your own selectors without the generated classes:
@use "@yammadev/flag-icons/sass/mixins" as fi;
.lang-es::before { @include fi.flag("ES"); } // box + image
.country[data-code="MX"] { @include fi.image("MX"); } // image only| Variable | Default | Description |
|---|---|---|
$flag-icons-path |
"../svg" |
Folder of the .svg files, relative to the compiled CSS. |
$flag-icons-flags |
all | List of codes that get a class. |
$flag-icons-class |
"flag-icons" |
Base class name. |
$flag-icons-height |
1em |
Default height. |
$flag-icons-ratio |
4/3 |
Width / height of the rectangle. |
The classic @import keeps working (variables first, then the import):
$flag-icons-path: "/assets/flags";
@import "flag-icons/sass/flag-icons";flags.json (the package main) lists every flag:
import flags from '@yammadev/flag-icons' with { type: 'json' };
// { extras: [{ code: 'CAF', name: 'Africa' }, …], countries: [{ code: 'AD', name: 'Andorra' }, …] }Nothing to change: same files, same paths and same classes. The CSS now also works on elements other than <i> and <span>, and it no longer uses an element in the selector, so your own .flag-icons { … } rules override it without !important.
Requires Node.js 18 or newer.
npm install
npm run build # flags.json -> Sass lists + README reference, then Sass -> css/
npm test # checks files, classes, Sass APIs and backwards compatibilityTo add a flag:
- Put
CODE.svginsvg/(21×15, same style as the others). - Add
{ "code": "CODE", "name": "…" }toflags.json. - Run
npm run assets(optimizes the svg and renders the missing png) andnpm run build.
Issues and pull requests are more than welcome.
Flag artwork is based on madebybowtie/FlagKit (MIT). AQ and EH were drawn for this project in the same style.
Released under the MIT license. See the changelog for release notes.
Looking for brand icons? Check out yammadev/brand-icons.
8 flags:
| Flag | Code | Name |
|---|---|---|
CAF |
Africa | |
CAS |
Asia | |
CNA |
North America | |
COC |
Oceania | |
CSA |
South America | |
EU |
European Union | |
WW |
World | |
LGBT |
Pride |
256 flags: