Skip to content
Tezmy Tools

Sort Lines by Length

Order lines by how many characters or words they have

5 lines. Lines of equal length keep their original order.

Runs in your browser. Nothing is uploaded.

About the Sort Lines by Length

Alphabetical order is not always what you want. Sometimes you need the shortest items first, the longest at the top, or lines grouped by how many words they have. This tool sorts your lines by length. Choose shortest first or longest first, and measure length in characters or in words. Empty lines can be dropped and repeated lines removed. Lines that are the same length keep the order they had before, so the sort is stable and predictable. It runs in your browser and nothing is uploaded.

Updated October 2026

How to use the Sort Lines by Length

  1. 1Paste your lines into the left box, one per line.
  2. 2Choose shortest first or longest first.
  3. 3Choose whether to measure length in characters or words.
  4. 4Tick the options to drop empty lines or remove duplicates.
  5. 5Copy the sorted lines.

When length order helps

Writers check headlines against a character limit and want to see the longest first. Developers sort strings by length to spot outliers in data. Teachers sort vocabulary lists from short to long. Designers fit labels into boxes and need to know which is the widest. Putting the longest lines on top shows the problem cases immediately.

Sorting by words is useful for sentences, since a line with twelve words is long even if the words are short.

    Options explained

    Drop empty lines removes blank lines, which would otherwise gather at the top in shortest-first order. Remove duplicate lines keeps only the first copy of each line. Both are on or off independently of the sort order.

    • Shortest first: ascending
    • Longest first: descending
    • Characters or words as the unit

    Related tasks

    For alphabetical order, use the Sort Words Tool or a line sorter. To remove repeats without sorting, use Remove Duplicate Lines. To count the characters or words in a text, use the character and word counters on this site.

      Examples

      Sorting the lines a long line of text here, short, medium line, x and between them shortest first gives x, short, medium line, between them, a long line of text here. In words mode, the one-word lines come first and the five-word line comes last.

      Empty lines are removed by default, so they do not float to the top. Turn that option off if blank lines mean something in your text.

        Phone and computer

        Paste on either device and copy the result with the button. For long lists, a computer is more comfortable for checking, but the sort itself is instant on a phone.

          Privacy

          The lines are sorted by code that runs in your browser. Nothing is sent to a server, so you can sort drafts, titles or private notes without sharing them. To pull in lines from other files, first use Merge Text Lists, and Sort IP Addresses does the same ordering for network numbers.

            Features

            • Shortest or longest first
            • Count characters or words
            • Optional removal of empty lines
            • Optional removal of duplicate lines
            • Equal lengths keep their order
            • Private: nothing is uploaded

            Frequently asked questions

            How do I sort lines by length?

            Paste the lines, choose the order and the unit, and the sorted list appears. Shortest first puts one-letter lines at the top; longest first starts with the longest line.

            Does it count spaces?

            When measuring in characters, yes, every character including spaces counts. Measure in words if spaces should not matter.

            What happens to lines of equal length?

            They stay in their original relative order. This makes the sort stable, so running it twice gives the same result.

            Can I sort by number of words?

            Yes. Choose words as the unit. A line of three words comes before a line of four in shortest-first order.

            Why would I sort by length?

            To find the longest titles or sentences, to check which lines exceed a limit, to group short entries together or to prepare lists for layout and fitting.

            Is my text uploaded?

            No. Sorting is done in your browser and the text stays on your device.

            Related tools