Skip to content
| Marketplace
Sign in
Visual Studio Code>Formatters>Pretty XML ProNew to Visual Studio Code? Get it now.
Pretty XML Pro

Pretty XML Pro

MahendrakarPrateek

|
2,782 installs
| (0) | Free
XML formatter extension for Visual Studio Code. Formats XML documents just like Visual Studio.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Pretty XML

logo

What is it?

Features
1. Prettify XML (XML Formatting)
2. Pretty XML: Minimize

Keyboard Shortcuts

Settings

Requirements

Installation

Known Issues

Change Log

For more information

What is it?

Pretty XML is an XML formatter extension for Visual Studio Code and VSCodium. It formats XML documents using the same formatting style as Visual Studio on Windows.

Supported file extensions:

  • xml
  • xaml
  • axml
  • xsd
  • xsl
  • plist
  • mobileconfig
  • config
  • csproj
  • svg
  • resx and all other XML-type files

A Visual Studio for Mac version of this extension is also available. Check it out at PrettyXML.VSMac

Suggestions and improvement pull requests are welcome.

LicenseDeploy

Visual Studio Marketplace VersionVisual Studio Marketplace InstallsVisual Studio Marketplace DownloadsVisual Studio Marketplace Rating

Open VSXOpen VSX DownloadsOpen VSX Rating

prettify gif.


Features

1. Prettify XML (XML Formatting)

Right-click and select "Prettify XML" or use the keyboard shortcut.

  • Positions each attribute on a separate line
  • First attribute on the same line as the element start tag
  • All attributes indented, aligned with the first attribute
  • If an element has no children, closes with an inline end tag
  • No empty lines
  • Supports ' and whitespace Unicode characters in attribute values for XAML parser compatibility

1.a. Format Entire Document

  • Formats the entire valid XML document

1.b. Format Selection - Beta

  • Formats a portion of an XML document. The XML can be partial and invalid. This feature is in beta, so feel free to submit pull requests with improvements.

Format Selection Screenshot
Before

Before.

After

After.

2. Pretty XML: Minimize

Minimizes XML documents.

minimize gif.


Keyboard Shortcuts

Command Platform Shortcut
Prettify XML Mac Cmd+K L
Prettify XML Windows, Linux Control+K L
PrettyXML: Minimize Mac Cmd+K `
PrettyXML: Minimize Windows, Linux Control+K `

Note

You can change these shortcuts in Preferences → Keyboard Shortcuts if desired.


Settings

These settings apply to the Prettify XML command.

Setting Key Default Value Description
prettyxml.settings.indentSpaceLength 4 Number of spaces for indentation
prettyxml.settings.useSingleQuotes false Use ' instead of "
prettyxml.settings.useSelfClosingTag true If no child nodes, use self-closing tag />
prettyxml.settings.formatOnSave false Enable format on save
prettyxml.settings.allowSingleQuoteInAttributeValue true Allows ' in attribute values instead of '
prettyxml.settings.addSpaceBeforeSelfClosingTag true Adds space before self-closing tag
prettyxml.settings.wrapCommentTextWithSpaces true Wraps comment text with a single space
prettyxml.settings.allowWhiteSpaceUnicodesInAttributeValues true Allows whitespace Unicode characters in attribute values
prettyxml.settings.positionFirstAttributeOnSameLine true Position first attribute on the same line
prettyxml.settings.positionAllAttributesOnFirstLine false Position all attributes on the first line
prettyxml.settings.preserveWhiteSpacesInComment false Preserves whitespaces in comments
prettyxml.settings.addSpaceBeforeEndOfXmlDeclaration false Add space before the end of XML declaration
prettyxml.settings.addXmlDeclarationIfMissing true Add XML declaration if missing
prettyxml.settings.attributesInNewlineThreshold 1 Attributes count threshold to position attributes on new lines
prettyxml.settings.enableLogs false Enables logs
prettyxml.settings.wildCardedExceptionsForPositionAllAttributesOnFirstLine Array<string> Wildcard exceptions for elements to ignore positionAllAttributesOnFirstLine
prettyxml.settings.addEmptyLineBetweenElements false Add empty line between elements if the child count is greater than 2

Settings Image.

Attributes In Newline Threshold

Example:

Value = 2

Input #1

<Element Attribute1="Value1" Attribute2="Value2" />

Output #1

<Element Attribute1="Value1" Attribute2="Value2" />

Input #2

<Element Attribute1="Value1" Attribute2="Value2" Attribute3="Value3" />

Output #2

<Element Attribute1="Value1"
         Attribute2="Value2"
         Attribute3="Value3"/>

Wild Carded Exceptions For Position All Attributes On First Line

List of element names to ignore the "Position All Attributes On First Line" setting. Include element names or patterns here.

Example:

 "prettyxml.settings.wildCardedExceptionsForPositionAllAttributesOnFirstLine": ["Content*"]

Input

<View>
    <Content X="X"
             Y="Y" Z="Z">
        <Label text="{i18>LabelText}" />
        <Input id="Input1" 
               value="{service>description}" />
    </Content>
</View>

Output

<View>
    <Content X="X"
             Y="Y"
             Z="Z">
        <Label text="{i18>LabelText}" />
        <Input id="Input1" value="{service>description}" />
    </Content>
</View>

Add Empty Line Between Elements

If enabled, and the child elements count is greater than 2, adds an empty line between elements.

[!NOTE]
Please note: it will not add an empty line before the first element or after the last element.

Input 1

<Root>
<Element1>Text1</Element1>
<Element2>Text2</Element2>
<Element3>Text3</Element3>
</Root>

Output 1

<Root>
    <Element1>Text1</Element1>

    <Element2>Text2</Element2>

    <Element3>Text3</Element3>
</Root>

Add Xml Declaration If Missing

Adds XML declaration <?xml version="1.0" encoding="utf-8"?> if missing.
Default is true.


Requirements

  • .NET 8 or later installed on your machine and accessible through the terminal
  • Install the Muhammad-Sammy C# or Microsoft C# extension
  • Visual Studio Code/VSCodium 1.59 or higher

Installation

Visual Studio Code - Visual Studio Marketplace

VSCodium - open-vsx.org


Known Issues

  • Limited DTD support
  • Formats valid XML files only. Syntax errors are displayed

Issues can be reported in the issues section


For more information

  • Source Code
  • If you want to support this project, buy-me-coffee
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft