Prettier plugin for formatting Svelte components, supporting Svelte 3, 4, and 5. Current stable version is 3.5.1, with active development. Automatically formats HTML, CSS, and JavaScript within Svelte files, including Svelte-specific syntax like each loops, if blocks, and event bindings. Key differentiators: official plugin from the Svelte team, integrates natively with the Svelte VS Code extension, and supports Prettier v3 (v2 works with Prettier v2). Released on npm, ships TypeScript types, and follows Prettier's plugin API. Compared to generic formatters, this plugin understands Svelte's template syntax and provides options like sorting order and strict mode.
npm install prettier-plugin-svelteVerified import paths — ran on the pinned version, not inferred.
Shows installation, Prettier configuration with plugin and Svelte options, and CLI usage to format all Svelte files.
Ensure you have prettier@3 installed (npm i prettier@3) and use the v3 plugin.
Delete 'pluginSearchDirs' from .prettierrc.
If using Svelte 5, ensure your code does not rely on quotes being added. Update templates accordingly.
Add 'overrides' entry as shown in the quickstart. Without it, formatting falls back to default HTML parser.
If using v1, omit 'options' from the sort order string.
Either remove the .prettierrc file to use extension settings, or configure options only in .prettierrc.
Run 'npm i --save-dev prettier-plugin-svelte prettier' to install both.
Ensure the plugin is in node_modules and add 'plugins' array in .prettierrc. Do not use require() – use the config file only.
Upgrade to prettier-plugin-svelte@3 if using Prettier v3, or downgrade to Prettier v2.
Verify the plugin is correctly configured in 'plugins' array. Ensure you are using prettier-plugin-svelte@2 or higher.
Set 'parser': 'svelte' (string) in the overrides. Example: 'overrides': [{ 'files': '*.svelte', 'options': { 'parser': 'svelte' } }]