For an Astro favicon setup, put your icon files in the public/ folder and add link tags to the <head> of your base layout: an SVG favicon for modern browsers, a favicon.ico fallback, and a 180-pixel apple-touch-icon.png for iOS. New Astro projects already ship public/favicon.svg, so often you only need to replace that file.
Key Takeaways
- Files in
public/are served from the site root unchanged:public/favicon.svgbecomes/favicon.svg.- Three files cover nearly everything:
favicon.svg,favicon.icoandapple-touch-icon.png.- Keep
favicon.icoat the root; some browsers and tools request/favicon.icodirectly.- Google shows your favicon in search results if it is at least 48 by 48 pixels and crawlable.
The files
public/
favicon.svg # vector icon for modern browsers
favicon.ico # 32x32 fallback (can contain 16 and 32 sizes)
apple-touch-icon.png # 180x180, solid background, no transparency
Export the SVG from your logo mark, not the full logo with text; at 16 pixels, words become a smudge. Give apple-touch-icon.png a solid background, because iOS fills transparent areas with black.
The link tags
---
// src/layouts/Layout.astro
---
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="/favicon.ico" sizes="32x32" />
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
</head>
<body><slot /></body>
</html>
Browsers that support SVG favicons use the SVG; others use the ICO. The sizes="32x32" on the ICO line stops Chrome from preferring it over the SVG.
Using a different base path
If your site deploys under a subpath (base: '/docs' in astro.config.mjs), prefix the paths so they resolve:
---
// src/layouts/Layout.astro
const base = import.meta.env.BASE_URL.replace(/\/$/, '');
---
<link rel="icon" href={`${base}/favicon.svg`} type="image/svg+xml" />
Optional: a web app manifest
If you want an installable site or Android home screen icons, add a manifest with 192 and 512 pixel PNGs:
// public/site.webmanifest
{
"name": "Example",
"icons": [
{ "src": "/icon-192.png", "type": "image/png", "sizes": "192x192" },
{ "src": "/icon-512.png", "type": "image/png", "sizes": "512x512" }
]
}
<link rel="manifest" href="/site.webmanifest" />
Skip it if you do not need installability; the three files above are enough for browsers and search.
Checking it worked
Build, run npm run preview, and open /favicon.svg and /favicon.ico directly. Browsers cache favicons aggressively, so test in a private window after changes. For search results, Google’s favicon guidelines require the icon to be crawlable and a multiple of 48 pixels square; an SVG meets that. To make the SVG follow the user’s dark mode, see our SVG favicon dark mode tip. Our meta tags component guide shows where these tags fit with the rest of the head, and the project structure docs explain public/. Every one of our Astro themes includes a favicon you replace this way.
FAQ
Where do I put the favicon in Astro?
In the public/ folder at the project root. Files there are copied to the build output as-is and served from the site root, so public/favicon.svg is available at /favicon.svg.
Why is my Astro favicon not showing?
Usually caching. Open the site in a private window or clear the cache. Also check the href path matches the file name in public/, and that you are not linking a file from src/.
Do I still need favicon.ico?
It is worth keeping. Some browsers, feed readers and tools request /favicon.ico directly without reading your link tags.