Easy Steps to Integrate Country Flag Icons in Angular, Vue, and React

Easiest bootstrap approach to show country flags by using ISO country codes within 5 minutes.2 min


-2
-2 points
Adding country flag icons easy guide
Adding country flag icons easy guide using svgs

TL;DR – Learn how to integrate country flag icons to your Angular, Vue, or React applications with this easy step-by-step guide.

In this article, I will show you how you can Integrate Country Flag Icons using the CSS approach to your Angular, Vue, or React applications. You just need to pass on the respective ISO country code in the CSS class as it has embedded images. Follow the below-given steps to add country icons to your web application.

You can see the live demo here.

Where can you use country icons?

You can use country flag icons for various purposes! for example, to show…

  • The user country, show where he belongs to!
  • Phone/Contact dropdowns
  • Show country icon beside the IP address
  • While capturing user address information
  • Show user profile with their country
  • Multilingual language applications switch/Translating languages

Cover Image credits: Country flags image via Wikimedia Commons CC0


Basic Requirements

  1. Node and NPM manager
  2. Angular CLI
  3. Typescript
  4. VSCode Editor/Your favorite IDE
  5. flag-icon-css npm package (Third-party library)

Steps to incorporate country flag to your application

Step 1: Install third-party library to your angular project

You need to hit the below command to your angular project root directory.

npm install flag-icon-css

Step 2: Set path of flag-icon-css to your angular.json > CSS section

Under styles array, you can mention the flag-icon.min.css file as shown below. Then restart your angular project.

...
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
...
"styles": [
...
"src/assets/font-awesome/css/font-awesome.min.css",
              "node_modules/flag-icon-css/css/flag-icon.min.css"
],
...

Alternatively, you can put your package build into your assets folder in this manner. You need to add a link tag to your index.html, or angular.json > styles array to reflect the changes.

...
-flag-icon-css
|- assets
|- css
|- flag-icon.css
|- flag-icon.min.css
|- flags
|- 1x1
|- 4x3
...

Here you will get a collection of all country flags in SVG file format compatible with CSS, which will be definitely easy for integration.

Step 3: Implement CSS class to your HTML component file

Open your app.component.ts file where you want to put country flag icons and add the following code as given below.

India 

Please make sure that the value of the ISO country code must be in lower case. For your angular application if you have country codes in UPPERCASE, So use the following line.

India 

In such way, you can implement the CSS classes to show the country flags within 5 minutes for sure.

Code explanation:

As you can see in the above code, the main thing is CSS class flag-icon-xx , where xx is the universal ISO country code in lower case.

This library also provides rectangle and square versions of each country flag. You can make your flag look like a square by using class flag-icon-squared .

Isn’t it so simple?

Output:

Wrapping up...

Hope you find the article more helpful for you, instead of saving and storing all country flags to a physical location or on a Database, use this approach, it is a more convenient and effective way!

What do you learn from this article?

  • Add country flags in your application within 5 minutes.
  • Where and How can you utilize such an amazing feature.
  • Country flag customization and their usage
  • List of countries and their ISO Codes (Which are in use globally for all countries)

All ISO Country Codes

Hope you like my work. You can see the live demo here.

You can also support my work with a donation — If you want to donate me however much you can afford, it means and helps more than you can imagine. You can give tips too using Buy me a coffee. The donation amount will help me to run the website, and server, So I can bring up innovative, knowledgeable things as always.

References:

  1. Node JS & Npm Manager 
  2. Angular CLI
  3. npm/flag-icon-css (Third-party library)
  4. Stackblitz — to prepare the demo (bootstrap country flags)

adsense


Discover more from 9Mood

Subscribe to get the latest posts sent to your email.


Like it? Share with your friends!

-2
-2 points

What's Your Reaction?

Lol Lol
0
Lol
WTF WTF
0
WTF
Cute Cute
0
Cute
Love Love
0
Love
Vomit Vomit
0
Vomit
Cry Cry
0
Cry
Wow Wow
0
Wow
Fail Fail
0
Fail
Angry Angry
0
Angry
Rakshit Shah

Legend

Hey Moodies, Kem chho ? - Majama? (Yeah, You guessed Right! I am from Gujarat, India) 25, Computer Engineer, Foodie, Gamer, Coder and may be a Traveller . > If I can’t, who else will? < You can reach out me by “Rakshitshah94” on 9MOodQuoraMediumGithubInstagramsnapchattwitter, Even you can also google it to see me. I am everywhere, But I am not God. Feel free to text me.

0 Comments

Leave a Reply

Choose A Format
Story
Formatted Text with Embeds and Visuals
List
The Classic Internet Listicles
Ranked List
Upvote or downvote to decide the best list item
Open List
Submit your own item and vote up for the best submission
Countdown
The Classic Internet Countdowns
Meme
Upload your own images to make custom memes
Poll
Voting to make decisions or determine opinions
Trivia quiz
Series of questions with right and wrong answers that intends to check knowledge
Personality quiz
Series of questions that intends to reveal something about the personality
is avocado good for breakfast? Sustainability Tips for Living Green Daily Photos Taken At Right Moment