hampusborgos/country-flags: ISO-coded SVG and PNG flag renders
SVG and PNG renders of all countries' flags.
At a glance
- What is it?
- A repository of SVG flag renders named by ISO 3166 country code, with pre-built PNG exports and an npm package for JavaScript projects. The value is in the naming convention and the accuracy policy, not in tooling.
- Who is it for?
- Adopt it if you need a fixed, ISO-code-named set of flag files to drop into a web or app project, or if you want the svg-country-flags npm package rather than maintaining your own SVG copies. Do not adopt it if you need runtime updates when a country changes its flag, or if you need a maintained API or metadata beyond the code-to-name mapping in countries.json.
- Can I use it commercially?
- Not without permission. GitHub finds no licence file in the repository, and without a licence all rights are reserved by default: you may read the code but not reuse it. Check the README, or ask the authors, before using it.
- Is it still maintained?
- Activity is slowing. The repository last received commits 8 months ago.
- What is it written in?
- Mainly JavaScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 22, 2026, and from our analysis. They are not legal advice.
Star history
- hampusborgos/country-flags3,804 ★ · +15
| Repository | 2026-09-24 | 2026-11-22 |
|---|---|---|
| hampusborgos/country-flags | 3.8k | 3.8k |
15 Stars in the last 59 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
What problem hampusborgos/country-flags solves
Most projects that display flags end up assembling their own folder of images. The files arrive from different sources, at different sizes, with inconsistent names. Then someone needs a flag for a country and has to guess whether the file is called germany.svg, de.svg or DE.svg.
This repository removes that guesswork. Every flag is named by its two-letter ISO 3166 country code, with one documented exception: the constituent countries of Great Britain use six-letter codes such as GB-ENG. Kosovo uses XK, which the README notes is not part of the ISO standard but is in use by several multinational organizations. A countries.json file at the repository root maps codes to country names.
The audience is developers embedding flags in a UI, a report, a spreadsheet export or a document generator. It is not aimed at people who want a flag API with metadata, and it is not a design system. It is a file collection with a naming contract.
How the flag files are organised and rendered
The repository layout is flat and predictable: a svg/ directory holds the source vectors, a scripts/ directory holds the PNG build script, and countries.json sits at the top level next to package.json. The README states the source files were taken from Wikimedia Commons and sometimes contributed back when national legislation describes the flag more precisely.
That sourcing note is the interesting part. The project's stated goal is not visual consistency but legal accuracy: "flags that most closely match what the country or territory's laws and regulations describe the flags as being." In practice this means the SVGs are not normalised to a common aspect ratio or a common viewBox. A flag whose law specifies proportions will carry those proportions. If your layout assumes every flag is a fixed 3:2 rectangle, you will need to handle the outliers yourself.
The PNG exports are pre-rendered at 100px, 250px and 1000px widths, produced from the SVGs by a Node script. There are no other sizes in the repository. Anything else is generated locally.
Installing svg-country-flags and rendering a first flag
There are three ways in, and the README lists all of them. You can download the repository as a zip, clone it, or install it as an npm module. The package name is svg-country-flags, not the repository name, which is an easy mistake to make.
npm install --save svg-country-flagsAfter that, the files are on disk under node_modules. The README does not document a JavaScript import API, so the practical route is to resolve the path to the SVG you want and hand it to your bundler or renderer. The naming rule is the ISO code, so a lookup by country code maps directly to a filename. The README itself points readers at the GitHub Pages viewer for browsing the whole set.
If you would rather not run Node at all, the same files are browsable on the project's GitHub Pages viewer, and the zip download gives you the whole svg/ tree without a package manager.
Generating PNGs at a width the repository does not ship
The pre-rendered PNGs cover 100px, 250px and 1000px. For anything else the README documents a script, and it requires two global tools first.
npm install -g svgexport imagemin-cli
npm run build-pngs -- 1000:The argument syntax is the part people get wrong. The trailing colon means width; the README gives :200 as the form for a height of 200px instead. The script is declared in package.json as node scripts/build-pngs.js, and there is a second script, build-100-250-1000-pngs, that chains the three standard widths in one command.
The README is explicit about why imagemin is in the pipeline: svgexport produces uncompressed PNGs that can be several megabytes each. The manual fallback, for environments where the Node script will not run, is a shell loop over the svg/ directory followed by imagemin and a cleanup of the intermediate files.
for file in *.svg; do svgexport $file "`basename $file svg`png" pad 1000: ; done
imagemin *.png --out-dir=../compressed-pngs/
rm *.pngThat manual route writes into a compressed-pngs/ folder, so the output location differs from the script's.
Where this repository is the wrong tool
The biggest limitation is update latency. Flags change. When a country adopts a new design, this repository only reflects it after someone updates the SVG, and no release process is documented: package.json carries version 1.2.10 and the repository has no published releases. If your application must display a current flag the day a change is gazetted, a static file collection is the wrong dependency. You would need a source that tracks changes and pushes them to you.
The second limitation is metadata. countries.json maps codes to names, and that is the extent of it. There is no capital, no region grouping, no emoji, no historical flag, no subdivision flag beyond the GB-ENG style entries the README mentions. The related search phrases about flags with capitals or flags in order describe a different kind of dataset.
The third is the accuracy policy itself. Chasing legal accuracy means accepting that flags are not uniformly proportioned, which pushes work onto your layout code. A project that only needs a visually consistent grid of rectangles may find that constraint costs more than it is worth.
Alternatives and how they differ
The obvious alternative is to keep using the flag assets you already have from a general icon set, such as the flag icons bundled with many UI libraries. The difference is scope and naming. An icon set gives you flags redrawn to a house style, usually at a fixed aspect ratio, with names chosen by that library. This repository gives you the source renders, unnormalised, named by ISO code. You trade visual uniformity for fidelity and for a naming convention that does not change between libraries.
A second alternative is fetching flags from Wikimedia Commons directly, which is where this project's sources came from. That gives you the widest possible coverage, including historical and proposed flags, but no stable naming contract and no guarantee that a file at a given URL will stay where it is. The repository is essentially a curated, renamed, pre-rendered snapshot of that source, which is exactly what you want if you do not want to do the curation.
Licence and maintenance cost
package.json declares "license": "PD", which is a public domain dedication. The README makes the same point in prose: flags are not under copyright protection since flags are in public domain, though it adds that there may be other restrictions on how a flag can be used. That caveat matters. Public domain status of the artwork does not automatically settle questions about using a national symbol in a commercial context, and the repository does not address those questions. This is a description of what the project states, not legal advice.
The maintenance cost is low but not zero. There is no dependency graph to keep current beyond the two global CLI tools used for PNG generation, and no server component. The cost is in watching for flag changes yourself, since no notification mechanism is described. The last push to the repository was on 2026-03-10.
Editorial conclusion
Adopt it if you need a fixed, ISO-code-named set of flag files to drop into a web or app project, or if you want the svg-country-flags npm package rather than maintaining your own SVG copies. Do not adopt it if you need runtime updates when a country changes its flag, or if you need a maintained API or metadata beyond the code-to-name mapping in countries.json. Before you commit, verify three things: that the licence field in package.json (PD) matches how you intend to use the assets, that the ISO codes you need are present including the GB-ENG style six-letter codes and XK for Kosovo, and that your rendering pipeline handles the SVG files as they ship rather than assuming a normalised viewBox.
Frequently asked questions
How do I add country flags in HTML with hampusborgos/country-flags?
No HTML component is documented. The practical approach is to reference the SVG files by their ISO 3166 country code filename, either from the cloned svg/ directory or from the installed svg-country-flags package.
How many country flags are there currently in hampusborgos/country-flags?
The README does not state a count. It says the repository contains renders of all the world's flags, named by two-letter ISO 3166 country code, with six-letter codes for the constituent countries of Great Britain and XK for Kosovo.
Can I use hampusborgos/country-flags in Excel?
No spreadsheet integration is documented. The PNG exports at 100px, 250px and 1000px widths are the files you would insert manually, since spreadsheets do not render SVG.
Can I use hampusborgos/country-flags in Google Sheets?
No Google Sheets integration is documented. As with Excel, the pre-rendered PNG exports are what a spreadsheet can display; the SVG sources are not rendered by the application.
Can I use hampusborgos/country-flags in Power BI?
The repository documents no Power BI integration. The PNG exports at 100px, 250px and 1000px widths are the assets you would import as images.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/hampusborgos-country-flags)Star history chart for your README
[](https://hysenlabs.com/projects/hampusborgos-country-flags)Was this useful?