String Left Padder

Pads text on the left with a chosen character until it reaches a target length, the classic 'left-pad' operation used for zero-padded numbers, fixed-width IDs, and aligned columns. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-22

Overview

Introduction

Fixed-width identifiers, zero-padded invoice numbers, aligned numeric columns, all need text padded to a consistent length on the left.

This tool does that directly.

What Is String Left Padder?

A left-padding tool built on JavaScript's String.prototype.padStart(), adding your chosen character to the front of the text until it reaches the target length.

It runs entirely client-side as part of this site's String Tools collection, so nothing you paste is ever uploaded to a server.

How String Left Padder Works

The tool calls input.padStart(length, padChar); if the text is already at least that long, it's returned unchanged.

The transformation happens synchronously in JavaScript the moment you type, with no network round trip involved.

When To Use String Left Padder

Use it for zero-padding numeric IDs, generating fixed-width fields for a legacy file format, or aligning short codes in a table.

It's a fast way to get the answer without opening a code editor, a REPL, or writing a one-off script just to check.

Often used alongside String Right Padder and String Center Aligner.

Features

Advantages

  • Simple, predictable behavior matching the native padStart() method exactly.
  • Never truncates; only ever adds padding.
  • Delegates to the native padStart, so the specification's edge cases, including a target shorter than the input, behave exactly as they would in code.

Limitations

  • Pad character must be exactly one character.
  • Doesn't account for full-width or multi-byte characters when counting length.

Examples

Zero-padding a number

Input

7

Output

00007

With target length 5 and pad character '0', four zeros are added to the left.

Best Practices & Notes

Best Practices

  • Use Right-pad a String instead if you want padding added to the end.
  • Use Center a String if you want padding on both sides.
  • Choose a target length that accommodates your largest expected value, since a longer input comes back unpadded and quietly breaks fixed-width alignment.

Developer Notes

This is a thin wrapper around the native String.prototype.padStart(length, padChar), which already handles the edge cases (target length shorter than input, pad character repetition) correctly per spec.

String Left Padder Use Cases

  • Zero-padding invoice or order numbers to a fixed width
  • Generating fixed-width fields for a legacy flat-file format
  • Aligning short codes in a plain-text table

Common Mistakes

  • Supplying a multi-character pad string, which padStart() only partially repeats to fit.
  • Padding a value already longer than the target and assuming it was trimmed to fit; nothing is ever removed, only added.

Tips

  • Use '0' as the pad character for numeric IDs, or a space for text alignment.
  • Zero-padding keeps numeric IDs sorting correctly as text, which is why '00007' sorts before '00010' while an unpadded '7' sorts after '10'.

References

Frequently Asked Questions