WebToolsPlanet
text Tools

Text Sorter

Sort lines alphabetically, numerically, by length, or randomly — with case-sensitive and reverse order options.

Last updated: March 25, 2026

Client-Side Processing
Input Data Stays on Device
Instant Local Execution

Find this tool useful? Support the project to keep it free!

Buy me a coffee

What is Text Sorter?

Sorting lines of text is a foundational data processing operation needed across many daily workflows. Developers sort lists of dependency names before committing package.json changes. Content writers sort glossary entries alphabetically. Data analysts sort comma-separated values by numeric score. System administrators sort log lines by timestamp. Database engineers sort database column lists before generating schema documentation.

This tool provides all common sort modes in one place: alphabetical (A-Z and Z-A), numeric (sorts digit strings as numbers, not as text — "10" sorts correctly after "9"), by line length (shortest-first or longest-first), and random shuffle (useful for randomizing a list of items for testing or lottery purposes). All operations are applied instantly using JavaScript's optimized sort algorithms.

How to Use Text Sorter

1

Paste your list of lines (one item per line) into the input area

2

Select your sort mode: Alphabetical, Numeric, By Length, or Random Shuffle

3

Choose Ascending (A-Z / small-to-large) or Descending (Z-A / large-to-small)

4

Toggle "Case Insensitive" if you want "banana" and "Banana" to sort as equal

5

Click "Copy Result" to copy the sorted output to your clipboard

Common Use Cases

  • Sorting a list of npm dependencies alphabetically before import in a package.json or import block
  • Alphabetizing a list of country names, country codes, or language options for a configuration file
  • Sorting a reading list, word list, or tag list alphabetically for a documentation site
  • Ranking search result URLs or domain names by their length to analyze character count patterns
  • Shuffling a list of team members randomly for turn-order assignment
  • Sorting a CSV column of scores or timestamps numerically for analysis
  • Sorting a list of CSS class names, HTML attributes, or JSON keys before code review
  • Reversing a list of git commits (oldest-first to newest-first) for documentation

Example Input and Output

Sorting a mixed list of programming language names alphabetically (case-insensitive):

Unsorted input (9 lines)
Python
javascript
TypeScript
rust
Go
ruby
JAVA
kotlin
swift
Sorted A-Z (case-insensitive)
Go
JAVA
javascript
kotlin
Python
ruby
rust
swift
TypeScript

Client-Side Processing

All sorting operations happen locally in your browser. The text you paste — including configuration values, email lists, or sensitive data — is never transmitted to our servers.

Sorting for Code Style

Alphabetically sorted imports and CSS properties are a common code style rule (enforced by ESLint "sort-imports" or Stylelint "declaration-property-sort-order" rules). Paste your unsorted import block or CSS declarations here, sort alphabetically, and paste back — much faster than manually reordering.

Command-Line Alternative

The Unix sort command is extremely powerful for file-based sorting: sort -u (sort + deduplicate), sort -n (numeric), sort -r (reverse), sort -k2 (by second column in CSV). For large files (millions of lines), use sort from the command line rather than a browser tool — it uses optimized external merge sort for files larger than available RAM.

Frequently Asked Questions

What is the difference between alphabetical and numeric sorting?
Alphabetical (lexicographic) sort compares characters left to right by Unicode code point. For numbers, this produces unintuitive results: "10", "2", "20" sort as "10", "2", "20" (because "1" < "2" < "2" lexicographically). Numeric sort parses each line as a number and compares mathematically: "2", "10", "20" sort correctly as 2, 10, 20. Use Numeric mode for any list containing quantities, scores, versions, or IDs.
Does sorting preserve blank lines?
By default, blank lines are treated as empty strings and sort to the top (in ascending order) since empty string is lexicographically first. Toggle "Remove Blank Lines Before Sorting" to strip all blank lines before applying the sort, which prevents empty strings from affecting sort order and producing unexpected empty entries at the top of the result.
How does "By Length" sorting work?
"By Length" sorts lines by their total character count. Ascending puts the shortest lines first; descending puts the longest first. This is useful for finding very long or very short entries in a list, analyzing word length distributions, or structuring CSS selectors (some developers prefer shorter selectors first). When two lines have the same length, their relative order is determined by a secondary lexicographic comparison.
Is the "Random Shuffle" truly random?
Yes and no. The shuffle uses Math.random() via the Fisher-Yates algorithm, which produces a statistically random permutation. However, Math.random() is a pseudo-random number generator — it is deterministic given the same internal state. For cryptographic randomness requirements (lottery, security draws), Math.random() is insufficient; use crypto.getRandomValues() instead. For casual randomization (team assignments, draft order), it is perfectly adequate.
Can I sort with multiple criteria (primary + secondary)?
The current tool supports single-criterion sorting. For multi-key sorting (e.g., sort by score descending, then by name ascending for ties), use a spreadsheet tool (Excel, Google Sheets) which has native multi-column sort, or write a quick script: array.sort((a, b) => b.score - a.score || a.name.localeCompare(b.name)).
How does locale-aware alphabetical sorting work?
Standard JavaScript sort() compares by Unicode code point, which can produce incorrect results for non-English characters: accented characters (é, ü, ñ) sort after all ASCII characters rather than alongside their base letters. Enable "Locale Sort" to use String.prototype.localeCompare() with the browser's locale setting, which correctly sorts accented characters alongside their base equivalents according to the language rules.

How This Tool Works

The input is split into a line array using \n as the delimiter. Depending on the selected mode: Alphabetical uses Array.sort() with localCompare() or direct code point comparison; Numeric uses sort((a, b) => parseFloat(a) - parseFloat(b)); By Length uses sort((a, b) => a.length - b.length); Random Shuffle implements the Fisher-Yates algorithm with Math.random(). Ascending/Descending is applied by either using the natural sort comparison or negating it. Case insensitivity lowercases both operands in the comparator function only. The sorted array is then joined with \n and displayed.

Technical Stack

Browser-native JavaScriptArray.sort() / Fisher-Yates shuffleString.localeCompare()Client-side only