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.
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 |
Syntax
// Pad with zeros
'5'.padStart(3, '0'); // '005'
'42'.padStart(3, '0'); // '042'
// Right-align
'hello'.padEnd(10, '.'); // 'hello.....' Live demo
right aligned. layout
PadEnd and padStart combination, reshi-t style. Output simul-tion..
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.
Related links
Powered by web-features