Guides · Updated 2026-12-04
Favicon setup in Next.js, Vite and React
Frameworks all handle static files a little differently, and the favicon is one of the places where those differences cause confusion. In one tool you drop a file in a folder and it works. In another you must declare it in code. In a third, the dev server shows the old icon for hours.
This guide covers the most common setups: Next.js with the App Router, Vite with React, and a plain React or Astro site. For each one you will see where the files go, what to write, and how to confirm it works.
Before you start: the files you need
Whatever the framework, the set of files is the same: a favicon.ico, an SVG or PNG icon, a 180 pixel Apple touch icon, and the 192 and 512 pixel icons for a manifest. Generate them once from one logo, and then place them as described below. The generator on the home page produces the whole set and the HTML.
Next.js with the App Router
The App Router uses file-based metadata. Place specially named files in the app directory and Next.js adds the correct link tags for you. A favicon.ico placed in the app folder is used as the site icon. An icon.png, icon.svg or icon.ico in the same folder is also detected, and apple-icon.png is used as the Apple touch icon.
You do not write any link tags yourself in this case. Next.js generates them and handles the file name hashing so the cache updates when you replace the file, which solves a lot of stale icon problems.
app/
favicon.ico
icon.svg
apple-icon.png
layout.tsxNext.js: using the metadata object instead
If you prefer to keep icons in the public folder, declare them in the metadata export of your root layout. Files in public are served from the site root, so the paths start with a slash.
export const metadata = {
icons: {
icon: [
{ url: "/favicon.ico", sizes: "32x32" },
{ url: "/icon.svg", type: "image/svg+xml" },
],
apple: "/apple-touch-icon.png",
},
manifest: "/site.webmanifest",
};Next.js Pages Router
With the older Pages Router there is no file convention for icons. Put the files in the public folder and add the link tags with the Head component from next/head, in _app or _document, so that they are in every page.
import Head from "next/head";
<Head>
<link rel="icon" href="/favicon.ico" sizes="32x32" />
<link rel="icon" href="/icon.svg" type="image/svg+xml" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
</Head>Vite with React
Vite serves everything in the public folder from the site root and copies it unchanged into the build. Put favicon.ico, icon.svg, the Apple icon and the manifest in public. Then add the link tags to the head of index.html, which is at the project root, not inside src.
<head>
<link rel="icon" href="/favicon.ico" sizes="32x32" />
<link rel="icon" href="/icon.svg" type="image/svg+xml" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<link rel="manifest" href="/site.webmanifest" />
</head>Create React App and other static setups
Create React App has a public folder with an index.html that already links a favicon. Replace the file and update the link tag. If you use PUBLIC_URL in the href, keep it, because it makes the path work when the app is hosted in a subfolder. The same approach applies to any plain static site: files in the web root, link tags in the head.
Astro, Remix and SvelteKit
These all follow the public folder pattern. In Astro, put the files in public and add the link tags to your base layout component. In Remix, use the links export of the root route. In SvelteKit, place the files in static and add the tags to app.html. In each case the key idea is the same: the file must be served from the site root and the tags must be in the head of every page.
Why the dev server shows the old icon
During development the icon often does not update when you replace the file. Browsers cache favicons hard, even on localhost, and a tab can keep showing the icon from a previous project that ran on the same port. Try a private window, a different port, or add a version query to the href while you are testing. A hard refresh usually does not clear the icon cache.
Also check that the dev server actually serves your file. Open the icon URL directly. If you get your app's HTML page back, the file is in the wrong folder.
Checklist for every framework
Whatever you use, confirm these before you deploy.
- favicon.ico is reachable at the site root.
- The link tags are in the head of the HTML the server returns.
- Paths start with a slash, so they work on nested pages.
- The Apple touch icon is 180 by 180 pixels with a solid background.
- The manifest is linked and lists 192 and 512 pixel icons.
- The built site, not only the dev server, shows the icon.
Was this guide helpful?
Questions
Where do I put favicon.ico in Next.js?
In the app directory for the App Router, which adds the tag automatically, or in the public folder if you declare it in the metadata object.
Where does the favicon go in a Vite project?
In the public folder, with link tags in index.html at the project root.
Why is my favicon not updating in development?
Browsers cache icons heavily, even on localhost. Use a private window or another port, or add a version query to the href.
Try it
More guides
- How to add a favicon to your website
- Favicon formats: ICO vs PNG vs SVG
- The Apple touch icon: size, format and common problems
- Favicon not showing or not updating: nine fixes
- Maskable icons explained: the safe zone and how to use it
- The web app manifest: what each field does
- How to design a favicon that is readable at 16 pixels
- How to get your favicon to show in Google Search results
- Open Graph image not showing: a checklist that finds the cause
- How to test Open Graph tags before you deploy