Favicon for React
How to add a favicon to a React app
A React app is still one HTML file, so the favicon lives in public/index.html. Generate the kit, unzip it into public/ and replace the default tags. Using Vite? See the note below.
Add the favicon in React
- Upload files to
- public/
- Add code to
- public/index.html
- Unzip the package into the public/ folder.
- Open public/index.html and delete the existing favicon and manifest <link> tags.
- Paste the snippet inside <head>.
public/index.html
<link rel="icon" href="/favicon.ico" sizes="32x32">
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
<link rel="icon" type="image/png" sizes="48x48" href="/favicon-48x48.png">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon-180x180.png">
<link rel="manifest" href="/site.webmanifest">
<meta name="theme-color" content="#FFFFFF">The file names match what the generator produces. Your theme colour and name are filled in when you generate your own kit.
Using Vite? Pick the Vite tab — its index.html lives in the project root.
Where the favicon sits in a React project
React itself has nothing to do with the favicon. The browser reads icons from the HTML document your bundler serves, so the work happens in one file and one folder. In Create React App that is public/index.html and the public/ folder. In a Vite project index.html sits in the project root, and files in public/ are copied to the output untouched and served from the site root.
Do not import favicons from src/ in your components. A bundler fingerprints imported files, so the URL changes on every build and the tag in index.html would point at a name that no longer exists. Put them in public/ and refer to them with a root path, or with %PUBLIC_URL% in Create React App when the app is served from a sub-folder.
A single-page app only loads that HTML once, so the icon does not change when you navigate. If you want a different icon for a theme or a notification badge, change the link's href at runtime. The component below does it for the system colour scheme, using a second SVG that you supply.
src/useThemeFavicon.js
import { useEffect } from "react";
export function useThemeFavicon() {
useEffect(() => {
const link = document.querySelector('link[rel="icon"][type="image/svg+xml"]');
const media = window.matchMedia("(prefers-color-scheme: dark)");
const apply = () => {
if (link) link.href = media.matches ? "/favicon-dark.svg" : "/favicon.svg";
};
apply();
media.addEventListener("change", apply);
return () => media.removeEventListener("change", apply);
}, []);
}Optional. It needs both favicon.svg and favicon-dark.svg in public/ and the matching <link> tag in index.html.
Check it worked
- Build the app and open the production output, not only the dev server.
- In DevTools, open the Network tab, reload, and filter by Img to see which icon file was requested and whether it returned 200.
- Search the built index.html for rel="icon" and make sure the old React logo tag is gone.
Why your React favicon may not show
- Delete the existing favicon.ico and logo192.png references. Leaving the old tags first means the browser may still pick the React logo.
- Files in public/ are served from the site root. If your app is deployed under a sub-path, prefix each href with it (or use %PUBLIC_URL% in Create React App).
- The browser caches favicons aggressively. Test in a private window, not just a refresh.
- To change the icon per route or theme at runtime, update the <link rel="icon"> href from an effect or use a head manager such as react-helmet-async.
Already published? Run your site through the favicon checker to see exactly what is wrong, or see every favicon size for what each file is for.
React favicon FAQ
Where do I put the favicon in a React app?
In the public/ folder, with the link tags in public/index.html. With Vite, index.html sits in the project root instead.
Why does my React app still show the React logo?
The old favicon.ico is still being requested, or the old link tag is still in index.html. Replace both and hard-refresh in a private window.
Can I use an SVG favicon in React?
Yes. Put favicon.svg in public/ and add <link rel="icon" href="/favicon.svg" type="image/svg+xml">. Keep favicon.ico as a fallback.
Skip the resizing.
Drop in one logo and get every size, the manifest and the HTML for React.
Open the favicon generator →