Favorites

JavaScript String.prototype.padStart() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
String.prototype.padStart()
JavaScript String Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The padStart() method pads the start of a string with another string until it reaches a given length, such as adding leading zeros.

Description

The padStart() method adds characters to the start of a string until it reaches the target length. The classic use is adding leading zeros, as in times and dates, or masking all but the last digits of a card number.

If the string is already as long as the target length, or longer, it's returned unchanged; it's never truncated. A pad string of several characters is repeated and cut to fit, so '7'.padStart(5, 'ab') gives "abab7".

Numbers need to be converted to strings first, as in String(n).padStart(3, '0'). For formatting numbers with a minimum number of digits in a locale-aware way, Intl.NumberFormat with minimumIntegerDigits does the same job and also handles separators and other numbering systems.

Syntax

string.padStart(targetLength)
string.padStart(targetLength, padString)

Parameters

  • targetLengthThe length of the resulting string.
  • padStringOptional. The text to pad with. Defaults to a space.

Return Value

The string padded at the start to the target length.

Example

console.log('5'.padStart(2, '0'));
const d = new Date(2026, 0, 7);
console.log(String(d.getDate()).padStart(2, '0') + '/' + String(d.getMonth() + 1).padStart(2, '0'));
console.log('4242'.padStart(16, '*'));

Browser Support

The following information will show you the current browser support for the String.prototype.padStart() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee