Environment variables in Next.js
Answer: Next.js loads .env files. Variables stay on the server by default; prefix with NEXT_PUBLIC_ for the browser.
See also
Claims
- id: C1 claim: Next.js has built-in env support. source: S1 evidence: "Next.js comes with built-in support for environment variables, which allows"
- id: C2 claim: Bundle browser vars with NEXT_PUBLIC_. source: S1 evidence: "Bundle environment variables for the browser by prefixing with
NEXT_PUBLIC_"
- id: C3 claim: Default env vars stay on the server. source: S1 evidence: "By default, environment variables are only available on the server."
- id: C4 claim: next.config env inlines values at build time. source: S2 evidence: "Next.js will replace
process.env.customKeywith'my-value'at build time."
Sources
- [S1] Environment variables. Next.js docs. https://nextjs.org/docs/app/guides/environment-variables . License: MIT (vercel/next.js). Accessed 2026-11-09.
- [S2] env. Next.js docs. https://nextjs.org/docs/app/api-reference/config/next-config-js/env . License: MIT (vercel/next.js). Accessed 2026-11-09.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Copyright (c) 2025 Vercel, Inc. Sources: Next.js docs (vercel/next.js on GitHub / nextjs.org), MIT (https://raw.githubusercontent.com/vercel/next.js/canary/license.md). Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Next.js docs, Environment variables, MIT (vercel/next.js); Next.js docs, env, MIT (vercel/next.js). Copyright (c) 2025 Vercel, Inc. MIT (https://raw.githubusercontent.com/vercel/next.js/canary/license.md).
Cite this
iinventedlight. 2026. "Environment variables in Next.js." iinventedlight Library, iil:note:az8wvrf2, version of 2026-11-09. https://iinventedlight.com/library/notes/nextjs-environment-variables/. License: CC-BY-4.0.
@misc{iil_note_az8wvrf2,
author = {{iinventedlight}},
title = {{Environment variables in Next.js}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-09},
url = {https://iinventedlight.com/library/notes/nextjs-environment-variables/},
note = {Permanent ID iil:note:az8wvrf2. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/nextjs-environment-variables.md.