String padStart() and padEnd()
The padEnd() 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 end of this 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
right aligned. layout
PadEnd and padStart combination, reshi-t style. Output simul-tion..
PreviewFullscreen
Use cases
-
Using String padStart() and padEnd()
The padEnd() 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.
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.