How to Format XML in VS Code
Step-by-step formatting workflow for XML in Visual Studio Code.
VS Code is a common editor for XML work, but formatting support depends on configuration. If you are trying to format XML in VS Code and nothing happens, the issue is usually missing language mode, no formatter extension, or conflicting formatter settings.
Step 1: Confirm XML Language Mode
Open your file and confirm the language mode at the bottom right reads XML. If it does not, switch it manually. Formatter commands are language-aware, so wrong mode can block formatting.
Step 2: Install an XML Formatter Extension
Install a trusted XML extension from the Marketplace that supports formatting and validation. After install, run Format Document from the command palette. If prompted, set the extension as default formatter for XML.
Step 3: Configure Indentation
Set tab size or spaces in VS Code preferences, then re-run formatting. For team consistency, align these settings with repository conventions so XML diffs stay predictable in pull requests.
Troubleshooting
- Command does nothing: check default formatter assignment for XML.
- Formatting breaks structure: validate XML syntax before formatting.
- Extension conflicts: disable other XML-related formatters temporarily.
If you are on a restricted machine or need a quick fallback, use an online XML formatter. That keeps you moving without extension setup and is handy for fast debugging sessions.
For portable workflows, many teams use both: VS Code for daily editing and browser-based XML formatting for ad-hoc tasks, quick checks, and collaboration across devices.
Continue with XML Formatter or open XML to JSON Converter.