DEV Community

Cover image for How to add a favicon to a Next.js static site?
Calvin Torra
Calvin Torra

Posted on • Originally published at calvintorra.com

2 2

How to add a favicon to a Next.js static site?

Join The JS Fam Discord Here

A chill community where we pair-program, launch products and learn together

=====

I was asked this on the website chat, but looking a bit closer I'm sure the problem was related to image paths.

The boilerplate Next.js comes with an example of the built-in Head module and they also have a favicon linked.

All we need to do is make sure we have our Head module from Next imported and placed our link tag inside.

import Head from "next/head";

<Head>
    <title>Create Next App</title>
    <meta name="description" content="Generated by create next app" />
    <link rel="icon" href="/favicon.ico" /> // <- HERE
</Head>
Enter fullscreen mode Exit fullscreen mode

You can grab a favicon icon-sized image from places like https://favicon.io/, they make it super easy to convert different types to favicon.

You can place the image in your public folder or make a new folder called images / icons etc and place it there.

From your code you don't need to add public to your path as Next gives you access directly to static assets in the public directory.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay