The Complete .env File Syntax Reference
Definitive reference for .env file syntax: quoting rules, comments, multiline values, variable expansion, and differences across Node.js, Python, Ruby, Go, and Docker Compose.
Last updated:
Frequently Asked Questions
Can .env files have comments?
Yes. Lines starting with # are treated as comments in all major dotenv implementations. Inline comments (KEY=value # comment) are supported by some libraries (Python, Ruby) but not all (Node.js dotenv). Avoid inline comments for maximum portability.
Do I need to quote values in .env files?
Unquoted values work for simple strings without spaces or special characters. Use double quotes for values with spaces, newlines (\n), or variable expansion ($VAR). Use single quotes for literal strings where no expansion should occur.
Does .env support multiline values?
Yes, in double quotes. Use \n for newline characters or span multiple lines by keeping the opening and closing quotes. Exact support varies by implementation — Node.js dotenv supports both approaches.
Stay up to date
Get notified about new guides, tools, and cheatsheets.
Related Guides
The .env File: A Complete Guide to Environment Variables
Everything you need to know about .env files: syntax, usage across languages, best practices, and common pitfalls.
Next.js Environment Variables: Complete Guide
How Next.js handles environment variables: .env files, NEXT_PUBLIC_ prefix, server vs client access, load order, and common production errors.
Node.js Environment Variables: process.env, dotenv & --env-file
How to use environment variables in Node.js. Covers process.env, dotenv, Node 20.6+ --env-file flag, NODE_ENV, type-safe validation with zod, and cross-platform support.