11

I have an issue with the new Next.js 13 beta. They removed head.js files and now (as it is written in doc) I have to use metadata in layout.ts. My favicon has name favicon.png.

How do i specify it here:

export const metadata = {
 title: 'Create Next App',
 description: 'Generated by create next app',
 }
Yilmaz
  • 35,338
  • 10
  • 157
  • 202
Nazar Duma
  • 127
  • 1
  • 1
  • 9

10 Answers10

22

This is the simplest way to use Favicon in the Next.js 13.4 Stable version.

  1. You need to convert your jpg, png, or SVG to .ico. It takes only a few seconds.

  2. Rename your .ico file to icon.ico and paste it into the app folder and remove the favicon.ico from the app folder

Done

Raghav Sharma
  • 284
  • 1
  • 5
16

You can do it as follow:

export const metadata = {
  icons: {
    icon: '/icon.png',
  },
};

The output will be

<link rel="icon" href="/icon.png" />

See all documentation regarding icons metadata:

https://beta.nextjs.org/docs/api-reference/metadata#icons

Jairo Py
  • 615
  • 6
  • 12
7

To add multiple icons and add other attributes like type and sizes:

// layout.tsx
    
export const metadata: Metadata = {
  ...,
  icons: [
    {
      rel: 'icon',
      type: 'image/png',
      sizes: '32x32',
      url: '/favicon/favicon-32x32.png',
    },
    {
      rel: 'icon',
      type: 'image/png',
      sizes: '16x16',
      url: '/favicon/favicon-16x16.png',
    },
    {
      rel: 'apple-touch-icon',
      sizes: '180x180',
      url: '/favicon/apple-touch-icon.png',
    },
  ],
}
Wani
  • 278
  • 3
  • 8
  • thanks it does add sizes attribute but it sets all rel to icons like here is my code ```icons: [ {rel: "icon",type: "image/png",sizes: "32x32",url: "/favicon.png",}, {rel: "apple-touch-icon",type: "image/png",sizes: "180x180",url: "/favicon.png",}, {rel: "shortcut icon",type: "image/png",url: "/favicon.png",},],``` and here is what i got in chrome `````` – UNRIVALLEDKING May 23 '23 at 17:58
  • how would you handle for toggling browser theme from light to dark? – Hyetigran Aug 16 '23 at 20:23
4

acctually this will be correct,

    export const metadata = {
        icons: {
            icon:'/_next/static/media/metadata/favicon.png',
        },
    };    

and then put you favicon image in that URL (_next/static/media/metadata).

devchitect
  • 41
  • 1
3

Based on docs here, adding link in RootLayout will also work

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>
        <link rel="icon" href="/favicon.ico" sizes="any" />
        {children}
      </body>
    </html>
  );
}
Yilmaz
  • 35,338
  • 10
  • 157
  • 202
2
// app/layout.tsx

import { Metadata } from 'next';

export const metadata: Metadata = {
  icons: {
    icon: ['/favicon.ico?v=4'],
    apple: ['/apple-touch-icon.png?v=4'],
    shortcut: ['/apple-touch-icon.png'],
  },
  manifest: '/site.webmanifest',
};

// public/
//    |- ...
//    |- android-chrome-192x192.png
//    |- android-chrome-512x512.png
//    |- apple-touch-icon.png
//    |- favicon-16x16.png
//    |- favicon-32x32.png
//    |- favicon.ico
//    |- site.webmanifest
//    |- ...

Icon Convertor: https://favicon.io/favicon-converter/

acoding
  • 81
  • 1
  • 4
0

in layout.tsx

export const metadata: Metadata = {
  icons: {
    icon: {
      url: "/favicon.png",
      type: "image/png",
    },
    shortcut: { url: "/favicon.png", type: "image/png" },
  },
};

and in public I have a image called favicon.png

0

To me, the only method that worked is here.

This example is from the kapeesa gaming platform

Rename your icon file name to favicon.ico

e.g mine was kapeesa.png which I renamed to favicon.ico

Put your favicon.ico file in the src/app/ directory.

You usually have to replace the one you find in this path src/app/

That's it. It'll be used, fingerprinted, kabam.

0

Step One: Delete the favicon.ico from root(app) directory.

Step Two: Place your icon in the root(app) directory like (app/icon.svg) app/icon.png, app/icon.jpg.

0

just put your favicon.ico in the root of src/app/ or app/ directory if still not working rename favicon to icon

Wildan Maulana
  • 62
  • 1
  • 1
  • 8