Bandeiras dos 26 estados brasileiros, do Distrito Federal e do Brasil.
Nítidas em qualquer tamanho, para React, Vue e React Native.
Português · English
Também existe para outras plataformas: Flutter · Compose Multiplatform · Swift
- 28 bandeiras em 4 estilos:
full(3:2),rounded(3:2 com cantos arredondados),square-roundedecircle. - Um pacote para React, Vue e React Native. Os dados são os mesmos; muda só o adaptador que desenha.
- Zero dependências. Os frameworks são peers opcionais, então instalar isso não traz nada junto.
- Você paga só pelas bandeiras que citar. Uma bandeira dá 2,2 KB comprimidos, e não 40 KB.
- Sem arquivos de imagem: cada bandeira é um caminho vetorial, nítido de 16 px à tela cheia.
- TypeScript, ESM e CommonJS.
npm install brazil-state-flags
Funciona igual com yarn add, pnpm add ou bun add. No React Native você
também precisa de
react-native-svg,
que é quem desenha de verdade.
Escolha o estilo pelo caminho de importação e a bandeira pelo nome.
import { Flag } from 'brazil-state-flags/react'; import { saoPaulo } from 'brazil-state-flags/circle'; import { rioDeJaneiro } from 'brazil-state-flags/full'; <Flag artwork={saoPaulo} size={32} /> <Flag artwork={rioDeJaneiro} width={120} />
<script setup lang="ts"> import { Flag } from 'brazil-state-flags/vue'; import { saoPaulo } from 'brazil-state-flags/circle'; </script> <template> <Flag :artwork="saoPaulo" :size="32" /> </template>
import { Flag } from 'brazil-state-flags/native'; import { saoPaulo } from 'brazil-state-flags/circle'; <Flag artwork={saoPaulo} size={32} />;
Os quatro estilos são brazil-state-flags/full,
brazil-state-flags/rounded, brazil-state-flags/square-rounded e
brazil-state-flags/circle.
size é a altura, e a largura sai da proporção do desenho. É o que faz uma
lista de bandeiras ficar alinhada: o estilo full é 3:2 e os redondos são
quadrados, então igualar a largura deixaria o retangular mais alto que todo o
resto.
import { parana as paranaFull } from 'brazil-state-flags/full'; import { parana as paranaCircle } from 'brazil-state-flags/circle'; <Flag artwork={paranaFull} size={40} /> // 60 x 40 <Flag artwork={paranaCircle} size={40} /> // 40 x 40
width ou height sozinho também respeita a proporção. Os dois juntos
esticam a bandeira, o que quase sempre é engano, mas a escolha é sua.
O adaptador é uma conveniência. Se você desenha de outro jeito, ou usa Svelte, Solid, Angular, Astro ou qualquer outra coisa, os dados bastam:
import { saoPaulo } from 'brazil-state-flags/circle'; saoPaulo.code; // 'SP' saoPaulo.name; // 'São Paulo' saoPaulo.width; // 200 saoPaulo.shapes; // [{ d: 'M0 100C0 155.2...', fill: '#d9251d' }, ...]
Cada forma traz d e um fill ou um stroke. Os caminhos usam só M, L,
C e Z: arcos, curvas quadráticas, coordenadas relativas e transformações
são resolvidos quando os dados são gerados, então nada disso chega no seu
código.
Cada estilo tem 31 desenhos e uns 120 KB de dados. Uma bandeira por exportação é o que faz o empacotador conseguir deixar de fora as que você nunca citou:
| O que você importa | Bundle | Comprimido |
|---|---|---|
| uma bandeira | 5,4 KB | 2,2 KB |
| cinco bandeiras | 12,7 KB | 4,8 KB |
as 31, via byCode |
110,2 KB | 40,3 KB |
| só o adaptador | 1,2 KB | 0,6 KB |
| só a lista de estados | 0,9 KB | 0,3 KB |
Medido com esbuild em modo produção. Um teste do repositório refaz essa conta
a cada execução, porque um import * as flags perdido devolve os 40 KB sem
avisar ninguém.
Formulários de endereço precisam escolher a bandeira a partir de uma string:
import { byCode } from 'brazil-state-flags/circle'; const bandeira = byCode[uf.toUpperCase()];
byCode e all citam todas as bandeiras do estilo, então o empacotador não
consegue remover nenhuma. Para um seletor completo isso vale a pena; para três
bandeiras fixas, importe os nomes direto.
Se você só precisa dos nomes e das siglas, states não traz desenho nenhum:
import { states } from 'brazil-state-flags'; states; // [{ code: 'AC', name: 'Acre' }, ...] ordenado por sigla
Três estados têm dois desenhos no conjunto original. Eles não seguem um eixo único de "detalhado" e "simples", então cada um é exposto pelo que realmente é:
| Padrão | Alternativa | Diferença |
|---|---|---|
paraiba |
paraibaSimplified |
a simplificada não traz a palavra NEGO |
ceara |
cearaSimplified |
a simplificada não traz o brasão |
espiritoSanto |
espiritoSantoSimplified |
a padrão traz o lema TRABALHA E CONFIA |
As alternativas têm code vazio e ficam fora de byCode, porque são um outro
desenho da bandeira e não a bandeira de outro lugar.
<Flag artwork={bahia} title="Bandeira da Bahia" />
Sem title a bandeira é marcada como decorativa, que costuma ser o certo
quando já existe um texto ao lado. Com title ela vira uma imagem com nome,
no React e no Vue por role="img" e no React Native por
accessibilityLabel.
| Requisito | Mínimo |
|---|---|
| Node | 18 |
| React | 18 |
| Vue | 3.5 |
| react-native-svg | 13 |
Os três são peers opcionais: instalar o pacote não traz nenhum deles, e usar o adaptador de React não pede que você tenha Vue.
Node 18 é o mínimo para usar o pacote, e é verificado a cada execução da CI rodando o pacote já construído nessa versão. Para trabalhar no repositório você precisa do Node 20, porque é o mínimo do Vitest.
No React Native, os caminhos de importação dependem do Metro resolver o campo
exports do package.json. Isso é o padrão a partir do React Native 0.79. Em
versões anteriores, ligue unstable_enablePackageExports no metro.config.js.
Os dados em src/data/ são gerados e ficam versionados, então instalar o
pacote não pede Dart nem nada além do npm.
npm test # os testes npm run typecheck # tsc npm run build # dist/ npm run smoke # roda o pacote construído como um app rodaria npm run generate -- <caminho-para-icones-bandeiras-br-uf/dist> npm run check:normalizer npm run check:generated
check:generated compara os dados com o que o gerador produz agora. A
comparação não é byte a byte de propósito: a geometria usa trigonometria, então
uma coordenada exatamente em cima de um limite de arredondamento sai 150.342 num
sistema e 150.343 noutro, de números que diferem em 1e-14. A forma do arquivo
precisa bater exatamente, as cores também, e cada número dentro de um fio de
cabelo.
check:normalizer compara tool/svg_normalizer.dart com as cópias das outras
três bibliotecas quando elas estão clonadas ao lado desta. As quatro desenham
as mesmas bandeiras e precisam produzir a mesma geometria, e uma delas ficar
para trás só apareceria comparando duas capturas de tela.
O overrides do package.json prende o esbuild numa versão sem avisos de
segurança abertos. Ele é ferramenta de build e nunca vai para o pacote
publicado, mas um npm audit limpo é mais fácil de ler que um com exceções.
A arte vem de
icones-bandeiras-br-uf,
de Pierre Lapalu, publicada sob CC0 1.0. Os SVGs são convertidos em TypeScript
por tool/generate_typescript.dart, incluído no repositório.
Flags of the 26 Brazilian states, the Federal District and Brazil. Sharp at any size, for React, Vue and React Native.
Also available for other platforms: Flutter · Compose Multiplatform · Swift
- 28 flags in 4 styles:
full(3:2),rounded(3:2 with rounded corners),square-roundedandcircle. - One package for React, Vue and React Native. The data is the same; only the adapter that draws it changes.
- Zero dependencies. The frameworks are optional peers, so installing this brings nothing along with it.
- You pay for the flags you name. One flag is 2.2 KB compressed, not 40 KB.
- No image files: each flag is vector path data, sharp from 16 px to full screen.
- TypeScript, ESM and CommonJS.
npm install brazil-state-flags
yarn add, pnpm add and bun add work the same way. On React Native you
also need
react-native-svg,
which is what actually draws.
The import path picks the style and the name picks the flag.
// React import { Flag } from 'brazil-state-flags/react'; import { saoPaulo } from 'brazil-state-flags/circle'; <Flag artwork={saoPaulo} size={32} />;
<!-- Vue --> <script setup lang="ts"> import { Flag } from 'brazil-state-flags/vue'; import { saoPaulo } from 'brazil-state-flags/circle'; </script> <template> <Flag :artwork="saoPaulo" :size="32" /> </template>
// React Native import { Flag } from 'brazil-state-flags/native'; import { saoPaulo } from 'brazil-state-flags/circle'; <Flag artwork={saoPaulo} size={32} />;
The four styles are brazil-state-flags/full, brazil-state-flags/rounded,
brazil-state-flags/square-rounded and brazil-state-flags/circle.
size is the height, and the width follows the artwork's proportions. That is
what makes a row of flags line up: the full style is 3:2 and the round ones
are square, so matching widths would leave the rectangular one taller than
everything else.
import { parana as paranaFull } from 'brazil-state-flags/full'; import { parana as paranaCircle } from 'brazil-state-flags/circle'; <Flag artwork={paranaFull} size={40} /> // 60 x 40 <Flag artwork={paranaCircle} size={40} /> // 40 x 40
A width or a height on its own keeps the proportions too. Giving both
stretches the flag, which is nearly always a mistake but is yours to make.
The adapter is a convenience. If you draw some other way, or you are on Svelte, Solid, Angular, Astro or anything else, the data is enough:
import { saoPaulo } from 'brazil-state-flags/circle'; saoPaulo.code; // 'SP' saoPaulo.name; // 'São Paulo' saoPaulo.width; // 200 saoPaulo.shapes; // [{ d: 'M0 100C0 155.2...', fill: '#d9251d' }, ...]
Every shape carries a d and either a fill or a stroke. The paths use only
M, L, C and Z: arcs, quadratic curves, relative coordinates and
transforms are all resolved when the data is generated, so none of them ever
reach your code.
Each style holds 31 drawings and about 120 KB of path data. One export per flag is what lets a bundler leave out the ones you never named:
| What you import | Bundle | Compressed |
|---|---|---|
| one flag | 5.4 KB | 2.2 KB |
| five flags | 12.7 KB | 4.8 KB |
all 31, through byCode |
110.2 KB | 40.3 KB |
| the adapter alone | 1.2 KB | 0.6 KB |
| the state list alone | 0.9 KB | 0.3 KB |
Measured with esbuild in production mode. A test in the repository does the
same arithmetic on every run, because one stray import * as flags hands the
40 KB back without telling anyone.
Address forms have to pick a flag from a string:
import { byCode } from 'brazil-state-flags/circle'; const flag = byCode[uf.toUpperCase()];
byCode and all name every flag in the style, so a bundler cannot drop any
of them. For a full picker that is worth it; for three fixed flags, import the
names directly.
If you only need the names and the codes, states carries no artwork at all:
import { states } from 'brazil-state-flags'; states; // [{ code: 'AC', name: 'Acre' }, ...] ordered by UF code
Three states ship two drawings in the source set. They do not follow a single "detailed versus simple" axis, so each is exposed as what it actually is:
| Default | Alternative | Difference |
|---|---|---|
paraiba |
paraibaSimplified |
the simplified one drops the word NEGO |
ceara |
cearaSimplified |
the simplified one drops the coat of arms |
espiritoSanto |
espiritoSantoSimplified |
the default carries the TRABALHA E CONFIA motto |
The alternatives have an empty code and stay out of byCode, because they
are another drawing of the same flag rather than the flag of somewhere else.
<Flag artwork={bahia} title="Flag of Bahia" />
Without title the flag is marked decorative, which is usually right when the
state's name is already next to it. With title it becomes a named image,
through role="img" on React and Vue and through accessibilityLabel on
React Native.
| Requirement | Minimum |
|---|---|
| Node | 18 |
| React | 18 |
| Vue | 3.5 |
| react-native-svg | 13 |
All three are optional peers: installing the package brings none of them, and using the React adapter does not ask you to have Vue.
Node 18 is the floor for using the package, and CI checks that on every run by running the built package on it. Working on the repository needs Node 20, because that is Vitest's floor.
On React Native, the import paths need Metro to resolve the exports field of
package.json. That is the default from React Native 0.79. On earlier
versions, turn on unstable_enablePackageExports in metro.config.js.
The data in src/data/ is generated and committed, so installing the package
needs no Dart and nothing beyond npm.
npm test # the tests npm run typecheck # tsc npm run build # dist/ npm run smoke # runs the built package the way an app would npm run generate -- <path-to-icones-bandeiras-br-uf/dist> npm run check:normalizer npm run check:generated
check:generated compares the data against what the generator produces now.
It is deliberately not a byte comparison: the geometry is built with
trigonometry, so a coordinate sitting exactly on a rounding boundary comes out
150.342 on one machine and 150.343 on another, from numbers that differ by
1e-14. The shape of the file has to match exactly, so do the colours, and every
number has to match within a hair.
check:normalizer compares tool/svg_normalizer.dart against the copies in
the other three libraries when they are checked out next to this one. All four
draw the same flags and have to produce the same geometry, and one of them
falling behind would only show up by comparing two screenshots.
The overrides block in package.json holds esbuild at a version with no open
advisories. It is a build tool and never reaches the published package, but a
clean npm audit is easier to read than one with exceptions.
The artwork comes from
icones-bandeiras-br-uf
by Pierre Lapalu, published under CC0 1.0. The SVGs are converted into
TypeScript by tool/generate_typescript.dart, included in the repository.

