What is the public folder in Next.js used for?

public/ holds static files served as-is from the site root: public/logo.png is available at /logo.png. Use it for favicons, robots.txt, images referenced by URL, downloadable files and verification files.

Rules

  • Files are served from /, never with /public in the URL.
  • Only files present at build time are served. Files added at runtime are not picked up; use object storage (S3, R2, Vercel Blob) for user uploads.
  • A file in public/ must not share a name with a page route, or there is a conflict.
  • Next.js cannot fingerprint these files, so browsers may cache an old version. By default they get Cache-Control: public, max-age=0, meaning revalidate every time.

When to prefer other options

  • Imported images (import hero from "./hero.jpg") get automatic width, height and blur placeholders with next/image, and hashed URLs that can be cached forever.
  • Favicons and OG images can use the metadata file conventions (app/icon.png, app/opengraph-image.png, app/favicon.ico), which Next.js turns into the right <link> tags.
  • robots.txt and sitemap.xml can be generated with app/robots.ts and app/sitemap.ts.

Using public images with next/image

Reference them by path and pass explicit width and height, because Next.js cannot read their dimensions automatically.

Code example

tsx
1// public/
2// ├── favicon.ico -> /favicon.ico
3// ├── images/team.jpg -> /images/team.jpg
4// └── docs/guide.pdf -> /docs/guide.pdf
5
6// app/about/page.tsx
7import Image from "next/image";
8import hero from "./hero.jpg"; // imported: size and blur placeholder known at build
9
10export default function About() {
11 return (
12 <main>
13 <Image src={hero} alt="Our office" placeholder="blur" preload />
14 {/* public/ file: give explicit dimensions */}
15 <Image src="/images/team.jpg" alt="The team" width={800} height={500} />
16 <a href="/docs/guide.pdf" download>
17 Download the guide
18 </a>
19 </main>
20 );
21}

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.

Open in study app