W3Schools offers a wide range of services and products for beginners and professionals, helping millions of people everyday to learn and master new skills.
Enjoy our free tutorials like millions of other internet users since 1999
Explore our selection of references covering all popular coding languages
Create your own website with W3Schools Spaces - no setup required
Test your skills with different exercises
Test yourself with multiple choice questions
Document your knowledge
Create a free W3Schools Account to Improve Your Learning Experience
Track your learning progress at W3Schools and collect rewards
Become a PLUS user and unlock powerful features (ad-free, hosting, support,..)
Not sure where you want to start? Follow our guided path
With our online code editor, you can edit code and view the result in your browser
Learn the basics of HTML in a fun and engaging video tutorial
We have created a bunch of responsive website templates you can use - for free!
Host your own website, and share it to the world with W3Schools Spaces
Create your own server using Python, PHP, React.js, Node.js, Java, C#, etc.
Large collection of code snippets for HTML, CSS and JavaScript
Build fast and responsive sites using our free W3.CSS framework
Read long term trends of browser usage
Test your typing speed
Use our color picker to find different RGB, HEX and HSL colors.
W3Schools Coding Game! Help the lynx collect pine cones
Join our newsletter and get access to exclusive content every month
Contact us about W3Schools Academy for educational institutions
Contact us about W3Schools Academy for your organization
About sales: [email protected] About errors: [email protected]
Remove spaces with trim():
Remove spaces with replace() using a regular expression:
The trim() method removes whitespace from both sides of a string.
trim()
The trim() method does not change the original string.
The trimEnd() Method
The trimStart() Method
The padEnd() Method
The padStart() Method
JavaScript Strings
JavaScript String Methods
JavaScript String Search
trim() is an ECMAScript5 (ES5) feature.
ES5 (JavaScript 2009) is fully supported in all modern browsers since July 2013: