LWC Formatter

Format and beautify LWC code.

Local Your input is processed locally in your browser. The first run loads the open-source Prettier library from this site; your input is not sent anywhere. Found a problem? Report an issue

What the LWC Formatter does

The LWC Formatter formats Lightning Web Components templates with Prettier 3.3.3, an open-source code formatter, running in your browser. It supports LWC templates, where attribute values in braces stay unquoted.

LWC Formatter example

The built-in sample

Input

<template>
<lightning-card title={title}>
<template if:true={items}>
<ul>
<template for:each={items} for:item="item">
<li key={item.id}>{item.name}</li>
</template>
</ul>
</template>
<lightning-button label="Save" onclick={handleSave}></lightning-button>
</lightning-card>
</template>

Output

<template>
  <lightning-card title={title}>
    <template if:true={items}>
      <ul>
        <template for:each={items} for:item="item">
          <li key={item.id}>{item.name}</li>
        </template>
      </ul>
    </template>
    <lightning-button label="Save" onclick={handleSave}></lightning-button>
  </lightning-card>
</template>

This is the input that the Load sample button fills in.

Each output was produced by running this tool on the input above it.

How it works

The code is parsed with Prettier's lwc parser and printed again from its syntax tree, using Prettier's default options: lines up to 80 characters and two-space indentation. The result therefore does not depend on how the input was laid out. If the code cannot be parsed, the parser's message with its line and column is shown instead of output.

Details and limits

  • This is the difference from the HTML Formatter: an attribute value written in braces, such as label={label}, is left unquoted. The HTML formatter would print label="{label}", which Lightning Web Components reads as a literal string.
  • Only the template (.html) file of a component is handled. Format the JavaScript file with the JavaScript Beautifier.
  • Template directives such as if:true, for:each and lwc:if are ordinary attributes to the formatter and are kept as written.

Questions

Is my data uploaded when I use LWC Formatter?

No. The tool runs in your browser, so what you paste or open is processed on your own device and is not sent to a server.

What does LWC Formatter do?

The LWC Formatter formats Lightning Web Components templates with Prettier 3.3.3, an open-source code formatter, running in your browser. It supports LWC templates, where attribute values in braces stay unquoted.

How does LWC Formatter work?

The code is parsed with Prettier's lwc parser and printed again from its syntax tree, using Prettier's default options: lines up to 80 characters and two-space indentation. The result therefore does not depend on how the input was laid out.

Are there any limits I should know about?

This is the difference from the HTML Formatter: an attribute value written in braces, such as label={label}, is left unquoted. The HTML formatter would print label="{label}", which Lightning Web Components reads as a literal string. Only the template (.html) file of a component is handled. Format the JavaScript file with the JavaScript Beautifier.

Is there a size limit?

There is no fixed size limit. Everything happens on your device, so very large inputs depend on its memory and can take longer on a phone than on a computer.

Does it work on phones, and is it free?

Yes. It works in any current browser on Android phones, iPhones, tablets and computers. It is free and needs no account or sign-up.