CalcCafe

LWC Formatter

Format Lightning Web Components HTML templates. It runs entirely on your device — nothing is uploaded.

Reviewed by the CalcCafe editorial team · Last updated 1 July 2026 · How we test our tools

Example

Format Lightning Web Components HTML templates.

How it works

Prettier's LWC parser formats Salesforce Lightning Web Component templates cleanly.

Good to know

The LWC Formatter cleans up the HTML markup inside Salesforce Lightning Web Component templates — the .html files that sit alongside your JavaScript and metadata in an LWC bundle. Paste your template, and it reflows indentation, attribute wrapping, and tag nesting using Prettier's HTML parser, so directives like template if:true, for:each, iterator:, and slot markup all line up consistently. It's aimed at Salesforce developers and admins who write or review components and want tidy, diff-friendly templates without setting up a local build.

Reach for it when you've pasted markup from a Stack Exchange answer, inherited an inconsistently formatted component, or want to standardize spacing before opening a pull request. Because it runs entirely in your browser, it's also handy when you can't (or shouldn't) paste org code into a third-party server — useful for client or regulated work.

Read the output as a normalized version of the same template: the structure and behavior are unchanged, only whitespace, line breaks, and attribute alignment are adjusted. If a tag was malformed or a directive bracket was unbalanced, formatting may fail or leave that region untouched, which is itself a quick signal that the markup has a syntax problem worth fixing.

A practical caveat: this tool formats the HTML template only, not the component's JavaScript controller or the .js-meta.xml file. For those, use a JavaScript-aware formatter, and for true project-wide consistency, pair this with a committed Prettier config and the Salesforce Prettier plugin in your repo so local and online output match.

Frequently asked questions

Is my data uploaded anywhere?
No — everything runs in your browser. Your code never leaves your device, so it's safe for private work and runs offline once loaded.
Is this tool free?
Yes, completely free with no sign-up and no limits.

People also ask

What is a Lightning Web Component HTML template?
It's the markup file in an LWC bundle, wrapped in a top-level <template> tag, that defines a component's UI. It uses Salesforce-specific directives such as if:true, for:each, and slots, and pairs with a JavaScript file and a metadata XML file.
Does formatting an LWC template change how the component behaves?
No. Formatting only adjusts whitespace, indentation, line breaks, and attribute wrapping. The tags, directives, and bindings stay the same, so the rendered output and behavior are unchanged.
Can this tool format the JavaScript and meta XML files in an LWC bundle?
No, it targets the HTML template markup. The component's JavaScript controller and the .js-meta.xml file need a JavaScript-aware or XML-aware formatter instead.
Will it handle LWC directives like for:each and if:true correctly?
Yes. It uses Prettier's HTML parser, which treats these as normal attributes, so directive-bearing tags are indented and wrapped along with the rest of the template.
How is this different from formatting plain HTML?
LWC templates are valid HTML but include a required <template> wrapper, Salesforce directives, and data-binding syntax in attributes. The formatting rules are the same as HTML; the difference is the markup patterns you're cleaning up.
How do I get the same formatting in my code editor?
Install Prettier and the prettier-plugin-apex or the Salesforce Prettier configuration in your project, then commit a .prettierrc file. That keeps local saves and CI consistent with what you see here.
Why did my template fail to format or come out unchanged?
That usually points to a syntax issue, such as an unclosed tag or an unbalanced directive bracket. Fix the malformed markup and run it again.
How can I beautify my HTML code?
Paste it into a formatter that re-indents the markup, breaks long tags across lines, and normalizes attribute spacing; this page does that for LWC templates using Prettier's parser, and plain HTML formatters work the same way. In an editor, VS Code's Format Document command (Shift+Alt+F on Windows, Shift+Option+F on macOS) uses its built-in HTML formatter, or Prettier if that extension is installed. Formatting changes only whitespace between tags, so the rendered page is unchanged.
What is the best code formatter?
There is no single best formatter; the practical answer is the one that is standard for your language, because a formatter's value comes from everyone on the team producing identical output. For JavaScript, HTML, CSS, and LWC templates that is Prettier, which this tool uses; for Python it is Black or Ruff, for Go gofmt, for Rust rustfmt, and for Apex the Prettier Apex plugin. Pick the community default, commit its config file, and run it on save or in CI.
Is LWC similar to React?
Yes in spirit: both are component frameworks where you build a UI from reusable JavaScript classes, pass data into child components, and let the framework re-render when tracked state changes. The main differences are that LWC is built on web standards (custom elements, shadow DOM, ES modules) and keeps its markup in a separate HTML template file with directives such as if:true and for:each, whereas React writes JSX inside the JavaScript and reconciles through a virtual DOM. LWC's lifecycle hooks (connectedCallback, renderedCallback) and wire service are also tuned to the Salesforce platform it runs on.

Related calculators

Sources & references

These tools follow our methodology and provide educational estimates only — verify important figures with a qualified professional.