| | |

Prettier 12 ๐ŸŽจ Supported Languages โ€” JS, TS, CSS, HTML, Markdown, YAML & more

โฑ๏ธ Estimated read: 9 min | |

Prettier’s language support is broader than its name suggests. The project started as a JavaScript formatter, but the current release ships with built-in parsers for a set of languages that covers the modern web stack: JavaScript and TypeScript (including JSX and Flow), CSS and its preprocessors, HTML and its template dialects, JSON, GraphQL, Markdown, YAML, and Handlebars . The support is implemented through a modular parser and printer architecture: each language family has its own parser module and printer module, and the core engine applies the same Doc intermediate representation to all of them .

This chapter covers the languages that ship with Prettier, the extensions that map to each parser, the embedded-language detection that lets a Markdown code block be formatted as JavaScript, and the plugin boundary that separates the built-in support from the community-maintained languages.

Key point: Prettier’s built-in support covers the languages in its own parser modules. A language that is not in that listโ€”Java, PHP, Ruby, Rust, or a domain-specific formatโ€”requires a plugin. The plugin is installed separately and added to the Prettier configuration.


Why the language list is curated

The parser maintenance problem. Every language that Prettier supports is a parser that must track the language’s syntax evolution. The TypeScript parser must support the latest TypeScript release. The HTML parser must handle the template dialects that the web ecosystem uses. The Markdown parser must handle CommonMark and the extensions that MDX adds. The built-in list is the set of languages that the Prettier team has committed to maintaining .

The printer problem. A parser is not enough. The printer must produce a formatted output that is valid in the target language. The Doc intermediate representation is the abstraction that makes this possible: the parser converts the source into an AST, the language-specific printer converts the AST into Doc commands, and the core engine renders the Doc into the final string . A language that does not have a printer cannot be supported by the core engine.

The plugin problem. A community member can write a parser and a printer for a language that Prettier does not support, and package them as a Prettier plugin. The plugin is installed with npm and added to the plugins array in the configuration. The Prettier website lists Java, PHP, Ruby, and Rust among the languages that are supported through plugins . The plugin is not part of the core; it is a separate package with its own maintenance schedule.


a. The JavaScript family

The estree AST format covers JavaScript, TypeScript, JSX, Flow, and JSON. The parser module is shared, and the printer module handles the language-specific formatting rules .

LanguageExtensionsParser
JavaScript.js, .mjs, .cjsbabel or espree
JSX.jsxbabel
TypeScript.ts, .mts, .ctstypescript
TSX.tsxtypescript
Flow.js (with Flow syntax)flow
JSON.json, .jsonc, .json5json or json5

The parser can be overridden with the --parser flag or the overrides configuration. A .js file that uses Flow syntax is formatted with the flow parser, and a .json file that contains comments is formatted with the json5 parser.


b. The style languages

The postcss AST format covers CSS, SCSS, and Less. The parser module handles the syntax, and the printer module handles the formatting rules for each dialect .

LanguageExtensions
CSS.css, .pcss, .postcss
SCSS.scss
Less.less

The CSS parser handles the standard CSS syntax and the preprocessor dialects. The SCSS parser handles the Sass-specific syntax, including variables, nesting, and mixins. The Less parser handles the Less-specific syntax.


c. The markup and data languages

The html AST format covers HTML, Vue, Angular, and Lightning Web Component templates. The mdast format covers Markdown and MDX. The graphql format covers GraphQL schemas and queries. The yaml format covers YAML. The glimmer format covers Handlebars and Glimmer templates .

LanguageExtensionsAST format
HTML.htmlhtml
Vue.vuehtml
Angular.component.html (with override)html
Markdown.md, .markdownmdast
MDX.mdxmdast
GraphQL.graphql, .gqlgraphql
YAML.yaml, .ymlyaml
Handlebars.hbsglimmer

The embedded-language detection is the feature that makes Markdown formatting practical. A fenced code block in a Markdown file is formatted with the parser for the language named in the info string. A code block tagged js is formatted with the Babel parser; a code block tagged css is formatted with the PostCSS parser; and a code block with no tag is left alone . The same detection applies to the <script> and <style> blocks in an HTML file, and to the template, script, and style blocks in a Vue SFC.


Complete Example Session

# ============================================
# PART 1: JAVASCRIPT
# ============================================
prettier --parser babel app.js
# ============================================
# PART 2: TYPESCRIPT
# ============================================
prettier --parser typescript app.ts
# ============================================
# PART 3: CSS AND SCSS
# ============================================
prettier --parser css styles.css
prettier --parser scss styles.scss
# ============================================
# PART 4: HTML
# ============================================
prettier --parser html index.html
# ============================================
# PART 5: MARKDOWN
# ============================================
prettier --parser markdown README.md
# ============================================
# PART 6: YAML
# ============================================
prettier --parser yaml config.yml
# ============================================
# PART 7: GRAPHQL
# ============================================
prettier --parser graphql schema.graphql
# ============================================
# PART 8: THE EMBEDDED LANGUAGE
# ============================================
# A Markdown file with a fenced js block:
# ```js
# const x = 1
# ```
# The block is formatted with the babel parser.
# ============================================
# PART 9: THE PLUGIN LANGUAGE
# ============================================
# npm install --save-dev prettier-plugin-java
# prettier --plugin=prettier-plugin-java Main.java
# ============================================
# PART 10: THE DECISION
# ============================================
# Built-in language? โ†’ no plugin needed
# Community language? โ†’ install the plugin

The ten parts covered JavaScript, TypeScript, CSS and SCSS, HTML, Markdown, YAML, GraphQL, the embedded language, the plugin language, and the decision.


Quick Reference

Built-in languages

LanguageExtensionsAST format
JavaScript.js, .mjs, .cjsestree
JSX.jsxestree
TypeScript.ts, .mts, .ctsestree
TSX.tsxestree
Flow.js (Flow syntax)estree
JSON.json, .jsonc, .json5estree
CSS.css, .pcss, .postcsspostcss
SCSS.scsspostcss
Less.lesspostcss
HTML.htmlhtml
Vue.vuehtml
Markdown.md, .markdownmdast
MDX.mdxmdast
GraphQL.graphql, .gqlgraphql
YAML.yaml, .ymlyaml
Handlebars.hbsglimmer

Plugin languages

LanguagePlugin
Javaprettier-plugin-java
PHP@prettier/plugin-php
Ruby@prettier/plugin-ruby
Rustprettier-plugin-rust

Embedded language detection

HostEmbeddedDetection
MarkdownAny languageCode fence info string
HTMLJavaScript<script> tag
HTMLCSS<style> tag
VueJS, CSS, HTMLBlock tags

Best Practices

โœ… Do This:

# Use the built-in parser for the language
prettier --parser typescript app.ts                          # โœ…
# Install a plugin for a community language
npm install --save-dev prettier-plugin-java                  # โœ…
// Add the plugin to the configuration
{ "plugins": ["prettier-plugin-java"] }                      // โœ…
<!-- Use the code fence info string for embedded formatting -->
```js
const x = 1
```                                                          // โœ…

โŒ Don’t Do This:

# Assume a community language is built in
prettier Main.java                                            # โŒ (no parser)
# Use the wrong parser for a preprocessor file
prettier --parser css styles.scss                             # โŒ (use scss)
<!-- Leave the code fence info string empty and expect formatting -->

const x = 1


Common Pitfalls

PitfallWhy It HappensFix
No parser could be inferredThe extension is not built inInstall a plugin or use --parser
SCSS file formatted with the CSS parserWrong parser specifiedUse --parser scss
Markdown code block is not formattedNo info string on the fenceAdd the language tag
Vue SFC is not formattedWrong parser or no Vue supportUse --parser vue
Angular template is formatted as HTMLDefault HTML parserUse an overrides entry with parser: "angular"

Real-World Examples

1. JavaScript

prettier --parser babel app.js

2. TypeScript

prettier --parser typescript app.ts

3. SCSS

prettier --parser scss styles.scss

4. HTML

prettier --parser html index.html

5. Markdown

prettier --parser markdown README.md

6. YAML

prettier --parser yaml config.yml

7. GraphQL

prettier --parser graphql schema.graphql

8. The embedded block

```css
.button { color: red; }

#### 9. The plugin

```bash
prettier --plugin=prettier-plugin-java Main.java

10. The decision

Built-in? โ†’ no plugin; Community? โ†’ install the plugin

Visual

The language families

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  estree                                                      โ”‚
โ”‚    โ”œโ”€โ”€ JavaScript, JSX                                       โ”‚
โ”‚    โ”œโ”€โ”€ TypeScript, TSX                                       โ”‚
โ”‚    โ”œโ”€โ”€ Flow                                                  โ”‚
โ”‚    โ””โ”€โ”€ JSON                                                  โ”‚
โ”‚                                                              โ”‚
โ”‚  postcss                                                     โ”‚
โ”‚    โ”œโ”€โ”€ CSS                                                   โ”‚
โ”‚    โ”œโ”€โ”€ SCSS                                                  โ”‚
โ”‚    โ””โ”€โ”€ Less                                                  โ”‚
โ”‚                                                              โ”‚
โ”‚  html                                                        โ”‚
โ”‚    โ”œโ”€โ”€ HTML                                                  โ”‚
โ”‚    โ”œโ”€โ”€ Vue                                                   โ”‚
โ”‚    โ””โ”€โ”€ Angular                                               โ”‚
โ”‚                                                              โ”‚
โ”‚  mdast        โ†’ Markdown, MDX                                โ”‚
โ”‚  graphql      โ†’ GraphQL                                      โ”‚
โ”‚  yaml         โ†’ YAML                                         โ”‚
โ”‚  glimmer      โ†’ Handlebars                                   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The embedded detection

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Markdown file                                               โ”‚
โ”‚    ```js                                                     โ”‚
โ”‚    const x = 1                                               โ”‚
โ”‚    ```                                                       โ”‚
โ”‚       โ”‚                                                      โ”‚
โ”‚       โ–ผ                                                      โ”‚
โ”‚  Prettier detects the "js" info string                       โ”‚
โ”‚       โ”‚                                                      โ”‚
โ”‚       โ–ผ                                                      โ”‚
โ”‚  Formats the block with the babel parser                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The plugin boundary

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Built-in                    Plugin                          โ”‚
โ”‚                                                              โ”‚
โ”‚  JS, TS, CSS, HTML,          Java, PHP, Ruby, Rust,          โ”‚
โ”‚  Markdown, YAML,             and other community             โ”‚
โ”‚  GraphQL, Handlebars         languages                       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The extension to parser mapping

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  .js    โ†’ babel          .ts    โ†’ typescript                 โ”‚
โ”‚  .css   โ†’ css            .scss  โ†’ scss                       โ”‚
โ”‚  .html  โ†’ html           .md    โ†’ markdown                   โ”‚
โ”‚  .yaml  โ†’ yaml           .graphql โ†’ graphql                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary

ItemValue
JavaScript familyJS, JSX, TS, TSX, Flow, JSON
Style languagesCSS, SCSS, Less
Markup languagesHTML, Vue, Angular, Handlebars
Data languagesJSON, GraphQL, YAML
Documentation languagesMarkdown, MDX
Embedded detectionCode fences, <script>, <style>
Plugin languagesJava, PHP, Ruby, Rust, others
Plugin installationnpm install + plugins config

Key takeaways:

  • Prettier’s built-in support covers the modern web stack. JavaScript, TypeScript, JSX, Flow, JSON, CSS, SCSS, Less, HTML, Vue, Angular, GraphQL, Markdown, MDX, YAML, and Handlebars are all supported by the core package . The support is implemented through language-specific parser and printer modules that share the same Doc intermediate representation.
  • The estree AST format covers the JavaScript family. JavaScript, JSX, TypeScript, TSX, Flow, and JSON share the same parser and printer architecture. The parser is selected by the extension or by the --parser flag, and the printer applies the language-specific formatting rules.
  • The postcss AST format covers the style languages. CSS, SCSS, and Less are supported with their own syntax. The parser handles the preprocessor dialects, and the printer applies the formatting rules for each dialect.
  • The embedded-language detection is what makes Markdown and HTML formatting practical. A fenced code block in Markdown is formatted with the parser for the language named in the info string. A <script> block in HTML is formatted with the JavaScript parser. A Vue SFC’s template, script, and style blocks are each formatted with the appropriate parser .
  • A language that is not built in requires a plugin. The Prettier website lists Java, PHP, Ruby, and Rust as languages that are supported through plugins . The plugin is installed with npm and added to the plugins array in the configuration. The core package does not include the parser or the printer for the language.
  • The plugin boundary is the maintenance boundary. The built-in languages are maintained by the Prettier team, and the plugin languages are maintained by the community. A project that depends on a plugin language is depending on the plugin’s release schedule and the plugin author’s responsiveness to the language’s syntax changes.

Remember: Prettier’s supported languages are the languages that have a parser and a printer in the core package, plus the languages that are added through plugins. The built-in list covers the modern web stack, and the plugin list covers the rest. The embedded-language detection is the feature that makes a Markdown file with a JavaScript example format the example correctly, and the code fence info string is the mechanism that tells Prettier which parser to use. When a file is not formatted, check the extension, the --parser flag, and the plugin installation, in that order.

Was this helpful?


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!