Truncate text
Set a limit of 20 and The quick brown fox jumps over the lazy dog becomes The quick brown f..., exactly 20 characters with the dots included. Text that already fits comes back unchanged. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Text
- The quick brown fox jumps over the lazy dog
- Length
- 20
- Input
- The quick brown fox jumps over the lazy dog
- Text
- The quick brown f...
- Original length
- 43
- Result length
- 20
A text truncator shortens a string to a maximum display length and appends an ellipsis when the original does not fit. Enter the plain text and the integer length you want the result to respect; the tool returns the shortened string, whether truncation was applied, the original and result lengths, and a short message. Optionally enable word-boundary mode so the cut prefers the last space before the limit instead of splitting a word mid-token. Previews, table cells, card titles, SEO snippets, chat bubbles, and notification copy all need that same hard length rule without opening a full editor or calling a rewrite model.
What truncate with ellipsis means versus rewrite or trim
Truncation is a hard display constraint: keep a prefix of the source string and, when the source is longer than the allowed length, mark the omission with an ellipsis suffix. That is different from trimming whitespace, which only cleans edges, and different from AI shortening, which rewrites meaning into fewer words. Here the maximum length is the maximum length of the entire result including the ellipsis when a cut is required.
If your text already fits, the tool returns it unchanged and sets truncated to false so callers can skip UI affordances that imply more content is hidden. Lengths below one are never accepted: a zero-width preview is not a useful contract for cards, tables, or notifications, and negative limits are always client bugs. Empty text with a valid length is allowed and returned as empty without an ellipsis, which keeps pipelines that pass optional fields from failing only because a title is blank.
What you can do with it
Card titles and table cell previews
Clamp product names and list rows to a fixed character budget with a visible ellipsis so dense UIs stay aligned without mid-layout overflow.
FAQ
Does the length include the ellipsis?
Yes. When truncation applies, the returned string is at most length characters long including the ellipsis suffix. If the original already fits, it is returned unchanged without adding an ellipsis.
What happens if length is zero or negative?
Length must be an integer of at least one; limits below one are rejected and never charged.
Is this the same as AI text shortening?
No. This capability is a deterministic prefix cut with an ellipsis. It does not rewrite meaning. Use an LLM shorten tool when you need compressed paraphrase instead of a hard display clamp.
Is the truncate text tool free?
The browser tool is free and runs locally.
Can I avoid cutting a word in half?
Yes. Turn on the word-boundary option and the cut moves back to the last space before the limit, so the result ends on a whole word. If there is no space to fall back on, the text is cut at the limit.
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/truncate \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"text":"The quick brown fox jumps over the lazy dog","length":20}'const res = await fetch("https://api.kit.forhosting.com/str/truncate", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"text": "The quick brown fox jumps over the lazy dog",
"length": 20
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/str/truncate",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"text": "The quick brown fox jumps over the lazy dog",
"length": 20
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/str/truncate", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"text":"The quick brown fox jumps over the lazy dog","length":20}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"text":"The quick brown fox jumps over the lazy dog","length":20}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/str/truncate", 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": "The quick brown fox jumps over the lazy dog",
"length": 20
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "str.truncate",
"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_chars | 100000 |
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
A length below one is rejected with a clear invalid_input error so form validation and CI never treat a zero or negative cap as success.
What truncate with ellipsis means versus rewrite or trim
If it does not fit, the solver computes a content budget equal to length minus the ellipsis length, takes a prefix up to that budget, optionally backs up to the previous whitespace when word_boundary is true, strips trailing spaces from the kept prefix so the ellipsis does not sit after a dangling gap, and concatenates the ellipsis.
How to call the API and what the response contains
Send a JSON body with required text (aliases input, value, string, s, content, and body) and required length (aliases max_length, max, n, limit, and max_len). Length must be an integer from one through one hundred thousand inclusive; values below one, non-integers, and oversize limits are invalid_input. Optional word_boundary (aliases word, soft, on_word) defaults to false and accepts boolean true or false. Optional ellipsis (aliases suffix, ending, marker) defaults to three ASCII dots and may be any string up to thirty-two characters; when truncation is required the ellipsis must not be longer than length or the request fails rather than inventing a clipped marker. Text must stay within one hundred thousand characters so a single request cannot exhaust Worker or browser memory. On success the response echoes input as the original string, text as the final string to display, length as the requested maximum, original_length and result_length as character counts, truncated as a boolean, word_boundary as the flag you sent (or default), ellipsis as the suffix used, used_word_boundary when a soft cut was applied, and message as a short English summary. Failed validation—missing text or length, a non-string text, a non-integer or sub-one length, an oversize payload, or an ellipsis that cannot fit under the limit when a cut is needed—returns invalid_input and is never charged. Pricing is a flat $0.002 per successful request with unit item and zero marginal unit price.
Practical tips, limits, and related searches
Use this capability when the search intent is truncate text, add ellipsis at max length, or soft-cut on a word boundary online. Custom ellipsis such as a single Unicode horizontal ellipsis character or a bracketed more label works when its length still fits inside the budget. This landing is not an AI summarizer, not a paragraph or word counter, not a title-case converter, and not a trimmer of line edges only. Round-trip checks for tests are easy: feed a long sentence with length twenty and expect truncated true and result_length at most twenty; enable word_boundary on a multi-word phrase and expect the last kept character not to sit inside a word when a space existed earlier; send length zero or a negative integer and expect invalid_input mentioning length below one. Prefer a hard cut when you need a fixed character grid such as monospace logs; prefer word_boundary for human-facing titles and previews where mid-word breaks look broken. Prefer text.shorten when you need meaning-preserving compression under a word budget with a language model; prefer str.trim_lines when you only need per-line whitespace cleanup; prefer this capability when the product already decided a hard maximum display length and must show a faithful prefix. Failed tasks that return invalid_input do not consume prepaid balance, which keeps form validation and CI negative tests cheap. When teaching reviewers, show the same sentence under hard and soft modes so they see that only the cut position and used_word_boundary flag change while the ellipsis rule stays the same.
Integration use cases
Notification and chat snippet limits
Shorten outbound push and in-app messages to platform length caps while optionally avoiding mid-word cuts on word_boundary mode.
Unit tests for display formatters
Generate known-good hard and soft truncations plus length-below-one rejections for frontend helpers and CMS preview pipelines.
Technical questions
What does word_boundary do?
When true, the cut prefers the last whitespace before the content budget so words are not split mid-token. If no suitable space exists, it falls back to a hard character cut.