JavaScript plugin example
Large flags
You can resize the flags with the --iti-flag-width CSS variable (height scales automatically), but the sprite is rasterised at a fixed size (20x15px, or 40x30px retina), so scaling up past the default looks soft. For crisp larger flags you need to rebuild the sprite yourself:
- Follow the Contributing guidelines to download the project and get it building (
npm run build) without errors. - In
scripts/generate-sprite.js, update theTARGET_HEIGHTvalue — for the demo below we use 18 (so the retina sprite is 36). Whatever height you choose, it must be a multiple of 3 so that the corresponding width is a whole number (flags have a 4:3 aspect ratio). - Run
npm run build:imgto generate the new flag images and the updated CSS needed to use them. - Open
demo.htmlto check the larger flags render correctly.
You may then want to override some of the CSS variables/styles from src/css/intlTelInput.css in your own CSS to accommodate the larger flag images — see the overrides used in this demo.
When you're happy, copy the built flag images and CSS file into your own project, and load the standard plugin script as usual.
Demo
Html
<label for="phone">Phone number</label>
<input id="phone" type="tel">
JavaScript
geoIpLookup here uses ipapi's limited free tier — for production, pick a paid plan, another provider, or roll your own.import intlTelInput from "intl-tel-input";
const input = document.querySelector("#phone");
intlTelInput(input, {
initialCountry: "auto",
separateDialCode: true,
strictMode: true,
strictRejectAnimation: true,
geoIpLookup: (success, failure) => {
fetch("https://ipapi.co/json")
.then(res => res.json())
.then(data => success(data.country_code))
.catch(() => failure());
},
loadUtils: () => import("intl-tel-input/utils"),
});