— Sort Lines by Length

Sort Lines by Length

Quick Tips

  • This tool runs entirely in your browser - your data stays private.
  • Press Ctrl+V (Cmd+V on Mac) to quickly paste text.
  • Use the Copy button to save your result to clipboard.
  • Bookmark this page for quick access!

Sort lines of text by character length.

Examples

Input
cat
elephant
dog
horse
Output
cat
dog
horse
elephant
Input
a
abc
ab
abcd
Output
a
ab
abc
abcd
Input
Hello World
Hi
Good morning
Output
Hi
Hello World
Good morning

Frequently Asked Questions

Length is calculated by counting all characters in each line, including spaces and punctuation. A line with "Hello World" has 11 characters (including the space). Empty lines have a length of zero.

When lines have equal length, they maintain their relative order from the original text (stable sort). Optionally, you can choose to alphabetize same-length lines or sort them by other criteria.

Yes, spaces are counted as characters by default. "Hi there" has 8 characters. If you need to sort by length excluding spaces, you can preprocess the text or use an option if available to ignore whitespace in the count.

Yes, select descending order to sort from longest to shortest. This puts the longest lines at the top, useful when you want to prioritize or analyze the most lengthy items first.

Most special characters count as 1 character. However, some emojis are actually multiple Unicode code points combined, which may count as multiple characters. The exact count depends on how the specific emoji is encoded.

Cookie Preferences

We use cookies to enhance your experience. By continuing to visit this site you agree to our use of cookies.

Cookie Preferences

Manage your cookie settings

Essential Cookies
Always Active

These cookies are necessary for the website to function and cannot be switched off. They are usually set in response to actions made by you such as setting your privacy preferences or logging in.

Functional Cookies

These cookies enable enhanced functionality and personalization, such as remembering your preferences, theme settings, and form data.

Analytics Cookies

These cookies allow us to count visits and traffic sources so we can measure and improve site performance. All data is aggregated and anonymous.

Google Analytics _ga, _gid

Learn more about our Cookie Policy