Skip to main content

Lua Code Formatter

Format and beautify Lua source code — re-indent by block structure (function/if/for/while/repeat), normalize operator and comma spacing, and choose 2-space, 4-space, or tab indentation. Runs entirely in your browser.

Input

Drop a file or browse
One file · text
Or

Formatting Options

Output

Formatted Code
 
Was this helpful?

Guides

The Lua Code Formatter turns messy, minified, or inconsistently indented Lua into clean, readable source. Paste a snippet or upload a .lua file, choose your indentation, and get properly nested output with normalized spacing — instantly, with no Lua interpreter, LuaRocks, or editor plugin to install.

It is built for the quick cases where a full toolchain is overkill: tidying a Stack Overflow answer, cleaning a code-review paste, formatting a game mod or Neovim config snippet, or making a compressed one-liner legible before you study it.

How to use it

  1. Paste your Lua code into the input box, or upload a .lua file.
  2. Choose an Indent Style — 2 spaces, 4 spaces, or tabs.
  3. Toggle Preserve comments and Collapse multiple blank lines into one to taste.
  4. The formatted result appears on the right, ready to copy or download as formatted.lua.

Formatting runs as you type, so you can switch indent styles and watch the output update live.

What it does

  • Re-indents every line by Lua block depth. Blocks opened by function, then, do, repeat, and a bare else step the indent in; end and until step it back out. A line that starts with end, until, else, or elseif is dedented before it prints, so if/elseif/else/end chains line up correctly.
  • Normalizes spacing around binary operators (=, ==, ~=, .., <=, +, and the rest), and after commas and semicolons, while keeping function calls and table indexing tight (f(x), t[i], obj:method()).
  • Distinguishes unary from binary - and the length operator #, so -x and #list are not spaced like subtraction.
  • Preserves comments verbatim by default — line comments (-- …) and long/block comments (--[[ … ]]) — or strips them entirely when you turn the option off.
  • Collapses runs of blank lines to a single blank line (optional), without touching the code between them.

Why the tokenizer matters

Lua lets keywords appear inside strings and comments, and a naive find-and-replace formatter breaks on them. This tool parses your code structurally instead: print("end of loop") and -- end of the function do not close a block, because the end inside a string or comment is recognized as string/comment text, never as the end keyword. Long-bracket strings ([[ … ]], [=[ … ]=]) and block comments that span several lines are also carried through untouched, so their contents are never re-indented or re-spaced.

Does it check my Lua for errors?

No. This is a formatter, not a parser or linter. It re-lays-out whatever you give it and does not report syntax errors or change behavior. Invalid Lua is reformatted as best it can, but it is not validated.

Does it change my code's behavior?

No. Formatting only adjusts whitespace — indentation and the spaces between tokens. String and comment contents are preserved byte-for-byte, so the program you paste in is the program you get back.

Which Lua versions are supported?

Standard Lua syntax through 5.4 and LuaJIT: functions, control blocks, tables, goto/labels, long strings and comments, and operators including integer division (//) and the bitwise operators (<<, >>).

Privacy

This tool runs entirely in your browser. Your code is never uploaded to a server — formatting happens locally in JavaScript, so even proprietary or sensitive source stays on your own machine.

luacode formatterbeautifyindentpretty printlua beautifier

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.