ForHosting KIT · Text & AI

Sort words by length

Paste a passage and get its words lined up by letter count: «I am a poet of moonlight» becomes I, a, am, of, poet, moonlight. Words of equal length keep their reading order. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Text
I am a poet of moonlight
You get
Text
I a am of poet moonlight
Words
I, a, am, of, poet, moonlight
Lengths
1, 1, 2, 2, 4, 9
Quantity
6

Sorting words by length is a focused text job: you want every word in a passage lined up from shortest to longest so you can study meter, fill a word-game rack, or scan a poem for long versus short tokens. Paste any non-empty text and this capability tokenizes Unicode letter runs, keeps internal apostrophes and hyphens so contractions and compounds stay whole, measures each token by letter count, and returns the words from shortest to longest. Same-length words keep their original reading order, so the ranking is stable across runs. Empty strings and punctuation-only input fail with invalid input rather than inventing an empty list.

How sorting words by length works and what counts as a word

Search intent for sort words by length is narrower than a general word counter or an alphabetical list sort: people want every token lined up by how many letters it contains, from shortest to longest, so they can study a poem, fill a puzzle rack, or compare long and short vocabulary in a passage. This capability defines a word as a maximal run of Unicode letters, including combining marks that sit on those letters so café and a decomposed cafe-plus-acute both stay one token.

An internal apostrophe or hyphen may join letter groups, so don't, well-known, and mother-in-law remain single words rather than splinters. Spaces, tabs, line breaks, digits, emoji, and all other punctuation act only as separators, so a trailing comma never inflates a length and never becomes a fake word. Length is the count of Unicode letters inside the token, not JavaScript UTF-16 code units and not the visual width in a particular font.

Hello has five letters, a has one, don't has four, and supercalifragilisticexpialidocious has thirty-four. After tokenization the engine records each word with its letter count and original index, then sorts by length ascending by default. Words that share a length keep their first-seen order so ties stay reproducible.

Word games and puzzle racks

Players and coaches paste a bank of candidate words and read groups to see which tokens fit a two-letter, three-letter, or five-letter slot.

Poetry meter and line texture

Poets sort a draft by letter length to spot a run of short function words or a single long token that will dominate a line.

How do I sort the words in my text by length?

The response includes text as a space-joined ranking, words as the ordered array, and groups that bucket those words by letter length from shortest to longest.

How is word length counted?

Length is the count of Unicode letters inside each token. Combining marks, apostrophes, and hyphens do not add to the count, so don't is four letters and café is four letters.

What happens when several words share the same length?

They stay in the order they first appeared in the input.

Are contractions and hyphenated compounds split?

No. An internal apostrophe or hyphen may join letter groups, so don't, well-known, and mother-in-law each stay one word. Surrounding punctuation is still a separator.

Can I sort words from longest to shortest?

Yes. Switch to the reverse order and the long words come first, so moonlight lands ahead of poet in the example. Shortest first is the default, the order most word games and meter studies need.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/str/sort-words-length

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/str/sort-words-length \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text":"I am a poet of moonlight"}'
{
  "text": "I am a poet of moonlight"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "str.sort_words_length",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_chars100000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Successful API calls are billed at $0.002 per item; validation failures are not charged.

How sorting words by length works and what counts as a word

Identical text always yields identical JSON with no network, no random seed, and no wall clock, which keeps homework keys and continuous-integration pins trustworthy for worksheets, layout scripts, and puzzle generators alike.

Input contract, sort order, response fields, and empty text

An empty string, a string of only spaces, or a string of only digits and punctuation also fails, because no letter-bearing word was found—the error message states that text must contain at least one word and that punctuation alone is not enough. Example: I am a poet of moonlight yields six words ordered I, a, am, of, poet, moonlight. Use text when a human needs a paste-ready line; use words and groups when an app will render buckets by length for a worksheet or a game board. POST a JSON body with the required string field text set to the passage you want sorted. Aliases input, value, s, content, and body are accepted so form generators and older clients can post under familiar names. The value must be a string; objects, arrays, booleans, and numbers fail with invalid_input naming the problem. Payloads longer than the documented character cap fail the same way so a single request cannot monopolize Worker memory. Those validation failures are not billed on the prepaid API. Optional order accepts asc for shortest to longest, which is the default, or desc for longest to shortest; aliases direction and dir are accepted. On success the response echoes original as the exact input, text as the sorted words joined with a single space, words as the ordered array, lengths as the matching letter counts, and count as how many tokens were sorted. shortest_length and longest_length report the extremes, groups lists each distinct length with the words that share it, order echoes the effective direction, and method is always sort_words_length so clients can branch without sniffing shapes.

Word games, poetry, linguistic workflows, pricing, and limits

Call the free in-browser sort-words-by-length tool when you need a hard ranking for word games, poetry, or linguistic exploration: a crossword coach can see which tokens fit a three-letter slot, a poet can scan a draft for a run of one-letter and two-letter words that speed the line, and a language teacher can show how a paragraph is built from short function words and longer content words. A typical workflow pastes a verse, reads groups to see the length histogram, and copies text back into a worksheet. Do not expect font metrics, kerning, syllable counts, or dictionary definitions—those depend on a typeface, a phonology, or a lexicon this parse path does not run. Use the prepaid KIT API when a tutoring app, CMS, or mobile client needs the same contract under balance at $0.002 per successful item; validation failures never consume balance after the engine rejects the request. Pair this endpoint with a word-count or unique-word review when the next step is volume or vocabulary analysis, but keep sort-words-by-length as its own landing so the shortest-to-longest intent is not mixed with alphabetical line sort or find-the-longest-word queries.

Classroom linguistics and fixtures

Teachers and build scripts pin the shortest-to-longest ranking so worksheets and tokenization regressions stay honest.

What does sorting words by length cost?

The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; empty or wordless input is not billed.

Read the full KIT documentation →