A lightweight React component library for displaying country flags. Easily render flags of any country using their ISO 3166-1 alpha-2 country codes.
Install the package using npm:
npm install react-country-icons
Or using yarn:
yarn add react-country-icons
Import the Flag
component and use it in your React application:
import React from 'react'
import Flag from 'react-country-icons'
const App: React.FC = () => {
return (
<div>
<Flag size={32} country="DE"/> {/* German flag */}
<Flag size={48} country="US"/> {/* US flag */}
<Flag size={24} country="FR"/> {/* French flag */}
<Flag size={32} square country="TR"/> {/* Turkish flag in square form */}
</div>
)
}
export default App
Prop | Type | Description | Example |
---|---|---|---|
size |
number | Height of the flag in pixels. | 32 |
country |
string | ISO 3166-1 alpha-2 country code. | "DE" |
square |
boolean | Forms icon into square shape | true |
The package supports all ISO 3166-1 alpha-2 country codes. Here are some examples:
-
DE
- Germany -
US
- United States -
FR
- France -
GB
- United Kingdom -
JP
- Japan
For a full list of country codes, refer to the ISO 3166-1 alpha-2 standard.
This project is licensed under the MIT License.
-
Flag images sourced from Wikipedia.
-
Built with React and TypeScript.
npm: melihfirat
github: firatmelih