Format Code Now
/

Lua Beautifier and Formatter

WM-75

Paste Lua code to format it with StyLua. Choose the indent, quote style, call parentheses and line width. Syntax errors give a line and column.

Runs in your browser. Nothing is uploaded.

Lua

Formatted Lua

How to use it

  1. Paste your Lua code into the input box, or open a .lua file.
  2. Pick the indent: 2, 3, 4 or 8 spaces, or a tab.
  3. Set the quote style, call parentheses and line width if you want to change them.
  4. Copy the formatted code or download it as a .lua file.

What runs in your browser

The formatter is StyLua, a Lua formatter written in Rust, compiled to WebAssembly so it runs on this page. It parses your code and prints it again with consistent indentation, spacing and line breaks. The first run downloads about 600 KB of formatter code, and the page keeps it for later runs. Your code is never run and never leaves the browser.

Options that change the text

Quotes can follow StyLua's default, which prefers double quotes unless that needs more escapes, or force single or double quotes everywhere. Call parentheses are kept as you wrote them by default, so print "x" stays that way; you can force them on or skip them for a lone string or table. Collapse turns short functions and if statements into one line. Line width decides where long expressions wrap.

Limits

It changes layout, not meaning. Variables are not renamed and nothing is sorted. It does not check that the code runs, so a call to a missing function passes. A syntax error is reported with its line and column, and then nothing is formatted. The position is where parsing stopped and may be a little after the actual mistake.

Error messages and what to do

MessageWhat it meansFix
Invalid Lua: unexpected token "return" at line 1, column 13The parser found a keyword where it expected something else, such as a parameter name or a closing parenthesis.Check the code just before the position for a missing parenthesis, end or comma.

Questions people ask

How do I format Lua code online?

Paste the code and the result appears as you type, formatted by StyLua with your chosen indent, quotes and width. Copy it or download it as a .lua file. The first run downloads the formatter, so allow a moment.

What is StyLua?

StyLua is an opinionated Lua formatter written in Rust and used by many Lua projects. This page runs it as WebAssembly in your browser, so you get the same formatting engine without installing anything.

Can I keep single quotes in my strings?

Yes. Choose Single, unless it needs more escapes, or Always single. The default prefers double quotes and switches to single when that avoids backslashes. Quote changes never alter the string's value.

Will it remove the parentheses around function calls?

Not unless you ask. The default keeps call parentheses as written. You can choose to skip them for a lone string or lone table argument, for example print "hi", or always add them.

What does the collapse option do?

It lets StyLua put simple functions and short if guards on one line instead of three. It applies only when the body is a single simple statement and fits the line width. Leave it off to keep every block expanded.

Does it check that my Lua runs?

No. It checks only that the code parses. Calling a function that does not exist, or using a variable before setting it, is not reported. Run the code in your Lua interpreter or use a linter such as luacheck for that.

About this tool

Runs StyLua, the Lua formatter written in Rust, compiled to WebAssembly in your browser. Layout is changed, not meaning: indentation, spacing, line breaks and quote style. Comments are kept. A syntax error is reported with its line and column and nothing is formatted. By default call parentheses stay as you wrote them. The first run downloads the formatter, and the page then keeps it for later runs. It does not rename variables, sort anything or check that the code runs.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.