Pad text
Stretch text to a fixed width with a fill character on the left, the right or both sides: 42 padded to 6 with zeros on the left becomes 000042. Ideal for invoice numbers, IDs and aligned columns. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Text
- 42
- Width
- 6
- Which side
- Left
- Char
- 0
- Result
- 000042
- Original length
- 2
- Length
- 6
- Pad count
- 4
Padding a string means extending it to a fixed character width by inserting a chosen fill character on the left, the right, or both sides at once. This tool takes the text you enter, a non-negative integer target width, a side selector (left, right, or both for center pad), and an optional single fill character that defaults to a space, then returns the padded result plus pad counts and lengths. Classic jobs include zero-padding invoice numbers and IDs, right-aligning labels in monospaced logs, and centering titles in fixed-width banners.
How string padding works
The engine measures the input text length in JavaScript string units, then computes how many fill units are still needed to reach the target width. When more width is available, the fill character—exactly one Unicode code point, defaulting to a space—is repeated to build the missing segment. Left padding prefixes the fill run, which is the usual path for zero-padded numeric codes such as turning forty-two into 000042 at width six.
Right padding suffixes the fill run, useful for blank-padded fields in fixed-width export files and monospaced table cells. Both (center) padding splits the budget with floor of need over two on the left and the remainder on the right, which keeps odd remainder characters on the right and produces a stable, deterministic center layout. Empty text is allowed so you can generate pure fill strings of a given width.
What you send and what you get back
Send required fields text, width, and side. Side must normalize to left, right, or both—start and l map to left, end and r to right, center, centre, c, and middle to both. Numbers and booleans for text are coerced to decimal or true/false strings; objects, arrays, NaN, and Infinity are rejected.
Classic checks include text forty-two, width six, side left, char zero becoming 000042; hello with width ten and side right and space becoming hello plus five spaces; and center padding of ab to width five with star characters producing star ab star star. Wire the free browser form for quick paste-and-copy work, then call the identical contract from scripts when you normalize fixed-width records, align log columns, or mint zero-padded identifiers in bulk.
If your pipeline later needs truncation, wrapping, or multi-character fill patterns, treat those as separate tools rather than overloading this pad-text landing.
Where text padding shows up in real work
Finance and operations teams zero-pad invoice numbers, store SKUs, and ticket IDs so lexicographic sort matches numeric order in spreadsheets and CSV exports. Backend engineers build fixed-width legacy file layouts where every field must occupy a declared column count with space or zero fill on a chosen side. Data and analytics pipelines right-pad labels before monospaced console tables and left-pad integers before joining keys that assume equal string length.
Product and growth teams center short titles inside fixed-width banners, receipts, and thermal printer lines where alignment is visual rather than semantic. Prefer this page when the search intent is literally pad text, left pad, right pad, center pad, or zero-pad a string; if you need base64, hashing, or case conversion, use the dedicated tools instead of stretching this capability beyond its contract.
What you can do with it
Zero-pad IDs and invoice numbers
Left-pad numeric codes with zeros to a fixed width so lexicographic sort matches numeric order in CSVs and reports.
Fixed-width file fields
Space-pad left or right to exact column widths required by legacy fixed-width export and import layouts.
Center titles in monospaced banners
Pad both sides with a fill character to center short labels inside fixed-width logs, receipts, and CLI headers.
FAQ
Can I pad on both sides (center)?
Yes. Set side to both (or center). The pad budget is split with floor(need/2) on the left and the remainder on the right.
What fill characters are allowed?
The default is a space. Common choices are 0 for zero-padding and * or - for visual banners.
Is empty text allowed?
Yes. Empty text with a positive width returns a pure fill string of that width, which is useful for generating separator lines.
What does it cost?
The browser tool is free and runs locally.
What happens if the width is smaller than my text?
The tool stops instead of cutting your text, so nothing is lost by accident. If the width equals the text length, you get the text back unchanged with no fill added.
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/pad \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"text":"42","width":6,"side":"left"}'const res = await fetch("https://api.kit.forhosting.com/str/pad", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"text": "42",
"width": 6,
"side": "left"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/str/pad",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"text": "42",
"width": 6,
"side": "left"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/str/pad", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"text":"42","width":6,"side":"left"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"text":"42","width":6,"side":"left"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/str/pad", 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": "42",
"width": 6,
"side": "left"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "str.pad",
"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
When the requested width is smaller than the text length the request fails with a clear validation error instead of silently truncating, so clients never lose data by accident. No network round-trips inside the engine, no random seeds, and no clock dependence—identical text, width, side, and character always produce identical JSON.
How string padding works
If the width is strictly smaller than that length, validation fails with invalid_input and no result is returned, because silent truncation would destroy user data. When the width equals the length, the original string is returned unchanged with pad_count zero. Extremely long payloads above the documented character cap, or a width above the documented maximum, also fail with invalid_input so a single request cannot monopolize Worker memory.
What you send and what you get back
Text is the string to pad; aliases such as input, value, data, s, message, string, content, and body are accepted for older clients. Width is a non-negative integer target length; aliases target, length, size, and n work when width is omitted. Optional char (aliases pad_char, fill, pad) is a single character; omit it to pad with spaces. On success the response echoes text, width, side, and char, plus result, original_length, length of the padded string, pad_count, pad_left, pad_right, and operation set to pad. Pricing for successful API calls is the published base of $0.002 per item; validation failures including width below text length do not consume prepaid balance.
Where text padding shows up in real work
Because this capability is a pure parse engine, API pricing is the published base of $0.002 per successful item and failed validation does not consume balance.
Technical questions
What happens if the width is smaller than the text?
The request fails with invalid_input. This tool never truncates; target width must be greater than or equal to the text length.