How do I add a favicon with NextJS?

Learn how to easily add a favicon to your NextJS project with this detailed guide and also find out how to generate a favicon on demand using ImageResponse.
•
Updated on August 14, 2026
•
5 min read
Believemy logo

Adding a favicon is not necessarily a walk in the park: you need to consider the size, the format, and the tag to use to display your icon.

Good to know

A favicon is a small icon used as a favorite (the term "favicon" comes from the English "favorite icon"). It is also displayed in the browser tab.

Fortunately, installing a favicon with NextJS (or Next.js for the insiders) is a real pleasure! 😬

 

Step 1: Prepare the Favicon

Before adding your favicon to your NextJS project, you need to follow two rules:

  • An image format - It must be in one of the following image formats: .ico, .jpg, .jpeg, .png, or .svg
  • Having a reduced size - NextJS allows you to use images of any size, but it’s still better if you use an image with a reduced size

If you don't want to hassle, you can use this favicon generator.

 

Step 2: Use the Favicon

With the App Router

To use a favicon with the app router, simply rename your image to icon.

If you have followed Step 1 correctly, you should have an image in the correct format. All that's left is to drag and drop your favicon into the base of the app router.

And that's it! 😋

Warning

If you want to learn more about NextJS, go to see this page, you should love it. ✨

Here is the code generated by NextJS when you drop a favicon.[ico | jpg | jpeg | png | svg] image into your app router:

HTML
<link
      rel="icon"
      href="/icon?<generated>"
      type="image/<generated>"
      sizes="<generated>"
    />

 

With the Pages Router

If you are using the pages router of NextJS, you might want to create an app folder to use the app router to make your life easier. Creating a favicon with the pages router is a bit more complicated. 🤔

You will need to create an image must be in .ico format. Fortunately, if you already have an image in another format, many online converters exist. For example, this one.

Once you have your image, you need to rename your image to favicon.ico.

Finally, you need to add your favicon to the public/static folder.

Good to know

The static folder is a folder used for all resources that do not change on your website, like your favicon or your fonts. If you don’t have it, you have the option to create it.

You should normally end up with this:

CONSOLE
/public/static/favicon.ico

To finish, you need to modify either the _app.js file or the _document.js file to add this:

JSX
<Head>
        <link rel="shortcut icon" href="/static/favicon.ico" />
    </Head>

Let’s explain this example a bit:

  • Head is the component provided by NextJS that allows you to add tags to the header of the HTML page.
  • link is a tag that allows you to link a resource; here, we specify that it’s an icon (rel="shortcut icon") and a shortcut.

Finally, we use the _app.js or _document.js file because all the pages of our site use one or the other of these base pages. Thus, by adding a tag that allows having a favicon on one of the two pages, all the pages of our project now have a favicon. 😉

 

Bonus: Using a JavaScript Favicon

Thanks to NextJS, we can also generate a specific favicon for each page. This is a favicon created using a JavaScript file.

Warning

It is only possible to (easily) generate a JavaScript favicon with the app router of NextJS.

File Type

You need to have a JavaScript or TypeScript file. Nothing different from what you’re already used to doing in your project.

Next, you need to add a file named icon.[js | jsx | ts | tsx] to your app router. You should have:

CONSOLE
/app/icon.[js | jsx | ts | tsx]

 

The Code to Use

To generate an image for your page, you need to use the ImageResponse component provided by NextJS.

Here’s a small example:

JSX
import { ImageResponse } from 'next/og'
     
    // Define the favicon dimensions
    export const size = {
      width: 128,
      height: 128,
    }
    
    // Create a .png image
    export const contentType = 'image/png'
     
    // Generate an image
    export default function Favicon() {
      return new ImageResponse(
        (
          <div
            style={{
              fontSize: 24,
              background: 'black',
              width: '100%',
              height: '100%',
              display: 'flex',
              alignItems: 'center',
              justifyContent: 'center',
              color: 'white',
            }}
          >
            B
          </div>
        ),
        // Define the options, including the size
        {
          ...size,
        }
      )
    }

With this example, you can imagine all that JavaScript allows you to do for your favicons!

Warning

Favicons generated by NextJS cannot be modified after build time. So when you export your project to put it online.

Finally, know that this file also receives a props params:

JSX
export default function Icon({ params }) {
      // ...
    }

 

Conclusion

Adding a favicon to a NextJS application is quick and easy. But, as we saw in the two examples with the pages router and the app router, it's much simpler with the latter.

Finally, we saw that it is possible to generate a favicon on the fly with NextJS!

If you want to learn everything about NextJS, we have prepared something special just for you. 🤭

Category: Developers

Share this article

Want to help us? Share this article on your networks or even better: on your site, in an article or in your newsletter.

Believemy logo
Comments (0)

You need to be logged in to comment on this article: log in or sign up.

Read next

How to create a custom 404 error page for NextJS?

Customize your 404 error page with NextJS for the brand-new App router, and make your users' experience more pleasant.

December 9, 2024

Setting up a loader when changing a Nextjs page

Have you ever been on a site where you click on a link and nothing happens? Or perhaps you've wondered whether your request was actually received? This is where having a loader comes in. In this article, we'll explain why it's important to have a loader on your website, how to set it up in your Nextjs project and create a function that will display the loader until the page is loaded. If you want to improve the user experience on your website and reassure your visitors, this article is for you.

December 11, 2024

What's new in NextJS 15

NextJS 15 was presented to the world on October 24, 2024 in San Francisco. Here's everything we know about NextJS 15's powerful new features!

December 5, 2024

How to install TinyMCE in a project using React or NextJS?

Find out how to install TinyMCE in React or NextJS and fully customize it with plugins to match your projects.

December 6, 2024

Why you should learn NextJS in 2025: all the benefits!

Explore why Next.js is a must-have framework for developers in 2025. Learn about its benefits, unique features and why the job market is increasingly adopting it.

December 6, 2024

Implementing over-request revalidation with NextJS

If you're a web developer, you probably know how important it is to have a fast, responsive site to deliver an optimal user experience. In this article, we're going to show you how to set up on-demand revalidation with NextJS, a feature that refreshes your site's data only when necessary. Using this method, you can save resources and improve the performance of your website, while offering up-to-date data to your users.

December 9, 2024

Creating a NEON button with CSS

Creating a button is one thing! But creating a button that your visitors want to click is something else entirely. In any case, this neon button will catch the eye of everyone who visits your pages.

December 9, 2024

React vs NextJS: what should you choose for your project in 2025?

Which technology should you use, React or NextJS? Discover their advantages and disadvantages to choose the one best suited to your projects.

December 9, 2024

Become the solopreneur you dream of being.

First project, career change, business launch: access our courses, practice on real-world cases, and move forward with clear guidance.