Course contentsShow
← JavaScript
Lesson 2583 of 2,72352. Linting and FormattingFree lesson

Prettier for More Than JavaScript

Use Prettier to format JSON, Markdown, CSS, HTML, and YAML files consistently.

Prettier for More Than JavaScript

You'll learn how Prettier formats many file types beyond JavaScript, keeping your entire codebase consistently styled.

Beyond JavaScript Files

While Prettier began as a JavaScript formatter, it now supports numerous languages out of the box. You can use the same tool and configuration to format JSON, Markdown, CSS, HTML, and YAML files—no additional plugins required for these common formats.

This is powerful because most web projects contain multiple file types. Your package.json, README files, stylesheets, and configuration files can all follow consistent formatting rules using a single tool.

Formatting Multiple File Types

When you run Prettier, it automatically detects file types by extension and applies appropriate formatting:

npx prettier --write "**/*.{js,json,md,css,html,yml}"

This command formats all matching files in your project. Prettier understands each format's syntax and applies sensible defaults—indenting JSON properly, wrapping Markdown text at reasonable lengths, organizing CSS properties, and normalizing YAML spacing.

Think of It as a Universal Formatter

Imagine having one style guide enforcer for your entire repository instead of separate tools for each language. Prettier acts like a universal translator for code style—it reads each file type's "dialect" and rewrites it in a consistent, clean format.

Your .prettierignore file works across all formats, and your configuration options (like tabWidth and semi) apply where relevant. For example, printWidth affects line wrapping in Markdown and JavaScript alike.

Practical Benefits

Using Prettier across file types eliminates debates about JSON indentation depth or whether YAML should use tabs. Your entire team formats configuration files, documentation, and styles identically without thinking about it.

Key Takeaway: Prettier formats JSON, Markdown, CSS, HTML, and YAML alongside JavaScript, providing one consistent formatting solution for your entire codebase.