ForHosting KIT · Developer Utilities

Center text in a chosen width

Center Text in Width formats every line independently inside the column width you choose.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

It adds ordinary spaces to the left and right, preserves blank lines, and returns a consistent rectangular text block that is easy to copy into a banner, terminal message, README, report, or other monospaced layout. When an odd number of spaces is needed, the extra space is placed on the right. The formatter never trims or rewrites your wording, and it reports an input error if the selected width is narrower than the longest line.

Choose a width that fits every line

Start by entering the text exactly as it should appear, including intentional blank lines and any spaces that already belong to the content. Then choose the total character width for each output row. The width must be at least as large as the longest line because this formatter only adds space; it does not wrap, shorten, crop, or overwrite text. A comfortably larger width creates visible margins, while a width equal to the longest line leaves that particular line unchanged. Character counts are based on Unicode code points, so an emoji or another supplementary character is treated as one character rather than two UTF-16 code units. Keep in mind that visual width still depends on the font and terminal: tabs, combining marks, and East Asian wide glyphs may occupy screen space differently. For the most predictable banner or console layout, use a monospaced font, replace tabs with spaces before formatting, and select a width that matches the destination column. If a line is too long, increase the width or edit the source deliberately instead of expecting hidden truncation.

Understand how the padding is divided

Each input line receives its own padding calculation. The formatter subtracts that line's character length from the requested width, places half of the available spaces on the left, and places the remainder on the right. When the available space is even, both sides match. When it is odd, the right side receives the single extra space. This fixed rule makes repeated runs deterministic and keeps lines aligned without arbitrary shifts. Existing characters, including leading and trailing spaces already present in a line, count toward its length and remain untouched. Line endings from Windows, macOS, or Unix input are recognized, while the returned block uses a consistent newline between rows. Empty lines are preserved and become rows made entirely of spaces, which is useful for framed notices and deliberately separated headings. Because every row reaches exactly the selected character width, the result can be placed inside ASCII borders, copied into source comments, or combined with other fixed-width content without calculating margins line by line.

Use the result safely in plain-text layouts

Review the returned lines before pasting them into their final destination, especially when the destination collapses whitespace. Plain-text files, code blocks, terminal output, and preformatted email sections normally preserve the padding, but ordinary HTML paragraphs and many rich-text editors may collapse consecutive spaces. In those environments, use a preformatted block or another whitespace-preserving container. The result includes both one joined text value and an array of individual lines, so an integration can copy the whole block or process rows separately. It also reports the chosen width and line count, which can help a script verify a layout. The operation is deterministic and local to the supplied text: it does not contact a network service, introduce random values, or attach timestamps. The listed base price is $0.002 when the capability is run through a paid channel, while eligible browser execution can use the same pure transformation. If the width is smaller than the longest line or a required field has the wrong type, correct that input and run the formatter again.

Console and terminal banners

Center a title, status message, or section heading within the known width of a terminal panel before adding borders or surrounding output.

README and code-block headings

Prepare balanced headings for Markdown code blocks, source comments, changelogs, and other whitespace-preserving documentation.

Fixed-width report layouts

Align multiline labels or cover-page text within a consistent column for exported reports, tickets, receipts, and plain-text templates.

What happens when the padding cannot be split evenly?

The left side receives the smaller half and the right side receives the extra space, so the rule is stable for every line.

Does the formatter wrap lines that exceed the width?

No. It returns an input error when the width is narrower than the longest line, preventing silent wrapping or data loss.

Are blank lines preserved?

Yes. Each blank input line becomes a line containing exactly the requested number of spaces.

Will the spaces remain visible after I paste the result?

They remain in plain text, but some rich-text and HTML contexts collapse repeated spaces. Use a preformatted or monospaced context there.

Does it preserve my existing leading and trailing spaces?

Yes. Existing spaces are treated as part of each line, and only the additional spaces needed to reach the chosen width are added.

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/center-text

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/center-text \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text":"QUARTERLY REPORT\nRevenue overview","width":24}'
{
  "text": "QUARTERLY REPORT\nRevenue overview",
  "width": 24
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "str.center_text",
  "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.

Read the full KIT documentation →