# .env Key Sorter Guide

Sort the keys in a .env file alphabetically, keeping each comment with its key and optionally dropping duplicates or aligning values.

- Tool: https://ilham.dev/tools/env-key-sorter/
- Guide URL: https://ilham.dev/guides/env-key-sorter/
- Tool guides index: https://ilham.dev/guides/tools/
- Broader guide: Working With Configuration Files (https://ilham.dev/guides/configuration-files/)

## What it does

Put a .env file in alphabetical order without shuffling the comments that belong to each setting. The top comment block stays first, a comment above a key travels with that key, and blank lines are closed up. Duplicate keys can be collapsed to the last value, and the equals signs can be lined up for a tidier read.

## Use the tool

Open https://ilham.dev/tools/env-key-sorter/, add the input the tool asks for, run it, and check the output before using it elsewhere.

## Input and output

- Input: text.
- Output: text.
- Category: Text.

## Privacy and processing
Processing happens locally in your browser. This tool does not upload the input to ilham.dev.

## Questions

### Does it change the values?

No. Only whole lines are moved, so spacing, quotes and inline comments inside a value are untouched. Alignment only pads the space before the equals sign.

### Which duplicate value wins?

The last one, which is what most .env loaders use when a key appears twice.

### Is my file uploaded?

No. The file is read, sorted and written in the browser; nothing leaves the page.

### Does it understand export?

Yes. A line like export PORT=3000 is still recognised as the PORT key and keeps its export prefix.