Angular Template Formatter
WM-88Paste an Angular component template and get it back with one attribute per line, spaced bindings and even indentation. It uses Prettier's Angular parser in your browser.
Runs in your browser. Nothing is uploaded.
Angular template
Formatted template
How to use it
- Paste your template, or open an .html file or drop it on the input box.
- Pick 2 spaces, 4 spaces or a tab, and a line width of 80, 100 or 120.
- Press Format.
- Copy the result or download it as an .html file.
What gets formatted
Prettier's Angular parser reads the template as HTML and then parses what sits inside Angular syntax. Property bindings such as [disabled], event bindings such as (click), structural directives like *ngIf and *ngFor, and interpolation in double curly braces are all spaced and wrapped. Attributes move to their own lines once a tag is wider than the line width. The newer @if and @for control flow blocks are formatted as well. Text, comments and attribute values are kept as you wrote them.
What it does not check
The tool formats text and has no idea what your component class contains. A misspelled property, a missing import or a pipe that does not exist will pass through without a message. An expression that the Angular parser cannot read is left exactly as you typed it, so a clean result does not prove the template compiles. Only broken HTML, such as a tag that never closes, is reported, with a line and column. Run ng build or your editor language service for real template checks.
Matching your project
Output depends on the Prettier version bundled in this page, so a template formatted here can differ in small ways from one formatted by the version in your repository. Indent size and line width are the two settings offered. If your project has a .prettierrc with other rules, such as bracket spacing or quote style, those rules are not read from here.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
Could not format the template: Opening tag "div" not terminated at line 1, column 1. | A tag was started but its closing angle bracket is missing. | Add the missing > to the tag at the line and column shown. |
Questions people ask
How do I format an Angular HTML template?
Paste the template into the box and press Format. Each element with several attributes is split across lines, bindings get single spaces around operators, and nested elements are indented. Copy the result back into your component's .html file.
Does it format *ngFor and *ngIf expressions?
Yes. Prettier parses the expression inside the directive, so let item of items;trackBy:track becomes let item of items; trackBy: track. If an expression has a syntax error, it is left untouched rather than guessed at.
Does it support the new @if and @for syntax?
Yes. The Angular parser in Prettier handles the built-in control flow blocks as well as the older structural directives. Blocks are indented like normal elements, so a template can mix both styles during a migration.
Can this tell me if my template has an error?
Only for broken HTML structure. It does not know your component, so unknown properties, missing imports and type mistakes are not reported. For those checks, use the Angular compiler or your editor.
Why does my project format it differently?
Prettier changes its output between versions, and your project may use another version or a config file with its own settings. This page offers indent size and line width only. Match those to your config to get closer output.
About this tool
Formats Angular templates with Prettier, using its Angular parser, which understands *ngIf and *ngFor, [property] and (event) bindings, interpolation and the @if and @for blocks. Everything is formatted in your browser. It formats text and does not check your component: an unknown element, a missing property or a wrong expression is not reported, and an expression Prettier cannot parse is left as you wrote it. Unclosed HTML tags may be closed for you in the output. The result depends on the Prettier version in this page, so it can differ from the version in your project.