Skip to content
CODE FORMATTING & MINIFICATION

JavaScript Formatter & Beautifier Online

Indent JavaScript and put each statement on its own line.

  • Free
  • No signup
  • Runs in your browser

This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.

JavaScript Formatter

About JavaScript Formatter

This tool re-indents JavaScript so each statement sits on its own line and every block is indented by two spaces. It keeps strings, template literals and comments exactly as written, and it does not split the semicolons inside a for loop header.

It is a lightweight formatter based on braces and semicolons, not a full parser such as Prettier. That makes it fast and predictable for snippets, minified code and quick clean-ups, but it does not rewrite quotes, wrap long lines or enforce a style guide.

How to use JavaScript Formatter

  1. Paste your JavaScript into the input box.
  2. Click Run Tool. The indented code appears in the output box.
  3. Copy the result into your editor, or download it as a text file.

Example

Input

function greet(name){if(!name){return "Hello, guest"}return "Hello, "+name} const users=["Aman","Kiran"];users.forEach(u=>{console.log(greet(u))});

Output

function greet(name) {
  if(!name) {
    return "Hello, guest"
  }
  return "Hello, "+name
}
const users=["Aman","Kiran"];
users.forEach(u=> {
  console.log(greet(u))
}
);

Common uses

  • Reading a minified script while you debug a third-party widget.
  • Tidying a snippet before pasting it into documentation or a forum post.
  • Checking brace nesting when a block does not behave as expected.

Privacy and safety

This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.

Frequently asked questions

Will it change how my code runs?

It only changes whitespace and line breaks outside strings and comments, so behaviour stays the same. Review the result in a project that uses automatic semicolon insertion.

Does it work with JSON, TypeScript or JSX?

Basic JSON and TypeScript blocks format acceptably because they use braces. JSX and regular expression literals that contain quotes can confuse a brace-based formatter, so use a full tool such as Prettier for those.

Where can I minify JavaScript?

Use the JavaScript Minifier on this site to remove comments and whitespace.

Learn to build this yourself

Free tutorials and courses on NHP Learning cover PHP, JavaScript, SQL and WordPress, from the basics to real projects.