Skip to the content

Hata旗

Load a native country or region flag, choose supported framing and keep each drawing’s source, author and licence.

Hata (旗) is Japanese for a flag. About the name

Contents

How-to

Move to hata from another flag set

The hata line that replaces each way of drawing a flag with flag-icons, country-flag-icons, circle-flags, react-world-flags or flagpack-core, and what changes.

Each section starts with a line from that set's own README (linked, read on 2026-11-17) and gives the hata line that does the same job. Install hata first, under its scoped name: npm install @johnmorrisdotca/hata. The comparison says what each set draws and where hata has no equal yet.

Three things are the same for every move. A hata code is the ISO 3166-1 alpha-2 code in either case (gr or GR), or an ISO 3166-2 code for a region (JP-13, DE-BY). A flag is drawn at its own proportions inside a box, never stretched, so a flag-icons fi of 4:3 and a hata flag of the same box differ for Japan, Canada, Switzerland and others: set the width, not both sides. And the licence of each drawing is its own, so read formats, sizes and licences before you ship.

From flag-icons

flag-icons uses classes on an empty span.

<span class="fi fi-gr"></span> <span class="fi fi-gr fis"></span>

In hata the element is the nearest thing. A squared flag is shape="square".

<script type="module" src="https://cdn.jsdelivr.net/npm/@johnmorrisdotca/hata@1/dist/element-define.js"></script>
<hata-flag code="GR" size="32"></hata-flag> <hata-flag code="GR" shape="square" size="32"></hata-flag>

What changes: hata has no CSS classes or sprite yet (MODULES-1426), so a page that styles .fi-gr in a stylesheet needs the element or an <img> from flagUrl instead.

From country-flag-icons

country-flag-icons has a React component, a string and a plain image for each flag.

import { US } from 'country-flag-icons/react/3x2'
import US from 'country-flag-icons/string/3x2/US'
import { Flag } from "@johnmorrisdotca/hata/react";
import us from "@johnmorrisdotca/hata/flags/us";   // the SVG as a string, one module a flag

<Flag code="US" label="United States" size="large" />

For <img src="…/3x2/US.svg">, use flagUrl("US"), which gives a jsDelivr address, or flagUrl("US", { base: "/flags" }) for a copy of dist/svg/ on your own site. Its hasFlag(code) is isFlagCode(code), and its countries list is FLAG_CODES.

What changes: the flags are drawn at their true proportions, not 3:2. Its Unicode emoji output has no equal; the README says why hata does not draw emoji (MODULES-1425).

From circle-flags

circle-flags is an image address and, for React, a separate package.

<img src="https://hatscripts.github.io/circle-flags/flags/br.svg" width="48" />
<hata-flag code="BR" shape="round" size="48"></hata-flag>
import { flag } from "@johnmorrisdotca/hata/load";

const brazil = await flag("BR", { shape: "round", label: "Brazil" });   // an SVG string drawn for the circle

What changes: a round hata flag is drawn again for the circle where a crop would lose a colour (the red bars of Canada's), where a circle-flags drawing is one design for the circle. A circle-flags file for a place hata has no flag for (the README names es-ib, the Balearic Islands) has no equal yet (MODULES-1412).

From react-world-flags

react-world-flags takes a code of two letters, three letters or three digits.

import Flag from 'react-world-flags'

<Flag code="nor" height="16" />
import { Flag } from "@johnmorrisdotca/hata/react";

<Flag code="NO" size={16} />

What changes: hata takes the two-letter code only (MODULES-1425), so convert a three-letter or numeric code first. Its bundle holds every flag and is about 1.3 MB gzipped, according to its README; hata's core is 3.7 kB gzipped with no flag in it, and each flag is a module of its own, loaded when a page asks.

From flagpack-core

flagpack-core says each flag is imported on its own from its flags folder, and that the React, Vue and Svelte packages do that for you.

import { Flag } from "@johnmorrisdotca/hata/react";

<Flag code="GB-SCT" label="Scotland" />

Vue and Svelte are in the framework guide.

What changes: England, Scotland and Wales are GB-ENG, GB-SCT and GB-WLS in both; Northern Ireland has no flag of its own, so hata offers the Union Flag and the former Ulster Banner as named variants and GB-NIR alone gives null, where flagpack-core has GB-NIR. The United Kingdom's own flag is GB in hata.

What none of them give you

The source, author and licence of the flag you drew, from manifest(code). Move that too: it is the reason to leave a set that does not say.

import { manifest } from "@johnmorrisdotca/hata/manifest";

console.log(manifest("NO")?.licence.name, manifest("NO")?.author);
Public domain Original: Fredrik Meltzer Vector: Gutten på Hemsen

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/hata 1.31.0.