Widely availableSupported across all major browsers. Safe to use in production.

Overview

The padStart() and padEnd() methods of strings return a string lengthened to a minimum number of characters by adding characters to the start or end of the string.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
57
15
48
10
57
10
Built-in object

The padStart() method of String values pads this string with a given string (repeated and/or truncated, if needed) so that the resulting string has a given length. The padding is applied from the start of this string.

57
15
48
10
57
10
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

JAVASCRIPT
// Pad with zeros
'5'.padStart(3, '0');    // '005'
'42'.padStart(3, '0');   // '042'

// Right-align
'hello'.padEnd(10, '.');  // 'hello.....'

Live demo

Number. rofill

PadStart Usenumber 3 digit(001shape notation) to format..

PreviewFullscreen

info. msking

.. with Phonenumber. bottom4 digit except *.

PreviewFullscreen

right aligned. layout

PadEnd and padStart combination, reshi-t style. Output simul-tion..

PreviewFullscreen

Use cases

  • Using String padStart() and padEnd()

    The padStart() and padEnd() methods of strings return a string lengthened to a minimum number of characters by adding characters to the start or end of the string.

Cautions

  • No specific concerns. Stable across all major browsers.

Accessibility

  • When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.

Powered by web-features