Text Sorter

How to Sort Lines Alphabetically Online

📅 April 2026⏱ 7 min read✍️ ToolsBox

Sorting a list of lines alphabetically is one of those tasks that sounds trivial until you find yourself staring at hundreds of entries in a plain text file with no obvious way to organise them. Whether you are arranging a keyword list, sorting bibliography entries, or ordering configuration values, knowing the quickest way to sort text alphabetically online can save a surprising amount of time. This guide covers every method — from browser-based tools to the command line and code.

Why Sorting Lines Alphabetically Matters

Alphabetically sorted lists are easier to scan, easier to search, and easier to maintain over time. When you add a new item to an unsorted list of 200 entries, it is nearly impossible to know whether that item already exists. When the list is sorted, a quick visual scan tells you immediately whether "Queensland" is already in your list of states.

Beyond readability, alphabetical order matters in several technical contexts:

  • CSS and code: Sorting CSS properties, import statements, and configuration keys alphabetically makes diffs cleaner and code reviews easier, since reviewers can immediately spot whether a new property belongs where it was placed.
  • SEO keyword lists: Alphabetically sorted keyword lists are easier to share with colleagues, import into tools, and cross-reference with existing research.
  • Data exports: Sorted CSV or TSV exports from databases are predictable — every analyst gets the same row order regardless of when they pull the data.
  • Reference documents: Glossaries, bibliographies, appendices, and indexes are almost universally expected to be alphabetically sorted.

How to Sort Lines Alphabetically Online in Seconds

The fastest way to sort lines alphabetically without installing any software is to use our free Text Sorter tool. Here is the full workflow:

  1. Open the Text Sorter on ToolsBox.
  2. Paste your text into the input box. Each line will be treated as a separate item to sort.
  3. Choose your sort order: A → Z (ascending), Z → A (descending), or by line length.
  4. Optionally enable case-insensitive sorting so that "banana" and "Banana" are treated as the same.
  5. Click Sort. The result appears instantly.
  6. Click Copy or download the sorted text as a file.

The tool runs entirely in your browser — no text is uploaded to any server — and there is no character or line limit. After sorting you might want to remove any duplicate entries that got grouped together using our Duplicate Line Remover.

Understanding Different Sort Orders

Not all alphabetical sorting is identical. Understanding the distinctions helps you pick the right option for your data:

Lexicographic (standard ASCII) sort: This is the default in most programming languages. It sorts character by character based on Unicode code points. Uppercase letters come before lowercase ones (A–Z before a–z), and numbers come before letters. So the list ["banana", "Apple", "cherry"] would sort as ["Apple", "banana", "cherry"] because uppercase A has a lower code point than lowercase b.

Case-insensitive sort: Before comparing, each line is converted to the same case (usually lowercase). This gives the intuitively expected result: Apple, banana, cherry all sort together regardless of capitalisation.

Natural sort (alphanumeric sort): This mode recognises that "10" should come after "9", not after "1". Without natural sort, a file list like ["file1", "file2", "file10"] sorts as ["file1", "file10", "file2"]. Natural sort correctly orders them as ["file1", "file2", "file10"]. This is critical for version numbers, file names, and any list that mixes text with numbers.

Reverse sort: Simply reverses the result of any of the above, giving Z → A or 10 → 1 order. Useful for reverse-chronological date lists or when you want the "last" items first for a specific display purpose.

Sort Lines Alphabetically with Command-Line Tools

If you work in a terminal, the sort command on Linux and macOS is powerful and fast enough to handle files of any size:

# Basic alphabetical sort (ascending)
sort input.txt > sorted_output.txt

# Case-insensitive sort
sort -f input.txt > sorted_output.txt

# Reverse (descending) sort
sort -r input.txt > sorted_output.txt

# Natural numeric sort (correct number ordering)
sort -V input.txt > sorted_output.txt

# Sort and remove duplicates in one step
sort -u input.txt > sorted_unique.txt

The -u flag is particularly useful — it combines sorting with deduplication in a single pass, which is faster than piping through uniq separately.

On Windows, PowerShell's Sort-Object provides similar functionality:

# Sort lines alphabetically
Get-Content input.txt | Sort-Object > sorted_output.txt

# Case-insensitive sort
Get-Content input.txt | Sort-Object { $_.ToLower() } > sorted_output.txt

# Descending sort
Get-Content input.txt | Sort-Object -Descending > sorted_output.txt

Sort Lines in Excel and Google Sheets

For lists that live in a spreadsheet, the native sort features are the most convenient option.

In Microsoft Excel: Select the cells containing your list. Click the Data tab and then the Sort A to Z or Sort Z to A button. If your list is in a single column, Excel sorts it immediately. If you have a multi-column table, Excel offers a dialog where you can choose which column to sort by and whether to include a header row.

In Google Sheets: Select the column, then choose Data → Sort sheet → Sort sheet by column A (A to Z). You can also select a range and use Data → Sort range for more control.

One caveat with spreadsheet sorting: if your text list is in a single column alongside other data in adjacent columns, Excel and Sheets may ask whether to expand the selection. Always preview the result before confirming to ensure you have not accidentally shuffled related data out of alignment.

Sort Lines Alphabetically in JavaScript

For developers processing text in Node.js or the browser, JavaScript's built-in Array.prototype.sort() method handles alphabetical sorting with minimal code:

const text = `banana
apple
Cherry
date
elderberry`;

// Case-sensitive sort (uppercase before lowercase)
const sorted = text.split('\n').sort().join('\n');

// Case-insensitive sort
const sortedCI = text.split('\n')
  .sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()))
  .join('\n');

// Natural sort (correct numeric ordering)
const sortedNatural = text.split('\n')
  .sort((a, b) => a.localeCompare(b, undefined, { numeric: true, sensitivity: 'base' }))
  .join('\n');

The localeCompare method with the numeric: true option enables natural sort, and sensitivity: 'base' makes it case-insensitive. This combination is the most robust general-purpose sort for user-facing text in JavaScript applications.

Combining Sort with Other Text Operations

Sorting is rarely the only operation you need. A common workflow for cleaning a text list looks like this:

  1. Remove extra whitespace — Use a Whitespace Remover to trim leading and trailing spaces from each line so that " apple" and "apple" sort together correctly.
  2. Remove duplicates — Run through a Duplicate Line Remover to eliminate repeated entries.
  3. Sort alphabetically — Use the Text Sorter to arrange the clean, unique list in the order you need.
  4. Count the result — Use a Word Counter to confirm the final line count matches your expectations.

Following this four-step sequence gives you a clean, sorted, deduplicated list from any raw input — ready to import into a spreadsheet, database, or document.

Sort your text list alphabetically — free

Ascending, descending, case-insensitive, or by line length. Instant results.
Open Text Sorter →

Frequently Asked Questions

Does sorting alphabetically online handle numbers correctly?

Standard alphabetical (lexicographic) sort treats numbers as strings, so "10" sorts before "2" because "1" comes before "2" in ASCII. For correct numeric sorting you need a tool that uses a numeric sort mode. Our Text Sorter supports natural sort order, which correctly orders 1, 2, 10, 20 rather than 1, 10, 2, 20.

Can I sort lines in reverse alphabetical order?

Yes. Most text sorting tools, including ours, have a Descending option that reverses the alphabetical order so lines go from Z to A. This is useful for reverse-chronological lists or for finding lines that start with later letters quickly.

How do I sort a list alphabetically in Microsoft Word?

Select the list, go to the Home tab, click the Sort button (AZ with an arrow) in the Paragraph group, choose Text and Ascending or Descending, then click OK. For plain text files outside Word, an online text sorter is usually faster.

Will sorting remove duplicates too?

Sorting alone does not remove duplicates — it just groups identical lines together. To both sort and remove duplicates, first run your text through a Duplicate Line Remover, then sort the result. Alternatively, some text sorter tools offer a combined "sort and deduplicate" option in a single step.

Back to Blog  |  Related tool: Text Sorter