ForHosting KIT · Text & AI

Pad string center

Center text inside a fixed-length field: hi centered to 8 characters with stars becomes ***hi***, three on each side. When the split is uneven, the extra character goes on the right. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Text
hi
Length
8
Char
*
You get
Result
***hi***
Original length
2
Result length
8
Pad count
6

Center-padding a string means extending it to a fixed character length by inserting a chosen fill character evenly on both sides so the original text sits in the middle of the field. This pad-string-center tool takes the text you enter, a non-negative integer target length, and an optional single fill character that defaults to a space, then returns the centered result plus left and right pad counts. Classic jobs include centering titles in monospaced banners and CLI headers, balancing labels inside fixed-width receipts or thermal printer lines, and building decorative separator rows with a short word in the middle.

How center 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 length. When more length is available, the fill character—exactly one Unicode code point, defaulting to a space—is repeated to build the missing segment. Center padding always splits the pad 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 every time.

Empty text is allowed so you can generate pure fill strings of a given length for separator lines. Prefer this landing when the search intent is specifically center-pad or center-align text inside a fixed field rather than choosing left or right pad sides.

What you send and what you get back

Send required fields text and length. Numbers and booleans for text are coerced to decimal or true/false strings; objects, arrays, NaN, and Infinity are rejected. Classic checks include text hi with length eight and char star becoming three stars, hi, three stars; hello with length eleven and default space becoming three spaces, hello, three spaces; and ab with length five and star producing one star, ab, two stars because the remainder sits on the right.

Wire the free browser form for quick paste-and-copy work, then call the identical contract from scripts when you center labels in fixed-width records, monospaced logs, or receipt layouts. If your pipeline needs left-only or right-only padding, use the general pad-text tool rather than overloading this center-only landing.

Where center-padding strings shows up in real work

Product and growth teams center short titles inside fixed-width banners, email plain-text headers, and in-app monospaced previews where alignment is visual rather than semantic. Backend engineers build decorative CLI headers and log section dividers with a label centered between fill characters such as equals signs or dashes. Retail and operations stacks format thermal receipt lines and ticket stubs so store names and totals sit centered in a fixed column width.

Data and analytics notebooks center short axis labels or table captions before dumping monospaced console tables. Prefer this page when the search intent is pad string center, center pad string, center align text in a fixed width field, or pad both sides of a short label; if you need left pad, right pad, base64, hashing, or case conversion, use the dedicated tools instead of stretching this capability beyond its contract.

Center titles in monospaced banners

Pad both sides with spaces, stars, or dashes so short labels sit centered inside fixed-width logs, CLI headers, and plain-text banners.

Receipt and ticket lines

Center store names and section titles in thermal printer or POS layouts that require an exact character column count.

How is an odd pad budget split?

Left gets floor(need/2) fill characters and right gets the remainder, so odd leftovers always land on the right for a stable center layout.

What fill characters are allowed?

The default is a space. Common choices are *, -, =, or 0 for visual banners and codes.

Is empty text allowed?

Yes. Empty text with a positive length returns a pure fill string of that length, which is useful for generating separator lines.

What does it cost?

The browser tool is free and runs locally.

What if the length is shorter than my text?

The tool stops rather than cutting your text, so nothing disappears by accident. If the length equals the text length, the text comes back unchanged with no fill.

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.

POSThttps://api.kit.forhosting.com/str/pad-center

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.

curl -X POST https://api.kit.forhosting.com/str/pad-center \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text":"hi","length":8}'
{
  "text": "hi",
  "length": 8
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "str.pad_center",
  "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.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

When the requested length 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, length, and character always produce identical JSON.

How center padding works

If the length is strictly smaller than that text length, validation fails with invalid_input and no result is returned, because silent truncation would destroy user data. When the length equals the text length, the original string is returned unchanged with pad_count zero. Extremely long payloads above the documented character cap, or a length 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 center-pad; aliases such as input, value, data, s, message, string, content, and body are accepted for older clients. Length is a non-negative integer target total character count; aliases width, target, size, and n work when length is omitted. Optional char (aliases pad_char, fill, pad, padding) is a single character; omit it to pad with spaces. On success the response echoes text, length, and char, plus result, original_length, result_length of the padded string, pad_count, pad_left, pad_right, and operation set to pad_center. Pricing for successful API calls is the published base of $0.002 per item; validation failures including length below text length do not consume prepaid balance.

Where center-padding strings 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.

Fixed-width field formatting

Build center-aligned fixed-length fields for exports, previews, and fixtures without writing ad-hoc pad math in every script.

What happens if the length is smaller than the text?

The request fails with invalid_input. This tool never truncates; target length must be greater than or equal to the text length.

Read the full KIT documentation →