If your Docusaurus favicon still shows the framework's default icon after you replace the asset, the file may be in the wrong folder or the config may not point to it. Put the icon in static/, set one config value, and verify the built output.
Prerequisites
You need a Docusaurus project, a square source image, and access to docusaurus.config.ts.
- A PNG or SVG whose mark stays recognizable at 16×16 pixels.
- The project dependencies installed and a terminal open at the repository root.
Add a Docusaurus favicon in five steps
-
Generate suitable files. Use Mzu favicondl to convert a square PNG or SVG into an ICO, then download an SVG or PNG. Keep the source artwork simple; a full wordmark becomes unreadable in a tab.
-
Use the
static/ directory. Docusaurus copies it into the build output without changing its internal paths. Replace the default icon or arrange your files like this:
static/
└── img/
├── favicon.ico
├── favicon.svg
└── favicon-32.png
-
Set the built-in config option. In the existing object in
docusaurus.config.ts, keep or add:
const config: Config = {
// ...other options
favicon: 'img/favicon.ico',
};
Use a path relative to static/, without a leading slash. The built-in option adds the icon link and applies baseUrl, so the configuration works at a domain root or under a subpath.
-
Add SVG when you want a scalable icon. Add this property to the same config object while retaining the ICO fallback:
headTags: [
{
tagName: 'link',
attributes: {
rel: 'icon',
type: 'image/svg+xml',
href: '/img/favicon.svg',
},
},
],
The tag follows HTML's rel='icon' link relationship. Because headTags are literal, include the base path: with baseUrl: '/docs/', use /docs/img/favicon.svg.
-
Build and check the real output. Run:
npm run build
npm run serve
Inspect the rendered <head>. It should contain an icon link like:
<link rel='icon' href='/img/favicon.ico'>
Confirm build/img/favicon.ico exists and the Network panel returns an image, not HTML. With baseUrl, check the prefixed URL. Deploy the complete build/ directory.
Common pitfalls
- Putting files in
src/img: Imported assets are bundled by the app; they are not automatically published at /img/. Use static/ for this setup.
- Ignoring
baseUrl: The config option handles it; literal icon URLs in headTags do not.
- Checking a cached tab: Open the site in a private window or force a reload. If the response is correct but the tab remains stale, use the favicon troubleshooting checklist.
- Overlapping icon links: Inspect the generated head for tags added by a theme or plugin. Keep one intentional SVG and one ICO fallback, then remove accidental duplicates.
- Comparing broader workflows: For shared principles, compare the static-site-generator favicon guide; the Docusaurus-specific parts are its
favicon option and static/ output.
Conclusion
A Docusaurus favicon does not need a page-level component or plugin. Generate the right files, keep them in static/img/, point favicon at the ICO, and verify the built head after every deployment or base-path change.
Si el favicon de tu Docusaurus sigue mostrando el icono predeterminado del framework después de sustituir el recurso, puede que el archivo esté en la carpeta equivocada o que la configuración no apunte a él. Coloca el icono en static/, define el valor de configuración correspondiente y comprueba la salida del build.
Requisitos previos
Necesitas un proyecto de Docusaurus, una imagen fuente cuadrada y acceso a docusaurus.config.ts.
- Un PNG o SVG cuyo diseño siga siendo reconocible a 16×16 píxeles.
- Las dependencias del proyecto instaladas y una terminal abierta en la raíz del repositorio.
Añade un favicon de Docusaurus en cinco pasos
-
Genera los archivos adecuados. Usa Mzu favicondl para convertir un PNG o SVG cuadrado en un ICO y descarga después un SVG o PNG. Mantén simple el diseño de origen; un wordmark completo se vuelve ilegible en una pestaña.
-
Usa el directorio
static/. Docusaurus lo copia en la salida del build sin modificar sus rutas internas. Sustituye el icono predeterminado o organiza tus archivos así:
static/
└── img/
├── favicon.ico
├── favicon.svg
└── favicon-32.png
-
Usa la opción de configuración integrada. En el objeto existente de
docusaurus.config.ts, mantén o añade:
const config: Config = {
// ...other options
favicon: 'img/favicon.ico',
};
Usa una ruta relativa a static/, sin una barra inicial. La opción integrada añade el enlace al icono y aplica baseUrl, por lo que la configuración funciona tanto en la raíz de un dominio como bajo un subpath.
-
Añade un SVG si quieres un icono escalable. Añade esta propiedad al mismo objeto de configuración sin eliminar el fallback de ICO:
headTags: [
{
tagName: 'link',
attributes: {
rel: 'icon',
type: 'image/svg+xml',
href: '/img/favicon.svg',
},
},
],
La etiqueta sigue la relación de enlace rel='icon' de HTML. Como headTags son literales, incluye la ruta base: con baseUrl: '/docs/', usa /docs/img/favicon.svg.
-
Compila y comprueba la salida real. Ejecuta:
npm run build
npm run serve
Inspecciona el <head> renderizado. Debería contener un enlace al icono como:
<link rel='icon' href='/img/favicon.ico'>
Confirma que build/img/favicon.ico exista y que el panel Network devuelva una imagen, no HTML. Si usas baseUrl, comprueba la URL con el prefijo. Despliega el directorio build/ completo.
Problemas habituales
- Colocar archivos en
src/img: Los assets importados se empaquetan en la app; no se publican automáticamente en /img/. Para esta configuración, usa static/.
- Ignorar
baseUrl: La opción de configuración se encarga de esto; las URL literales de los iconos en headTags, no.
- Revisar una pestaña con la caché: Abre el sitio en una ventana privada o fuerza una recarga. Si la respuesta es correcta pero la pestaña sigue desactualizada, usa la lista de diagnóstico del favicon.
- Enlaces de iconos redundantes: Revisa el head generado para detectar las etiquetas que hayan añadido un theme o un plugin. Conserva un SVG intencional y un ICO como fallback, y elimina los duplicados accidentales.
- Comparar otros flujos de trabajo: Para conocer los principios comunes, consulta la guía de favicon para static site generators; las partes específicas de Docusaurus son su opción
favicon y el resultado en static/.
Conclusión
Un favicon en Docusaurus no necesita un componente a nivel de página ni un plugin. Genera los archivos correctos, mantenlos en static/img/, apunta la opción favicon al ICO y verifica el head generado después de cada despliegue o cambio de base path.
Prepare a clean Docusaurus icon set
Convert a square logo into ICO, PNG, and SVG files with Mzu favicondl, then add them to your Docusaurus static folder.
Try It Free →