Line length statistics
Get the four numbers that describe how wide your lines are: in a three-line sample, the shortest has 5 characters, the longest 22 and the median 10, alongside the average. Spot the line that will break a layout without eyeballing the file. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Text
- short a somewhat longer line mid length
- Lines
- 3
- Min
- 5
- Max
- 22
- Average
- 12.333333
min, max, average and median line length
What the four numbers tell you
Each statistic answers a different question about your text. The minimum line length catches the short end: blank separators, one-word lines, or a stray fragment left after an edit. The maximum line length catches the long end, which is what breaks layouts, terminal panes, email clients and code review tools that assume a column budget.
The average gives you the typical size, useful when you compare two versions of the same document or check whether a rewrite actually tightened the prose. And the median tells you where the middle line sits, which is more robust than the average when a few extreme lines would drag the mean around.
Read together, min and max give the spread, while average and median together reveal skew: if the average is well above the median, a handful of very long lines are pulling the text up, and you probably want to find them.
How lines and lengths are counted
The text is split into lines on any of the usual line endings — LF, CR or CRLF — so files from Unix, classic Mac and Windows systems all measure the same way. Length is counted in characters, exactly as the string holds them: no trimming, no collapsing of whitespace, no exclusions. An empty line between two paragraphs counts as a line of length zero, and a line of trailing spaces counts every one of those spaces, because that is the honest width of what you sent.
The average and the median are rounded to six decimal places so the result is identical on every machine, which matters when you compare outputs across runs or store them in an audit trail.
Where it fits in real workflows
Teams wire line length statistics into checks that would otherwise be manual eyeballing. A documentation pipeline verifies that code samples stay inside an 80-column budget before publishing; a data pipeline profiles incoming fixed-width files and rejects a feed whose record length suddenly changes; a publishing workflow confirms that a plain-text newsletter wraps the way the template expects. Nothing you send is kept: the text is measured and discarded, and only the four numbers come back.
For counting lines rather than measuring them, pair it with a line counter; for enforcing a width, pair it with a text wrapper that re-breaks the lines to the column you choose.
What you can do with it
Audit a log or data feed
Profile an incoming fixed-width or CSV-like file and alert when the maximum line length drifts from the record size the parser expects.
Enforce a column budget
Check that code samples, READMEs or plain-text emails stay within an 80-column limit before they are published or sent.
Compare drafts of a document
Track average and median line length across revisions to see whether an edit actually tightened the text or just moved words around.
FAQ
What exactly counts as a line?
The text is split on LF, CR or CRLF line endings. Every segment counts, including empty lines, which measure as length zero.
Is whitespace trimmed before measuring?
No. Lengths are counted in characters exactly as sent, so leading and trailing spaces are included in each line's length.
How are the average and median rounded?
Both are rounded to six decimal places so results are stable and byte-identical across machines and runs.
Is my text stored?
No. It is measured and discarded; only the four statistics are returned.
What does it mean when the average is well above the median?
It means a handful of very long lines are pulling the average up. The median sits on the middle line and barely moves with extreme lines, so a big gap is a sign to go and find those long ones.
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/text/line-length-stats \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"text":"short\na somewhat longer line\nmid length"}'const res = await fetch("https://api.kit.forhosting.com/text/line-length-stats", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"text": "short\na somewhat longer line\nmid length"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/text/line-length-stats",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"text": "short\na somewhat longer line\nmid length"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/text/line-length-stats", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"text":"short\\na somewhat longer line\\nmid length"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"text":"short\na somewhat longer line\nmid length"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/text/line-length-stats", 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": "short\na somewhat longer line\nmid length"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "text.line_length_stats",
"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.
Limits
max_mb | 5 |
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 line length statistics API reads a multi-line text and returns, in a single call, the four numbers that describe how its lines are sized: the shortest line, the longest line, the average line length and the median line length, all counted in characters. It is the quickest way to answer questions like how wide a log file really is, whether a poem keeps a steady meter, or whether a wrapped document respects its target column width — without loading the text into an editor and eyeballing it. Paste the text and you get the profile; automate it and the same code runs on the edge for $0.002 per request.
How lines and lengths are counted
The only input that is rejected is a text with no lines at all — an empty string — because there is nothing meaningful to measure; in that case you get a clear invalid_input error and the request is not billed.
Where it fits in real workflows
Because the same code runs free in your browser and on the API, you can prototype the check by pasting a sample on this page and only pay — $0.002 per request — once you automate it.
Technical questions
What does it cost?
$0.002 per request. It is also free to run in your browser on this page.
What happens if the text is empty?
An empty string has no lines, so the request fails with an invalid_input error and is not billed.