String.prototype.padEnd() pads a string from the end until it reaches a target length (same API as MDN String.prototype.padEnd()). Learn the default space pad, how padString repeats or truncates, when the original string is returned unchanged, how it compares to padStart(), five examples, and try-it labs.
01
Kind
Instance method
02
Returns
New string
03
Pads
Right / end
04
Default pad
Space (" ")
05
Mutates?
No
06
Baseline
Widely available
Fundamentals
Introduction
Need a string of a fixed width — for example dotted leaders, fixed-width columns, or short codes padded with spaces? padEnd() adds characters after your text until the result reaches targetLength.
The filler is optional. Omit it and JavaScript uses a single space. Provide a longer filler and it is repeated (and trimmed) to fill the gap. If the string is already long enough, nothing is added.
💡
Beginner tip
padEnd = pad on the right. padStart = pad on the left. Same length rules for both.
When no padding is possible or needed, you get the original text back. Successful pads always yield result.length === targetLength (measured in UTF-16 code units).
Applications
🚀 Common Use Cases
Dotted leaders — title.padEnd(40, ".") for menus or receipts.
Fixed-width logs — align labels before values in console output.
Table-like text — pad cells so columns line up in monospace fonts.
Display formatting — fill short codes or tags to a shared width.
Not for visual width — emoji / wide glyphs may look uneven; length is code units.
Left padding — use padStart() for leading zeros and right-aligned numbers.
🧠 How padEnd() Builds the Result
1
Read length + filler
Take targetLength and optional padString (default space).
Input
2
Compare lengths
If already long enough (or filler is empty), return the original text.
Guard
3
Fill the end
Repeat and/or truncate padString until the gap is filled.
Pad
4
✅
Return a new string
Original text first, filler last — str itself never changes.
Important
📝 Notes
padEnd() pads on the right; padStart() pads on the left.
Default filler is one space character.
If targetLength <= str.length, the string is returned unchanged.
Long fillers are truncated; short fillers are repeated.
Empty padString cannot add characters.
Length uses UTF-16 code units — same as str.length.
Compatibility
Browser & Runtime Support
String.prototype.padEnd() is Baseline Widely available — supported across modern browsers since April 2017.
✓ Baseline · Widely available
String.padEnd()
Safe for production. Use padEnd for right-side padding; padStart for left-side padding.
UniversalWidely available
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
padEnd()Excellent
Bottom line: Use String.padEnd() when you need a fixed width with filler on the right. Remember the default space, truncation rules, and that length is measured in UTF-16 code units.
Wrap Up
Conclusion
String.prototype.padEnd() is the clear way to grow a string to a target length by adding characters at the end. Reach for it for leaders, columns, and fixed-width text — and switch to padStart() when the filler belongs on the left.
Use monospace fonts when aligning columns in the UI
Prefer padStart() for leading zeros on numbers/IDs
Check str.length when debugging unexpected widths
❌ Don’t
Expect padding when targetLength is too small
Pass an empty padString and expect filler
Assume length equals visual width for all Unicode
Mutate strings — always capture the returned value
Hand-roll padding loops when padEnd already fits
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about String.padEnd()
Right-side padding to a target length.
5
Core concepts
📝01
Side
end / right
API
🔎02
Default
space
Rule
✂️03
Filler
repeat / truncate
Fill
⚡04
vs padStart
right vs left
Compare
📄05
Mutates
no
Immutable
❓ Frequently Asked Questions
String.prototype.padEnd(targetLength, padString?) returns a new string padded at the end so its length reaches targetLength. The default padString is a single space.
If targetLength is less than or equal to str.length, padEnd() returns the original string unchanged (as a new string with the same contents).
padString is truncated from the end so the result length equals targetLength. For example "abc".padEnd(6, "123456") returns "abc123".
padEnd adds padding after the text (on the right). padStart adds padding before the text (on the left). Both use the same length and padString rules.
No. Strings are immutable. padEnd() returns a new padded string.
padEnd uses UTF-16 code-unit length (same as str.length). Some emoji use two code units, so visual width and .length can differ — pad carefully with Unicode-heavy text.
Did you know?
padStart and padEnd arrived together in ES2017. Before that, developers often wrote helpers with while loops or Array(n + 1).join(pad) — both are easy to get slightly wrong on truncation.