Skip to content

Sort Lines by Length

Sort lines by character length.

Input
Output

No result

About Sort Lines by Length

Sort Lines by Length reorders the lines of your text from shortest to longest, counting characters. Empty lines, at zero characters, rise to the top; the longest line sinks to the bottom; and lines of equal length keep the order they arrived in, because the browser sort this page relies on is stable. The result recalculates as you type.

The count is a plain character count, which is worth understanding before trusting the output. Twenty CJK characters measure as twenty, the same as twenty Latin letters, even though they render roughly twice as wide on screen - so a list sorted to look tidy in one writing system is not tidy in another. A trailing space also counts, so two lines that look identical can sort apart if one of them carries invisible whitespace at the end.

Sorting by length is the natural first pass on any pile of lines whose shape matters more than its content: trimming a word list down to the short entries, finding the over-long lines in a piece of prose, or arranging items for a layout. The direction is fixed ascending, with no descending option and no tie-breaking key - alphabetical order for equal-length lines has to be applied separately.

How to use Sort Lines by Length

  1. 1 Paste the multi-line text into the panel.
  2. 2 Watch the output, which is reordered live with the shortest line first.
  3. 3 Use the top of the result for the shortest lines and the bottom for the longest.
  4. 4 Copy the reordered text, or clear the panel and start on the next block.

Frequently asked questions

How are lines of the same length ordered?

They keep the relative order they had in the input, because the underlying sort is stable. Two five-character lines arrive in the order you pasted them and leave the same way round, with no alphabetical tie-break applied.

Why did two identical-looking lines sort apart?

Almost always because one of them has trailing whitespace. The length that is compared includes every character, so a space on the end makes a line measure one longer than its visible twin, and no trimming is done before the comparison.

Can I sort from longest to shortest instead?

Not on this page. The direction is fixed ascending, so the longest lines are at the bottom rather than the top. Reading the result upwards gives the same information, and a true descending sort is not offered here.

Does it sort alphabetically within a length?

No. Length is the only key. If a group of equal-length lines needs an alphabetical order underneath, this page has to run first and an alphabetical sort applied to the result separately.

Free, online, and private

Free to use

Sort Lines by Length is completely free. There is no account to create, no login, and no hidden charge or usage limit.

Runs online in your browser

It is a free online tool that runs entirely in your browser. Nothing to download or install — open the page and start using it right away.

Your data stays private

All processing happens locally on your device. Your input is never uploaded, stored, or tracked, so it never leaves your browser.

How Sort Lines by Length behaves in detail

These are the specifics of this implementation — the exact ranges, defaults and fixed settings you are working with.

Parameter Value
Input one text panel, recalculated live as you type
Splitting the text is split on newlines into lines, which are sorted and rejoined
Order ascending by character count, with the shortest line first
Stability lines of equal length keep their original relative order, as the browser sort is stable
Empty lines an empty line has length zero and therefore sorts to the very top of the result
Output the same set of lines, reordered, joined back with newlines

Compiled from the implementation of this tool and checked against it by itoolnet.

What Sort Lines by Length does not do

Knowing the edges of a tool saves more time than another list of its features. These are the cases where it will not do what you might expect.

  • Length is a character count, not a display width. A line of twenty CJK characters is measured as twenty, exactly like a line of twenty Latin letters, even though it renders about twice as wide - so a result sorted for visual tidiness in one script is not tidy in another.
  • The direction is fixed ascending with no descending option, and there are no keys for anything but length: alphabetical order, numeric order and shuffle all live on their own pages, so a length tie that should be broken alphabetically has to be finished by hand.
  • Lines are compared whole and a trailing space counts. A line with invisible trailing whitespace sorts as longer than its visible twin, and there is no trimming pass, no trimming setting, and no indication of which lines carried the extra characters.

Tested and documented by itoolnet, the team that builds and maintains this site.

Share & embed this tool

Writing a guide or article? You are welcome to link to Sort Lines by Length with the snippet below. It is free, runs entirely in your browser, and needs no signup.