digitlimit/flag is a simple Laravel package that provides Blade and Livewire components for displaying SVG country flags in 1x1 (square) or 4x3 (rectangular) aspect ratios.
It comes bundled with a collection of country flag SVGs and makes rendering them as easy as using a Blade component.
Require the package using Composer:
composer require digitlimit/flagNo need to publish anything — the package auto-discovers and registers itself.
The package provides Blade components for every country using ISO 3166-1 alpha-2 codes.
<x-flag::1x1.us />
<x-flag::4x3.us />You can apply custom classes to style the flags:
<x-flag::1x1.us class="w-6 h-auto rounded-full" />
<x-flag::4x3.us class="w-6 h-auto rounded-full" />1x1: Square flags 4x3: Traditional rectangular flags
<div class="flex space-x-2 items-center">
<x-flag::1x1.ng class="w-6 h-6 rounded-full" />
<span>Nigeria</span>
</div>
<div class="flex space-x-2 items-center">
<x-flag::4x3.gb class="w-10 h-auto rounded" />
<span>United Kingdom</span>
</div>All ISO 3166-1 alpha-2 country codes are supported (e.g., us, ng, gb, fr, de, etc.).
The flag assets are stored in:
resources/flags/1x1/
resources/flags/4x3/Refer to this Wikipedia page for a full list of valid codes.
If you want to customize or reference the SVG files directly:
php artisan vendor:publish --tag=flag-assetsThe files will be published to your public/vendor/flag directory.
Q: What if a flag doesn’t show up?
Make sure: You’re using a valid ISO alpha-2 country code. The country code is lowercase (e.g., ng, us, de, not NG or Us).
Q: Can I use this in Livewire components? Yes! Blade components work seamlessly in Livewire views.
Q: Will this work with Tailwind CSS? Absolutely. Pass any Tailwind or custom class names via the class attribute.
To run the tests:
composer testOr with Pest:
./vendor/bin/pestContributions are welcome! Please fork this repository and submit a pull request:
- Fork the repo Create your feature branch (git checkout -b feature/your-feature)
- Commit your changes
- Push to the branch
- Create a new Pull Request
This package is open-sourced software licensed under the MIT license.