Pretty XML
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.










Features
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
- Formats the entire valid XML document
- 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.

Before

After

2. Pretty XML: Minimize
Minimizes XML documents.

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 |

Attributes In Newline Threshold
Example:
Value = 2
<Element Attribute1="Value1" Attribute2="Value2" />
Output #1
<Element Attribute1="Value1" Attribute2="Value2" />
<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*"]
<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.
<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
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