Skip to content
ZeroServer.tools

Text Padding Tool

Pad every line to a fixed width with any fill character — left, right, or center aligned.

Padding Configuration
Lines: 0Characters: 0

How text padding works

Text padding ensures every line is a fixed width, filling empty space with a chosen character. Left-padding (fill right) creates a ragged-right format; right-padding creates right-aligned columns like a table; center-padding centres each line. This is useful for ASCII art, generating fixed-width log output, aligning code comments, or building plain-text tables.

To split text before padding, use the String Splitter. For line-number prefixes, see Add Line Numbers.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Aligning a column of values for fixed-width output.
  • Padding labels so an ASCII table's borders line up.
  • Producing fixed-width records for a legacy importer.
  • Centring a caption inside a fixed-width banner so the borders stay square.
  • Aligning code comments across several lines.

Frequently Asked Questions

What is padding used for?
Fixed-width formats: legacy mainframe records, COBOL layouts, some bank files, and aligning console output into columns. In these formats field position IS the schema, so padding is structural rather than cosmetic.
When do I pad left versus right?
Numbers pad LEFT with zeros or spaces so digits align by place value; text pads RIGHT with spaces so it reads naturally. Getting this backwards makes a numeric column unreadable and breaks fixed-width parsing.
What happens if the content is longer than the width?
A real decision: truncate and lose data, or overflow and break the alignment. Fixed-width formats usually require truncation, which is why field lengths must be validated before writing rather than after.
Does padding work with non-ASCII text?
Not by character count alone. CJK characters are double-width in a monospace terminal, so padding to 10 characters produces a column twice as wide. Alignment needs display width, not string length.
Is this the same as padStart in JavaScript?
The same operation — padStart and padEnd take a target length and a pad string. They count UTF-16 code units, so an emoji counts as 2 and a combining sequence counts every part, which misaligns visually.
Why does padded text misalign in a terminal?
Because padding counts characters and a terminal renders columns. CJK characters and many emoji occupy two columns, so a correctly padded string can still look ragged — alignment needs display width, not length.
What is padding with a character other than a space for?
Fixed-width record formats and cheque-style protection, where a zero-padded number keeps its field width and a dot leader guides the eye across a gap. The choice belongs to the format, not to the tool.

Common errors and gotchas

  • Padding with spaces where the destination expects a specific fill character, such as zeros.
  • Padding by character count when the display measures width, which differs for wide characters.
  • Truncating rather than padding when a line already exceeds the target width.
  • Padding text that a downstream system trims, which undoes the alignment.
  • Aligning in a proportional font, where equal character counts are not equal widths.

Related Text Tools tools

Private & free — this tool runs entirely in your browser.