OKfmt

Complete Configuration Specification Guide for Frontend Site Favicon

This article sorts out 5 categories of favicon configuration rules, covering the internal embedding principle and adaptation details of ICO, to help front-end developers complete standardized configuration.

Bijgewerkt 2026-08-11

Basic Principle of Multi-size Embedding for ICO

A standard ICO file supports embedding multiple bitmaps of different sizes in a single container, and the common configuration includes three sizes: 16×16, 32×32 and 48×48. Different usage scenarios automatically match the corresponding size: 16×16 is used for browser tab bars, 32×32 for bookmark bars, and 48×48 for desktop shortcuts.

The multi-size storage of ICO files follows the ICO format specification, each size corresponds to an independent bitmap data block, and the browser reads the bitmap of the corresponding size according to the current rendering scenario, so there is no need to generate multiple independent files. Older IE browsers only support reading favicons in ICO format, so keeping favicon.ico in the root directory can be compatible with access from older versions.

Embedded sizeUsage scenario
16×16Display in browser tab bar
32×32Display in browser bookmark bar
48×48System desktop shortcut

Declaration Specification for PNG Favicon in Modern Browsers

Modern browsers such as Chrome, Firefox, and Edge all support favicons in PNG format. The declaration method uses the link tag to add the corresponding size attribute, and core configuration requires two specifications: 32×32 and 192×192. 32×32 matches high-resolution tab bar rendering in modern browsers, and 192×192 is used for native PWA application icons on Android.

The standard declaration code is <link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32"> and <link rel="icon" type="image/png" href="/favicon-192x192.png" sizes="192x192">. Browsers will automatically select the corresponding size to load according to the scenario.

Dark Mode Adaptation for SVG Favicon

Some modern browsers support favicons in SVG format. SVG can achieve color adaptation under different themes through built-in media queries to adapt to system dark mode switching. The principle of SVG adaptation is to add a media query for prefers-color-scheme in the SVG code, and define the icon fill color under light and dark modes respectively.

To declare an SVG favicon, use type="image/svg+xml" to specify the file format. It has a higher priority than traditional ICO and PNG, and browsers load SVG format first. Developers can use an SVG to ICO converter to convert the edited adapted SVG to ICO format to be compatible with more access scenarios.

Configuration Requirements for apple-touch-icon

Apple iOS provides a dedicated icon for web pages added to the home screen, namely apple-touch-icon. The current specification requires a 180×180 PNG icon. Early versions supported declarations of multiple different sizes, and iOS 12 and later versions prioritize the 180×180 size to match all Apple devices.

The standard declaration code is <link rel="apple-touch-icon" href="/apple-touch-icon-180x180.png">. There is no need to add the size attribute, and the iOS system will automatically recognize the 180×180 size for adaptation. Rounded corners and highlight effects are automatically processed by the iOS system, and developers do not need to pre-process rounded corners.

Configuration for manifest.json and theme-color

PWA applications need to configure the manifest.json file to declare basic application information, which needs to include an icon field with the corresponding size, declaring a 512×512 application icon to meet PWA installation requirements. theme-color needs to be declared in both the meta tag and manifest, and is used for theme color matching of the browser address bar.

For a complete configuration, add <meta name="theme-color" content="#ffffff">, and add a field with the same name in manifest.json, keeping the value consistent with the meta tag, to adapt to the address bar rendering logic of different browsers.

Veelgestelde vragen

Do I have to keep favicon.ico in the root directory?

Yes, it is required. Some older browsers and services will automatically request favicon.ico from the root directory, and the absence will generate a 404 error. A compliant configuration will retain the ICO file that meets the size requirements in the root directory.

Can SVG favicon replace all formats?

No. IE11 and lower versions do not support SVG favicons. In production environments, ICO and PNG formats need to be retained as a fallback solution, and SVG is only used as a priority option for modern browsers.

Does apple-touch-icon need pre-applied rounded corners?

No. The iOS system automatically adds rounded corners, highlights and mask effects to icons added to the home screen. Pre-made rounded corners will cause abnormal display. You only need to provide a square 180×180 PNG.