create-favicon

Creates a minimal set of favicons that are compatible with most environments,
based on this article by Evil Martians.
Requires Node.js 22 or later.
Source image must be at least 512x512, preferably a square SVG.
The generated files are:
- 32x32 favicon (for older devices)
- 180x180 PNG icon for Apple devices
- 192x192 PNG icon for Android devices
- 512x512 PNG icon for Android devices
- Web manifest files pointing to the two larger PNG icons
- (If source is an SVG) An SVG icon for modern browsers - this also supports dark mode
Outputs the HTML needed to link these files up on success.
Available as a CLI tool and as an API.
CLI usage
npm install -g create-favicon
create-favicon <path-to-image> [output-dir]
npm create favicon <path-to-image> [output-dir]
npm create favicon <path-to-image> [output-dir] -- --overwrite
npx create-favicon <path-to-image> [output-dir]
npx create-favicon <path-to-image> [output-dir] -- --no-warn
CLI options
<path-to-image> Source image
[output-dir] Output directory (default: ./favicons)
--overwrite Overwrite existing files (default: false)
--base-path <path> Base path for printed HTML and web manifest (default: /)
--no-warn Disable warnings (default: false)
--no-manifest Skip outputting a webmanifest (default: false)
-h, --help Display this message
-v, --version Display version number
API usage
import {createFavicon} from 'create-favicon'
const {html} = await createFavicon({sourceFile: '/path/to/some/file.svg'})
const {html} = await createFavicon({
sourceFile: '/path/to/some/file.svg',
outputDir: '/path/to/output/dir',
})
const {html} = await createFavicon({
sourceFile: '/path/to/some/file.svg',
basePath: '/my/app',
})
const {html} = await createFavicon({
sourceFile: '/path/to/some/file.svg',
overwrite: true,
})
const {html} = await createFavicon({
sourceFile: '/path/to/some/file.svg',
warn: false,
})
const {html} = await createFavicon({
sourceFile: '/path/to/some/file.svg',
manifest: false,
})
const {html} = await createFavicon({sourceFile: 'https://example.com/sourceLogo.svg'})
const myImage = await someFetcher({
url: 'https://example.com/sourceLogo.svg',
}).then((res) => res.buffer())
const {html} = await createFavicon({sourceFile: myImage})
License
MIT © Espen Hovlandsdal