String.prototype.trimStart() returns a new string with whitespace removed from the start only (same API as MDN String.prototype.trimStart()). Learn the trimLeft alias, how it differs from trim() / trimEnd(), five examples, and try-it labs.
01
Kind
Instance method
02
Returns
New string
03
Parameters
None
04
Removes
Start only
05
Alias
trimLeft()
06
Baseline
Widely available
Fundamentals
Introduction
Sometimes you need to drop leading spaces, tabs, or indentation but keep trailing padding. That is exactly what trimStart() does — clean the left side only.
After trim() was standardized, engines also had a non-standard trimLeft(). The standard name is trimStart() (to match padStart()), and trimLeft remains as an alias of the same function for compatibility.
💡
Beginner tip
Prefer trimStart() in new code. Use plain trim() when both ends should be cleaned (typical form fields).
str.trimStart() builds a new string with leading whitespace removed. Trailing whitespace and middle spaces stay unchanged.
Returns a new string — the original is unchanged.
Takes no parameters.
Only the start (left side) is cleaned.
trimLeft is the same function (alias).
Foundation
📝 Syntax
General form of String.prototype.trimStart:
JavaScript
str.trimStart()
str.trimLeft() // alias — same function
Parameters
None.
Return value
A new string representing str stripped of whitespace from its beginning. If there is no leading whitespace, a new string is still returned (essentially a copy).
Exceptions
None for normal string values.
Aliasing
trimLeft and trimStart refer to the exact same function object. In some engines, String.prototype.trimLeft.name === "trimStart".
Using full trim() here would also remove the trailing spaces. trimStart() only removes the leading indent.
Applications
🎯 Common Use Cases
Remove indentation — strip leading spaces/tabs while keeping end padding.
Fixed-width fields — drop left pad, keep right alignment spaces.
Pasted text cleanup — remove accidental leading whitespace only.
Not for form fields — usually prefer trim() (both ends).
Not mid-string spaces — use replace / regex for those.
🧠 How trimStart() Works
1
Scan from the start
Walk forward while characters are whitespace.
Start
2
Stop at first non-space
Everything after that point is kept, including trailing spaces.
Keep
3
Drop the leading run
Spaces, tabs, and line breaks at the start are removed.
Trim
4
✅
Return a new string
Original string is never modified.
Important
📝 Notes
Always returns a new string — assign it if you need the result.
Trailing whitespace is intentionally kept.
trimLeft is an alias — prefer trimStart in new code.
Does not change spaces in the middle of the string.
Named to mirror padStart() after standardization.
Compatibility
Browser & Runtime Support
String.prototype.trimStart() is Baseline Widely available — supported across modern browsers since January 2020.
✓ Baseline · Widely available
String.trimStart()
Safe for production in browsers and runtimes (Node.js, Deno, Bun). Prefer trimStart() over the trimLeft() alias in new code.
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
trimStart()Excellent
Bottom line: Use String.trimStart() to remove leading whitespace while keeping trailing spaces. Use trim() for both ends and trimEnd() for the end only.
Wrap Up
Conclusion
String.prototype.trimStart() cleans the left side of a string — perfect when trailing padding must stay. Prefer it over trimLeft(), and use trim() when both ends should go.
Start only — trailing spaces kept, trimLeft is an alias.
5
Core concepts
📝01
Returns
new string
API
📏02
Removes
start only
Role
🔄03
Alias
trimLeft
Compat
🔍04
Keeps
trailing spaces
Rule
⚡05
Mutates
no
Immutable
❓ Frequently Asked Questions
String.prototype.trimStart() returns a new string with whitespace removed from the beginning (left side) only. Trailing whitespace is kept. The original string is not changed.
Yes. trimLeft() is an alias of trimStart() — they are the same function. Prefer trimStart() for consistency with padStart().
Whitespace includes spaces, tabs, newlines, and other white space characters plus line terminators (same rules as trim()).
trim() cleans both ends. trimStart() removes only from the start. trimEnd() removes only from the end.
No. Strings are immutable. trimStart() always returns a new string — even when there was nothing to remove.
When you must keep trailing padding or spaces but want to drop leading spaces, tabs, or indentation — for example aligning text while preserving end padding.
Did you know?
The name trimStart was chosen to match padStart. trimLeft stayed as an alias so older pages and libraries keep working — in many engines even trimLeft.name reports "trimStart".