Find longest line
Paste text and see which line is the widest: in a three-line sample, line 2 wins with 29 characters. Check code against eighty- or hundred-twenty-column rules, plan table columns or test a log paste before it wraps. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Text
- short this is the longest line here mid
- Longest line
- this is the longest line here
- Length
- 29
- Line number
- 2
- Total lines
- 3
Finding the longest line is a small measurement with a clear product job: you paste multi-line text and learn which row is the widest in characters and exactly how long it is. Developers use that number to enforce style guides such as eighty or one hundred twenty columns, data people use it to size tables and CSV previews, and operators use it before dumping logs into a terminal that will wrap or truncate. Empty input is rejected with invalid input so pipelines never store silent zero-length scans.
What longest-line length means and how lines are measured
A longest-line report answers a search intent that is different from counting how many lines exist or how many words a document contains. People type find longest line, max line length, or longest line character count when they care about width, not cardinality. This tool defines a line as a segment between line terminators.
Terminators are carriage return, line feed, or a carriage-return-plus-line-feed pair treated as a single break so a CRLF file is not double-split. After splitting, each segment is measured with JavaScript string length, which counts UTF-16 code units the same way browser textareas and most KIT string utilities do. That means ordinary ASCII and Latin-1 characters count as one, and many emoji or rare symbols may count as two code units—the same contract you already accept in other free text tools here.
Total_lines is the number of segments after the split, including a trailing empty segment when the text ends with a newline, matching how editors often show an extra empty row at the end of a file. Character_count is the full original string length for a quick size check next to the per-line maximum. Prefer this find-longest-line calculator when the job is style limits, table column planning, or terminal formatting width.
Do not use it when you only need total line counts, word counts, or byte sizes of binary files—those are separate landings.
What you can do with it
Code style and column budget checks
Developers paste source or diffs to see the longest line length against eighty or one hundred twenty column style rules before review.
Table and CSV preview layout
Analysts measure the widest row in sample tables so UI columns and export previews avoid unexpected horizontal overflow.
Terminal and log paste formatting
Operators check support pastes and log excerpts for max line width before dumping them into terminals that wrap or truncate.
FAQ
What happens if text is empty?
A zero-length string is rejected and not charged; whitespace-only text is allowed and measured.
Is the longest line finder free?
The browser tool runs free on your device.
How are CRLF and LF handled?
Carriage return, line feed, and CRLF pairs are all treated as line breaks. CRLF counts as a single break so Windows-style files are not double-split.
What happens when two lines have the same length?
The topmost one is reported. The first line that reaches the maximum keeps the title, so the line number you get stays the same every time you run the same text.
Do emoji count as one character?
Not always. Length is counted the way browser text boxes count it: ordinary letters count as one, while many emoji and rare symbols count as two, so a line full of emoji may look shorter than reported.
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/longest-line \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"text":"short\nthis is the longest line here\nmid"}'const res = await fetch("https://api.kit.forhosting.com/str/longest-line", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"text": "short\nthis is the longest line here\nmid"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/str/longest-line",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"text": "short\nthis is the longest line here\nmid"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/str/longest-line", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"text":"short\\nthis is the longest line here\\nmid"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"text":"short\nthis is the longest line here\nmid"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/str/longest-line", 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\nthis is the longest line here\nmid"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "str.longest_line",
"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
This capability splits on carriage return, line feed, or Windows-style CRLF pairs, measures each line with the same JavaScript string length browsers and Worker isolates already use, and returns the first maximum so ties stay stable in tests. The free browser tool runs on your device; the prepaid API charges $0.002 per successful item when servers need the same contract in bulk.
What longest-line length means and how lines are measured
The winning line is the first segment whose length is strictly greater than every previous maximum, so when two lines share the same length the topmost one is reported and line_number is stable.
Input contract, empty rejection, and reading the response fields
Send a JSON body with the required string field text set to the non-empty sample you want scanned. Aliases input, value, s, content, and body 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. Whitespace-only text is allowed: it is not empty input, and a single blank line correctly reports length zero with that blank segment as longest_line. Extremely large payloads above the soft character ceiling are rejected so a Worker isolate stays responsive; ordinary source files, logs, and drafts fit comfortably. On success the response includes longest_line as the exact characters of the winning row, length as that row’s character length, line_number as a one-based index for jump-to-line UIs, total_lines as the segment count, character_count for the whole paste, original as an echo so UIs can show before-and-after tables without re-storing the payload, and method always set to longest_line so downstream code can branch without sniffing shapes. Use length alone when a linter-style gate only needs the max width; use longest_line when a reviewer must see which row broke the budget; use line_number when an editor should scroll to the offender. 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 find longest line tool for homework style checks, paste-bin audits, README width reviews, and quick terminal formatting checks without writing another split-and-max one-liner in every language. Another workflow sizes table previews: feed CSV or markdown rows, learn the max cell-line width, and choose column layouts that avoid horizontal scroll. Do not expect display-column measurement for tabs, word wrapping, or font metrics—those are presentation problems outside this character-length contract. Authors shipping SDKs can document text as the only required field and show a multi-line success example plus 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. A typical workflow pastes a source file, reads length against an eighty or one hundred twenty column policy, then shortens the reported longest_line before commit. Pair this endpoint with line counters or word counters when the next step is broader text statistics, but keep find longest line as its own landing so the max-line-length search intent is not mixed with total line counts or full document word metrics.
Technical questions
How do I find the longest line in text with this tool?
Send JSON with text set to your non-empty string. The response returns longest_line, length, line_number, total_lines, and character_count.
What if two lines have the same maximum length?
The first (topmost) line wins. line_number points to that first maximum so results stay stable for tests and UIs.