favicon, icon, and apple-icon in Next.js — Setting App Icons with Files or Code

Next.js supports special conventions for setting app icons: favicon, icon, and apple-icon. These icons appear in browser tabs, mobile home screens, and search engine previews. You can define them using image files or generate them programmatically with ImageResponse. This article explains both approaches, valid file locations, metadata configuration, and how Next.js automatically injects the correct <head> tags.

faviconapple-iconImageResponsehead tags

~3 min read • Updated Oct 29, 2025

1. Types of App Icons in Next.js


Next.js supports three types of icons:

  • favicon: for browser tabs
  • icon: for general app branding
  • apple-icon: for iOS home screen shortcuts

2. Ways to Define Icons


You can define icons in two ways:

  1. Using image files (.ico, .jpg, .png)
  2. Generating icons with code (.js, .ts, .tsx)

3. Using Image Files


TypeSupported FormatsValid Location
favicon.icoOnly in app/
icon.ico, .jpg, .png, .svgAnywhere in app/**
apple-icon.jpg, .pngAnywhere in app/**

Example <head> Output:

<link rel="icon" href="/favicon.ico" sizes="any" />
<link rel="icon" href="/icon?...generated" type="image/png" sizes="32x32" />
<link rel="apple-touch-icon" href="/apple-icon?...generated" type="image/png" sizes="180x180" />

4. Generating Icons with Code


Use the ImageResponse API from next/og to generate icons programmatically:

// app/icon.tsx
import { ImageResponse } from 'next/og'

export const size = { width: 32, height: 32 }
export const contentType = 'image/png'

export default function Icon() {
  return new ImageResponse(
    <div style={{
      fontSize: 24,
      background: 'black',
      width: '100%',
      height: '100%',
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center',
      color: 'white',
    }}>
      A
    </div>,
    { ...size }
  )
}

Good to Know:

  • Generated icons are statically optimized at build time unless they use dynamic APIs
  • You cannot generate a favicon — use a .ico file instead
  • You can define multiple icons using numbered filenames like icon1.png, icon2.png

5. Input and Output Parameters


The default export function can receive dynamic route parameters:

export default async function Icon({ params }) {
  const { slug } = await params
}

Valid return types include:

  • Blob
  • ArrayBuffer
  • TypedArray
  • ReadableStream
  • Response

6. Metadata Configuration


You can export metadata for the icon:

export const size = { width: 32, height: 32 }
export const contentType = 'image/png'

Conclusion


Next.js offers flexible ways to define app icons using either static image files or dynamic code. With proper conventions and metadata, your icons will be automatically injected into the HTML head, ensuring a polished and recognizable experience across platforms.


Written & researched by Dr. Shahin Siami