Sort lines alphabetically
banana, apple, Cherry and apricot come back as Cherry, apple, apricot, banana: 4 lines sorted A to Z, with capitals first by default. Choose Z to A, or ignore capitals, when you need to. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Text
- banana apple Cherry apricot
- Text
- Cherry apple apricot banana
- Lines
- Cherry, apple, apricot, banana
- Quantity
- 4
- Order
- Asc
Sorting lines alphabetically is one of those small text jobs that still needs a clear contract: which characters define order, whether uppercase letters come before lowercase ones, how carriage returns and Windows line endings are treated, and what happens when the paste box is empty. This capability accepts non-empty multiline text, splits it on carriage return, line feed, or CRLF pairs, then reorders every line in ascending A–Z or descending Z–A order with an optional case-insensitive fold so Apple and apple group together.
What alphabetical line sorting means and when to use it
Alphabetical line sorting answers a search people type every day: sort lines alphabetically, put this list A to Z, or reverse the order from Z to A without opening a spreadsheet. This tool defines a line as a segment between line terminators. Terminators are carriage return, line feed, or the Windows-style carriage-return-plus-line-feed pair treated as a single break so a CRLF file is not double-split into empty rows.
After splitting, every segment participates in the sort, including blank lines and lines that are only spaces, because blank rows still have a position in a file and many editors keep them when you choose Sort Lines. Case-insensitive mode folds each line with Unicode default lowercasing before comparing, then tie-breaks on the original string and original index so the result stays stable when folds match. Prefer this sort-lines-alphabetically calculator when the intent is plain A–Z or Z–A over pasted text, README lists, glossary rows, or log snippets.
What you can do with it
Glossaries and name lists
Editors paste unsorted names or glossary terms, sort A–Z with optional case-insensitive order, and copy the joined text back into docs or CMS fields.
Changelog and packing-list cleanup
Teams reverse or alphabetize bullet lines before release notes, packing lists, or inventory pastes without opening a desktop editor sort plugin.
FAQ
What happens if text is empty?
A zero-length string is rejected and not charged; you must send at least one character of text.
Does case-insensitive sort treat Apple and apple as equal?
Ties break on the original string and original position for a stable result.
Is the sort lines alphabetically calculator free?
The browser tool runs free on your device.
How is this different from locale-aware list sort?
This capability sorts lines of plain text with deterministic code-unit or case-folded order. Locale-aware collators, accent rules, and numeric natural sort over item arrays are a separate product and search intent.
Why does Cherry come before apple?
By default capital letters sort ahead of lowercase ones, so any line starting with a capital rises to the top. Turn on the option that ignores case and Cherry moves to its alphabetical place after banana.
Related tools
For developers — API access
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.
API endpoint
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.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/str/sort-lines \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"text":"banana\napple\nCherry\napricot"}'const res = await fetch("https://api.kit.forhosting.com/str/sort-lines", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"text": "banana\napple\nCherry\napricot"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/str/sort-lines",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"text": "banana\napple\nCherry\napricot"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/str/sort-lines", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"text":"banana\\napple\\nCherry\\napricot"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"text":"banana\napple\nCherry\napricot"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/str/sort-lines", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"text": "banana\napple\nCherry\napricot"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "str.sort_lines",
"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.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
The response returns both a joined text block ready to copy and a structured lines array for APIs, plus counts and echoed options you can pin in tests. Empty input fails with invalid input so pipelines never store blank payloads by accident.
What alphabetical line sorting means and when to use it
Do not use it when you need locale-aware collation with accents, natural numeric order such as item 2 before item 12, or an array API with BCP-47 locale tags—that is a different product and a different search intent.
Input contract, empty rejection, order, and reading the response
Trailing newlines produce a trailing empty segment that sorts among other lines by string order, matching how many editors expose an extra empty row at the end of the file. Send a JSON body with the required string field text set to the non-empty sample you want sorted. Aliases input, value, s, content, body, and lines are accepted when older clients or form generators use those names. Missing text, a non-string value, or a zero-length string all raise invalid_input with a message that names the problem, and those failures are not charged on the prepaid API. Optional order accepts asc for ascending A–Z, which is the default, or desc for descending Z–A; aliases direction and dir are accepted. Optional case_insensitive is a boolean defaulting to false; aliases ignore_case and ci work the same way. On success the response includes text as the sorted lines joined with a single line feed character, lines as the ordered array of segments, and count as the number of segments after the split so you can assert length without re-parsing. order and case_insensitive echo the effective options after defaults so UIs can label the result without re-reading the request. original echoes the exact input for before-and-after displays, and method is always sort_lines so downstream code can branch without sniffing shapes. Use text when a human or clipboard needs one paste-ready block; use lines when an SDK will map each row into a table or database insert. Keep payloads to ordinary message and document sizes suitable for a Worker isolate rather than multi-megabyte dumps; this product is a text utility, not a bulk file warehouse.
API usage, pricing, workflows, and practical limits
Call the free in-browser sort lines alphabetically tool for glossary cleanup, packing lists, name lists, changelog bullets, and quick Z–A reverse checks without installing a desktop editor plugin or writing a one-liner in every language. A typical workflow pastes unsorted product names, sorts ascending case-insensitively, then copies the joined text field back into a spreadsheet or markdown table. Do not expect deduplication, natural numeric order, or language-specific accent rules here—those are separate problems with separate SEO terms. Authors shipping SDKs can document text as the only required field, show a multi-line success example with order desc, and include an empty-string error example so integrators see both sides of the contract. Use the prepaid KIT API when a CMS, content pipeline, QA harness, 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 line counting when the next step is reporting how many rows you sorted, but keep sort lines as its own landing so the sort-lines-alphabetically search intent is not mixed with locale list collation or full spreadsheet sort.
Integration use cases
CI fixtures for text pipelines
Build scripts pin sorted-line golden outputs so CRLF mishandling, empty-input regressions, or broken case folds fail continuous integration immediately.
Technical questions
How do I sort lines alphabetically with this tool?
Send JSON with text set to your non-empty multiline string. Optionally set order to asc or desc and case_insensitive to true or false. The response returns sorted text, a lines array, and count.