String.prototype.trimStart()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

The trimStart() method of String values removes whitespace from the beginning of this string and returns a new string, without modifying the original string. trimLeft() is an alias of this method.

Try it

const greeting = "   Hello world!   ";

console.log(greeting);
// Expected output: "   Hello world!   ";

console.log(greeting.trimStart());
// Expected output: "Hello world!   ";

Syntax

js
trimStart()

trimLeft()

Parameters

None.

Return value

A new string representing str stripped of whitespace from its beginning (left side). Whitespace is defined as white space characters plus line terminators.

If the beginning of str has no whitespace, a new string is still returned (essentially a copy of str).

Aliasing

After trim() was standardized, engines also implemented the non-standard method trimLeft. However, for consistency with padStart(), when the method got standardized, its name was chosen as trimStart. For web compatibility reasons, trimLeft remains as an alias to trimStart, and they refer to the exact same function object. In some engines this means:

js
String.prototype.trimLeft.name === "trimStart";

Examples

Using trimStart()

The following example trims whitespace from the start of str, but not from its end.

js
let str = "   foo  ";

console.log(str.length); // 8

str = str.trimStart();
console.log(str.length); // 5
console.log(str); // 'foo  '

Specifications

Specification
ECMAScript® 2025 Language Specification
# sec-string.prototype.trimstart

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
trimStart

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Uses a non-standard name.
Has more compatibility info.

See also