Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Flag Icon Css Laravel Package

components/flag-icon-css

Country flag icons in SVG with ready-to-use CSS/Sass helpers. Import via npm/Yarn or CDN, then add .fi and .fi-xx (ISO 3166-1 alpha-2) classes to render flags, with optional squared variants and configurable Sass builds.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    npm install flag-icons
    

    or via CDN:

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/lipis/flag-icons@7.3.2/css/flag-icons.min.css" />
    
  2. First Use Case: Display a flag for Greece inline with text:

    <span class="fi fi-gr"></span> <!-- Default flag -->
    <span class="fi fi-gr fis"></span> <!-- Squared flag -->
    

Where to Look First


Implementation Patterns

Core Workflows

  1. Basic Flag Display:

    <!-- Default (proportional) -->
    <span class="fi fi-us"></span>
    
    <!-- Squared version -->
    <span class="fi fi-us fis"></span>
    
  2. Dynamic Flag Rendering (Laravel Blade):

    @php
    $countryCode = 'ca'; // Canada
    $isSquared = true;
    @endphp
    
    <span class="fi fi-{{ $countryCode }} {{ $isSquared ? 'fis' : '' }}"></span>
    
  3. SASS Integration (Custom Build):

    @use "node_modules/flag-icons/sass/flag-icons" with (
      $flag-icons-included-countries: ("us", "ca", "jp") // Only include these flags
    );
    

    Compile with npm run dev or laravel-mix.

  4. Flag as Background Image:

    .country-badge {
      background: url('/node_modules/flag-icons/flags/1x1/us.svg') no-repeat center;
      background-size: contain;
    }
    
  5. Accessibility:

    <span class="fi fi-gb" aria-label="United Kingdom"></span>
    

Integration Tips

  • Laravel Mix/Webpack: Import the CSS in resources/js/app.js:

    import 'flag-icons/css/flag-icons.min.css';
    

    Ensure the flags/ directory is copied to public/ via mix.copy().

  • Dynamic Country Codes: Fetch codes from an API (e.g., REST Countries) and map them to flags.

  • Dark Mode: Use SASS variables to override colors:

    @use "node_modules/flag-icons/sass/flag-icons" with (
      $flag-icons-bg: #f0f0f0, // Light background for flags
      $flag-icons-opacity: 0.8
    );
    

Gotchas and Tips

Pitfalls

  1. Missing Flags:

    • If a flag doesn’t render, verify the ISO 3166-1-alpha-2 code (e.g., gb for UK, not uk).
    • Check the demo page for valid codes.
  2. SASS Path Issues:

    • Ensure $flag-icons-path in SASS points to the correct directory (default: node_modules/flag-icons/flags).
    • If using Laravel Mix, run npm run dev after updating SASS variables.
  3. CDN Caching:

    • Hardcash the CDN URL in production to avoid layout shifts:
      <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/lipis/flag-icons@7.3.2/css/flag-icons.min.css" integrity="..." crossorigin="anonymous">
      
  4. File Size:

    • The full CSS (~10KB) includes all flags. Use SASS to exclude unused countries for smaller builds.
  5. SVG Optimization:

    • Flags are SVGs. If using inline SVGs (e.g., <img src="...">), ensure your Laravel asset pipeline handles them (e.g., via mix.copy()).

Debugging

  • Flag Not Loading?

    • Check the browser’s Network tab for 404s on SVG files (e.g., /flags/1x1/us.svg).
    • Verify the flags/ directory is accessible in public/.
  • SASS Errors:

    • Run npm run dev to recompile SASS after changes.
    • Check for typos in country codes (e.g., fi-gr vs. fi-gb).

Extension Points

  1. Custom Flags:

    • Add your own SVGs to the flags/ directory and reference them with fi-custom (requires CSS updates).
  2. Flag Size:

    • Use fi-2x, fi-3x, etc., for larger flags:
      <span class="fi fi-us fi-2x"></span>
      
  3. Flag Animations:

    • Animate flags with CSS:
      .fi.fi-us {
        transition: transform 0.3s;
      }
      .fi.fi-us:hover {
        transform: scale(1.2);
      }
      
  4. Laravel View Composers:

    // app/Providers/AppServiceProvider.php
    View::composer('*', function ($view) {
        $view->with('countryFlags', ['us', 'ca', 'gb']); // Preload common flags
    });
    
  5. Localization:

    • Pair flags with country names using Laravel’s trans():
      <span class="fi fi-fr"></span> {{ trans('countries.fr') }}
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
babenkoivan/elastic-client
innmind/static-analysis
innmind/coding-standard
datacore/hub-sdk
alengo/sulu-http-cache-bundle
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme
agtp/agtp-php
agtp/mod-php
centraldesktop/protobuf-php