### Development Server Output Example
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/build-and-utilities.md
An example of the output generated when the development server starts. It includes server version, settings, and logs for incoming requests.
```log
Starting up http-server, serving ./
Hit CTRL-C to stop the server
http-server version: 14.1.1
http-server settings:
CORS: disabled
Cache: 3600 seconds
Connection Timeout: 120 seconds
HTTP port: 8000
Press CTRL+C to stop the server
[YYYY-MM-DD HH:MM:SS] "GET /" "Mozilla/5.0..."
[YYYY-MM-DD HH:MM:SS] "GET /css/flag-icons.min.css" "Mozilla/5.0..."
```
--------------------------------
### Installation Box Styling
Source: https://github.com/lipis/flag-icons/blob/main/index.html
Styles the installation box, which displays installation commands. It uses a semi-transparent background, rounded corners, and flexbox for layout. Includes styling for code display and tab buttons.
```css
/* Installation box */
.install-box {
background-color: rgba(0, 0, 0, 0.2);
border-radius: var(--border-radius);
padding: 0.75rem 1rem;
display: flex;
align-items: center;
justify-content: space-between;
max-width: 500px;
margin: 1.5rem auto;
font-family: "SF Mono", "Fira Mono", "Courier New", Courier, monospace;
position: relative;
overflow: hidden;
}
.install-box code {
overflow-x: auto;
white-space: nowrap;
font-size: 0.9rem;
color: white;
}
.install-tabs {
display: flex;
justify-content: center;
margin-bottom: 0.5rem;
}
.install-tab {
background: rgba(255, 255, 255, 0.1);
border: none;
color: white;
padding: 0.4rem 1rem;
font-size: 0.8rem;
cursor: pointer;
transition: var(--transition);
}
.install-tab:first-child {
border-top-left-radius: var(--border-radius);
border-bottom-left-radius: var(--border-radius);
}
.install-tab:last-child {
border-top-right-radius: var(--border-radius);
border-bottom-right-radius: var(--border-radius);
}
.install-tab.active {
background: rgba(255, 255, 255, 0.3);
font-weight: 600;
}
.copy-btn {
background: transparent;
border: none;
color: white;
cursor: pointer;
padding: 0.25rem 0.5rem;
font-size: 0.9rem;
transition: var(--transition);
border-radius: 4px;
}
.copy-btn:hover {
background-color: rgba(255, 255, 255, 0.2);
}
/* Usage guide */
.usage-btn {
background: transparent;
border: none;
color: rgba(255, 255, 255, 0.8);
font-size: 0.85rem;
margin-top: 0.5rem;
cursor: pointer;
text-decoration: underline;
transition: var(--transition);
}
.usage-btn:hover {
color: white;
}
```
--------------------------------
### Serve flag-icons on localhost
Source: https://github.com/lipis/flag-icons/blob/main/README.md
Run the 'start' command to serve the project on localhost:8000. This is useful for local development and testing.
```bash
$ yarn start
```
--------------------------------
### Development Workflow Steps
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/build-and-utilities.md
Steps for the typical development workflow, from installing dependencies to iterating on changes.
```bash
# 1. Start with fresh dependencies
yarn install
# 2. Make changes to SASS or SVGs
# 3. Auto-format code
yarn fix
# 4. Build CSS
yarn build
# 5. Start dev server
yarn start
# 6. Open http://localhost:8000 in browser
# 7. Iterate: edit, build, refresh browser
```
--------------------------------
### Install flag-icons using Composer
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/integration-guide.md
Install the flag-icons package using Composer for PHP projects.
```bash
composer require lipis/flag-icons
```
--------------------------------
### Setup Copy Buttons
Source: https://github.com/lipis/flag-icons/blob/main/index.html
Initializes data attributes for elements intended to copy standard and square flag codes, pre-populating them with example HTML.
```javascript
const setupCopyButtons = () => {
document.getElementById("copy-standard-code").dataset.code = ` United States`;
document.getElementById("copy-square-code").dataset.code = ` United States`;
};
```
--------------------------------
### Start Development Server with Yarn
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/build-and-utilities.md
This command starts a local HTTP server for development and testing purposes. The server runs on localhost:8000 and serves static project files. Manual browser refresh is required for hot reloading.
```bash
yarn start
```
--------------------------------
### Install Project Dependencies
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/build-and-utilities.md
Commands to install all project dependencies, including development tools like http-server, prettier, sass, and svgo. Both yarn and npm package managers are supported.
```bash
yarn install
# or
npm install
```
--------------------------------
### Install Dependencies
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/index.md
Installs project dependencies using Yarn. This is a prerequisite for building and developing the flag-icons library.
```bash
yarn install
```
--------------------------------
### HTML Example with Basic Flag Icons
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/integration-guide.md
Basic HTML structure demonstrating how to include flag icons for different languages using CDN.
```html
Languages
English
German
French
```
--------------------------------
### Start Application on DOM Ready
Source: https://github.com/lipis/flag-icons/blob/main/index.html
Ensures the application initialization function runs only after the entire HTML document has been loaded and parsed.
```javascript
document.addEventListener("DOMContentLoaded", init);
```
--------------------------------
### Install flag-icons via npm or Yarn
Source: https://github.com/lipis/flag-icons/blob/main/README.md
Install the flag-icons library using your preferred package manager. This is the first step to integrating the flag icons into your project.
```bash
npm install flag-icons
# or
yarn add flag-icons
```
--------------------------------
### CDN Hosting Configuration Example
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/configuration.md
Configure the flag-icons library to serve assets from a Content Delivery Network by setting the `$flag-icons-path` variable to a CDN URL.
```scss
@use "node_modules/flag-icons/sass/flag-icons" with (
$flag-icons-path: "https://cdn.jsdelivr.net/gh/lipis/flag-icons@7.5.0/flags"
);
```
--------------------------------
### Custom Theme Example
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/api-reference-sass.md
Shows how to import flag-icons with custom country selection and then apply additional custom styling to the flag elements.
```scss
@use "node_modules/flag-icons/sass/flag-icons" as flag-icons with (
$flag-icons-included-countries: ("us", "gb", "de", "fr")
);
// Add custom styling
.fi {
border-radius: 4px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.fi-us {
border: 2px solid blue;
}
```
--------------------------------
### React Example with Flag Icon
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/integration-guide.md
Demonstrates how to import flag icons CSS and use a flag icon component in a React application.
```jsx
import 'flag-icons/css/flag-icons.min.css';
export default function App() {
return ;
}
```
--------------------------------
### Update Installation Command Display
Source: https://github.com/lipis/flag-icons/blob/main/index.html
Updates the displayed installation command and highlights the active tab for npm or yarn.
```javascript
const switchInstallCommand = (type) => {
installCommand.textContent = installCommands[type];
copyBtn.dataset.copy = installCommands[type];
installTabs.forEach((tab) => {
if (tab.dataset.tab === type) {
tab.classList.add("active");
} else {
tab.classList.remove("active");
}
});
};
```
--------------------------------
### Local Hosting Configuration Example
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/configuration.md
Illustrates the default SASS configuration for local asset hosting, where flags are served from relative paths. This is suitable for development.
```scss
// Default configuration
$flag-icons-path: "../flags"
// Generated URL: ../flags/4x3/us.svg (relative to CSS file)
```
--------------------------------
### Install Sass Dependency
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/build-and-utilities.md
Installs the 'sass' package if it's missing, resolving 'Cannot find module 'sass'' errors.
```bash
yarn install
# or
npm install sass@^1.89.2
```
--------------------------------
### CI/CD Pipeline Commands
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/build-and-utilities.md
Commands for automated builds in CI/CD environments, including installation, testing, and building.
```bash
# Install
yarn install
# Check formatting
yarn test
# Build CSS
yarn build
# Validate data
python3 flag-ids.py
python3 flags.py
```
--------------------------------
### Vue Example with Flag Icon
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/integration-guide.md
Shows how to import flag icons CSS and use a flag icon in a Vue.js component.
```vue
```
--------------------------------
### HTML Examples for Displaying Flags
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/index.md
Demonstrates how to display flags in HTML using different classes for inline text, square format, and as background images.
```html
United States
United Kingdom
USA
UK
```
--------------------------------
### Example Structure of Complete Country.json
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/types.md
Provides a sample of the root country.json file, showing an array of country objects sorted alphabetically by name.
```json
[
{
"capital": "Kabul",
"code": "af",
"continent": "Asia",
"flag_1x1": "flags/1x1/af.svg",
"flag_4x3": "flags/4x3/af.svg",
"iso": true,
"name": "Afghanistan"
},
{
"capital": "Tirana",
"code": "al",
"continent": "Europe",
"flag_1x1": "flags/1x1/al.svg",
"flag_4x3": "flags/4x3/al.svg",
"iso": true,
"name": "Albania"
},
// ... 250+ more entries sorted by name
]
```
--------------------------------
### Next.js App Router Layout Setup
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/integration-guide.md
Import the flag-icons CSS in your root layout for the App Router in Next.js.
```typescript
// app/layout.tsx
import 'flag-icons/css/flag-icons.min.css';
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
{children}
);
}
```
--------------------------------
### Next.js Pages Router App Setup
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/integration-guide.md
Import the flag-icons CSS in your _app.tsx for the Pages Router in Next.js.
```typescript
// pages/_app.tsx
import 'flag-icons/css/flag-icons.min.css';
import type { AppProps } from 'next/app';
export default function App({ Component, pageProps }: AppProps) {
return ;
}
```
--------------------------------
### Include Flag Icons CSS Locally
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/integration-guide.md
Link to the flag-icons CSS file from your local installation. This method ensures offline availability but requires the package to be installed via npm or yarn.
```html
```
--------------------------------
### Build Europe-Focused Stylesheet
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/api-reference-sass.md
Example of configuring `$flag-icons-included-countries` to generate CSS for a specific region, in this case, European countries.
```scss
@use "node_modules/flag-icons/sass/flag-icons" with (
$flag-icons-included-countries: (
"ad", "al", "at", "be", "bg", "by", "ch", "cy", "cz", "de", "dk", "ee",
"es", "fi", "fr", "gb", "gr", "hr", "hu", "ie", "it", "lt", "lu", "lv",
"mc", "md", "me", "nl", "no", "pl", "pt", "ro", "rs", "se", "si", "sk",
"ua", "eu"
)
);
```
--------------------------------
### Initialize Flag Icons Application
Source: https://github.com/lipis/flag-icons/blob/main/index.html
Loads country data, creates flag cards, sets up event listeners for search, format switching, installation commands, and modal interactions.
```javascript
const init = async () => {
try {
const countries = await loadJSON("country.json");
// Sort countries by name
countries.sort((a, b) => a.name.localeCompare(b.name));
// Create flag cards
countries.forEach((country) => {
const card = createFlagCard(country);
if (country.iso) {
isoFlagsGrid.appendChild(card);
} else {
nonIsoFlagsGrid.appendChild(card);
}
allFlags.push({ country, element: card });
});
setupCopyButtons();
// Set up event listeners
searchInput.addEventListener("input", filterFlags);
format4x3Btn.addEventListener("click", () => switchFormat("4x3"));
format1x1Btn.addEventListener("click", () => switchFormat("1x1"));
// Installation tab switching
installTabs.forEach((tab) => {
tab.addEventListener("click", () => {
switchInstallCommand(tab.dataset.tab);
});
});
// Copy npm/yarn command
copyBtn.addEventListener("click", (e) => {
const textToCopy = e.currentTarget.dataset.copy;
navigator.clipboard
.writeText(textToCopy)
.then(() => showCopyTooltip())
.catch((err) => console.error("Could not copy text: ", err));
});
// Usage modal
usageBtn.addEventListener("click", () => {
usageModal.classList.add("active");
});
modalClose.addEventListener("click", () => {
usageModal.classList.remove("active");
});
usageModal.addEventListener("click", (e) => {
if (e.target === usageModal) {
usageModal.classList.remove("active");
}
});
// Filter dropdown
filterBtn.addEventListener("click", toggleFilterDropdown);
filterOptions.forEach((option) => {
option.addEventListener("click", () => {
currentFilter = option.dataset.filter;
filterBtn.textContent = option.textContent + " ";
const icon = document.createElement("i");
icon.className = "bi bi-chevron-down";
filterBtn.appendChild(icon);
filterOptions.forEach((opt) => {
opt.classList.toggle("active", opt === option);
});
filterFlags();
toggleFilterDropdown();
});
});
// Code block copy buttons
codeBlockCopyBtns.forEach((btn) => {
btn.addEventListener("click", () => copyCode(btn));
});
} catch (error) {
console.error("Error initializing the application:", error);
}
};
```
--------------------------------
### Example Usage of .fi Class
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/api-reference-css-classes.md
Demonstrates how to use the .fi class with country codes to display rectangular flags next to text.
```html
United States
United Kingdom
Germany
```
--------------------------------
### HTML Example for Flag Grid Display
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/integration-guide.md
Demonstrates a responsive grid layout for displaying multiple flag icons with associated text, using CSS Grid for arrangement.
```html
USA
UK
Germany
```
--------------------------------
### Angular Global CSS Setup
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/integration-guide.md
Demonstrates how to set up flag icon CSS globally in an Angular project, either by importing into `styles.css` or by configuring `angular.json`.
```css
@import 'flag-icons/css/flag-icons.min.css';
```
```json
{
"projects": {
"myapp": {
"architect": {
"build": {
"options": {
"styles": [
"node_modules/flag-icons/css/flag-icons.min.css",
"src/styles.css"
]
}
}
}
}
}
}
```
--------------------------------
### Example SVG Header with ID
Source: https://github.com/lipis/flag-icons/blob/main/_autodocs/data-reference.md
Illustrates the structure of an SVG file after the 'flag-ids.py' script has added a unique ID for accessibility purposes.
```xml