Home / Text tools / Sort lines by length

Sort Lines by Length

Order your lines from shortest to longest, or longest to shortest, by number of characters.

How length is measured

Length is the number of characters in a line, counting spaces. Emoji and other characters made of several code units are counted as one character each, so the order matches what you see on screen.

Ties

When two lines have the same length, they are ordered alphabetically by default. Untick Break ties alphabetically to keep them in their original order instead.

What it is useful for

  • Finding the longest or shortest line in a list.
  • Tidying word lists, names or taglines by size.
  • Checking which lines will not fit in a limit, by putting the longest first.
  • Grouping similar items, such as short codes and long descriptions.

Example

The words banana, fig, apple, kiwi, watermelon and plum sorted shortest first become fig, kiwi, plum, apple, banana, watermelon.

Need exact numbers? The line counter shows the longest line and its length. For other orders use the main sort lines tool, or read the sorting guide.

Frequently asked questions

How do I sort lines from longest to shortest?

Set the direction to Descending.

Are spaces counted in the length?

Yes. Every character counts, including spaces. Use Trim lines to remove spaces at the ends.

What order do lines of equal length appear in?

Alphabetical by default. Untick the option to keep their original order.