Back to Tools

.env Formatter

Clean, sort, and perfectly align your environment variables.

Input Data

Tidy environment files without hand editing

A .env file grows organically. Keys are added at the bottom, someone pastes a duplicate from another project, and spacing drifts. This formatter reads KEY=value lines and produces a neat, column-aligned listing in which each variable name appears exactly once, so you can see the real configuration rather than a pile of overrides.

How to use it

  1. Paste your variables into the Input Data box, one per line. The Sample button loads a Laravel-style example that includes a repeated APP_ENV.
  2. Press Process / Generate.
  3. Look at the aligned output and the summary line, which reports how many unique keys were formatted.
  4. Choose Copy to grab the text or Download to save it as result.txt. Clear resets the box.

Exactly what changes

  • Whitespace around each key and value is trimmed, and the text is split at the first equals sign only, so values that contain = are left intact.
  • Keys are padded to the width of the longest name so the equals signs line up in one column.
  • When a key appears more than once, it is listed at the position of its first appearance but carries the value from its last appearance, which mirrors how most loaders let later lines win.
  • Blank lines and lines starting with # are skipped, as is any line without an equals sign.

Good moments to reach for it

  • Comparing your local .env with .env.example before onboarding a teammate.
  • Finding out which value actually wins after a merge conflict left two DB_HOST lines.
  • Making a config snippet readable for a screenshot or a support request.
  • Auditing a long file for repeated variable names.

Cautions before copying the result back

Comments are removed from the output, so do not overwrite a commented file without saving the notes elsewhere. The order is not alphabetical; it follows first appearance. The output also puts spaces around the equals sign for readability. Many dotenv libraries accept that, but a shell that runs source .env or Docker's env-file loader may not, so delete the spaces if you need strict KEY=value form. Quotes around values are kept as typed. Because .env files often hold secrets, review the output before pasting it into public issues. The formatting runs in JavaScript within your browser page.

Related Articles

Related Tools







Frequently Asked Questions

Does the .env Formatter sort variables alphabetically?
No. Despite tidying the layout, it keeps keys in the order each name first appears. It aligns them into a column and removes repeats, but it does not reorder. If you want alphabetical order, sort the lines in your editor before pasting.
Which value is kept when a key is duplicated?
The last value wins. The key appears once, at the position where it was first seen, and carries the value from its final occurrence. The summary line shows how many unique keys remain after duplicates are merged.
Are comments preserved?
No. Lines beginning with # are skipped and do not appear in the output, and neither do lines lacking an equals sign. Keep a copy of the original if your comments matter.
Can I use the output directly as a .env file?
Often yes, but check first. The tool writes KEY = value with padding and spaces around the equals sign. Some parsers and shell sourcing require KEY=value with no spaces, so remove the spacing if you see load errors.
Will values containing equals signs break?
No. Each line is split at the first equals sign only, so a value such as a base64 string ending in = or a URL with query parameters stays intact. Only the key is separated from what follows.
Support Chat
We typically reply within minutes

Hello! 👋 Before we start, please tell us your name.