Country Flag API
The Country Flag API provides SVG flag images for any country, territory, or area of special interest (over 250 supported). The small file sizes are perfect for displaying flag icons on your website or populating a dropdown menu.
Available endpoints:
- /v1/countryflag - Get a country's flag as an SVG image in base64 format
- /v1/allcountryflags - Get flag images for all countries
For geographic, demographic and economic statistics on countries, check out the Country API instead.
From 4,004 users
Applications using this API
API Status
API Response Times
Average | P50 | P75 | P90 | P95 |
|---|---|---|---|---|
| 327ms | 365ms | 369ms | 554ms | 1201ms |
Similar APIs
Didn't find what you were looking for? Suggest an improvement
/v1/countryflag GET
https://api.api-ninjas.com/v1/countryflag
Get a country's flag as an SVG image in base64 format. Both 1:1 and 4:3 aspect ratios are supported and returned in the response.
Parameters
countryrequired2-letter ISO-3166 alpha-2 country code (e.g.
US,CA,FR). For countries in the United Kingdom, useGBfor Great Britain,GB-ENGfor England,GB-SCTfor Scotland,GB-WLSfor Wales,GB-NIRfor Northern Ireland.
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Response
A JSON object with the following fields or an error if the request is unsuccessful.
country2-letter ISO-3166 alpha-2 country code.
square_image_urlURL to the square (1:1) flag image in SVG format.
rectangle_image_urlURL to the rectangle (4:3) flag image in SVG format.
Sample Request Live Demo!
Try our APIs in the API playground
Sign up for a free API key to get started — no credit card required.
https://api.api-ninjas.com/v1/countryflag?country=USHeaders
X-Api-KeyLog in or sign up to get your API KeySample Response
Code Examples
1
2
curl -X GET "https://api.api-ninjas.com/v1/countryflag?country=United%20States" \
-H "X-Api-Key: YOUR_API_KEY"If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.
/v1/allcountryflags GETPremium Only
https://api.api-ninjas.com/v1/allcountryflags
Get flag images for all countries. Returns an list of countries and their flag URLs.
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Response
A JSON array of objects, each containing the following fields, or an error if the request is unsuccessful.
country2-letter ISO-3166 alpha-2 country code.
square_image_urlURL to the square (1:1) flag image in SVG format.
rectangle_image_urlURL to the rectangle (4:3) flag image in SVG format.
Sample Request
https://api.api-ninjas.com/v1/allcountryflagsSample Response
Frequently Asked Questions
Can I use the Country Flag API for commercial purposes?
Yes, but you must have a premium subscription. Commercial use of the Country Flag API is not permitted on the free tier. See our pricing page to choose a plan that fits your needs.How do I get an API key and start using the Country Flag API?
Sign up for a free account to instantly get your API key, then pass it in theX-Api-Keyheader on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.What happens if I exceed my quota for the month?
Your API requests will simply be denied once you hit your monthly quota — you will never be charged more than the plan you signed up for. To increase your quota, you can upgrade your plan any time on our pricing page.What happens if a request to the Country Flag API fails?
The API responds with a standard HTTP status code and a JSON error message describing the problem. See our error codes reference for the full list of codes and how to resolve each one, or contact support if you need help.How do I get the flag for a specific country?
Send a GET request to/v1/countryflagwith the requiredcountryparameter set to a 2-letter ISO-3166 alpha-2 country code such asUS,CA, orFR. For the United Kingdom you can also use sub-codes likeGB-ENGfor England,GB-SCTfor Scotland,GB-WLSfor Wales, andGB-NIRfor Northern Ireland. See the full API list for related endpoints.What does the Country Flag API response include?
Each response returns thecountrycode along withsquare_image_url(the 1:1 aspect ratio flag) andrectangle_image_url(the 4:3 aspect ratio flag), both pointing to SVG images. If a request is unsuccessful you will receive an error instead.How can I retrieve flags for all countries at once?
Use the premium-only/v1/allcountryflagsendpoint, which returns a JSON array of objects each containingcountry,square_image_url, andrectangle_image_urlfor every supported country. This endpoint requires a paid plan, which you can review on the pricing page.What are some use cases for the Country Flag API?
Because the SVG flags have small file sizes, they are ideal for displaying flag icons on your website or populating a country dropdown menu, and they cover over 250 countries, territories, and areas of special interest. For geographic, demographic, and economic statistics on countries, pair it with the Country API.