Skip to tool

JavaScript Pad string Online

Pad string to length.

The output updates as you type. The tool processes input in your browser.

Worked example

Width is a minimum size. The tool preserves longer strings and applies the fill to the selected side.

Pad length
8
Pad string
"0"
Pad type
"STR_PAD_LEFT"
Sample input
42
Sample output
00000042

Using this operation in JavaScript

The interactive result uses JavaScript. JavaScript string indexes count UTF-16 code units. Use code-point iteration when working with supplementary Unicode characters.

JavaScript reference