Pretty XML

January 25, 2026 ยท View on GitHub

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 a XML formatter extension for Visual Studio Code and VSCodium. It formats XML documents just like Visual Studio on Windows.

Supported file extensions:

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

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

Suggestions, improvement PRs 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 shortcut

  • Position each attribute on a separate line.
  • First attribute on same line as start element start tag.
  • All attributes indented aligning with first attribute.
  • If no child for an element then close inline end tag.
  • No empty lines.
  • Supports ' and whitespace unicodes in attribute value for XAML parser compatibility.

1.a. Format Entire Document

  • Lets you format entire valid XML document.

1.b. Format Selection - Beta

  • Lets you format part of an XML document. XML can be partial and invalid. This is in beta, so feel free to submit pull request with improvements.

Format Selection Screenshot

Before

Before.

After

After.

2. Pretty XML: Minimize

Minimizes XML.

minimize gif.


Keyboard Shortcuts

CommandPlatformShortcut
Prettify XMLMacCmd+K L
Prettify XMLWindows, LinuxControl+K L
PrettyXML: MinimizeMacCmd+K `
PrettyXML: MinimizeWindows, LinuxControl+K `

Note

You can change these in Preferences โ†’ Keyboard Shortcuts if you want.


Settings

These will be for Prettify XML command.

Setting KeyDefault ValueDescription
prettyxml.settings.indentSpaceLength4No. of spaces for indentation.
prettyxml.settings.useSingleQuotesfalseUse ' instead of "
prettyxml.settings.useSelfClosingTagtrueIf no child nodes then self closing tag />
prettyxml.settings.formatOnSavefalseEnable format on save
prettyxml.settings.allowSingleQuoteInAttributeValuetrueAllows ' in attribute values instead of '
prettyxml.settings.addSpaceBeforeSelfClosingTagtrueAdds space before self closing tag
prettyxml.settings.wrapCommentTextWithSpacestrueWraps comment text with a single space
prettyxml.settings.allowWhiteSpaceUnicodesInAttributeValuestrueAllows white space unicodes in attribute values
prettyxml.settings.positionFirstAttributeOnSameLinetruePosition first attribute on same line.
prettyxml.settings.positionAllAttributesOnFirstLinefalsePosition all attributes on first line
prettyxml.settings.preserveWhiteSpacesInCommentfalsePreserves whitespaces in a comment.
prettyxml.settings.addSpaceBeforeEndOfXmlDeclarationfalseAdd space before end of XML declaration.
prettyxml.settings.addXmlDeclarationIfMissingtrueAdd XML declaration if missing.
prettyxml.settings.attributesInNewlineThreshold1Attributes count threshold to position attributes in newlines.
prettyxml.settings.enableLogsfalseEnables logs
prettyxml.settings.wildCardedExceptionsForPositionAllAttributesOnFirstLineArray<string>Wild card exceptions for elements to ignore positionAllAttributesOnFirstLine
prettyxml.settings.addEmptyLineBetweenElementsfalseAdd empty line between elements if the child count is greater than 2
prettyxml.settings.preserveNewLinesfalsePreserve existing new lines between elements.
prettyxml.settings.preserveCommentPlacementfalsePreserve comment line placement.

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 Position All Attributes On First Line setting. Include element names or patterns here.

Example:

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

Input 3

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

Ouput 3

<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 child elements count is greater than 2 then adds empty line between elements.

Note


Please note it wont add empty element before first element and after last element.

Input 4

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

Output 4

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

Preserve New Lines

Preserves existing new lines between elements.

Example: Value = false

Input 5

<Root>
      <Element1>Text1</Element1>


    <Element2>Text2</Element2>

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

Output 5

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

Example: Value = true

Input 6

<Root>
      <Element1>Text1</Element1>


    <Element2>Text2</Element2>

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

Output 6

<Root>
    <Element1>Text1</Element1>

    
    <Element2>Text2</Element2>
        
    <Element3>Text3</Element3>
    <Element3>Text4</Element3>
</Root>

Preserve Comment Placement

Preserve existing comment line placement. Default is Unchecked

Checked : Comments remains in their original lines. Unchecked : Comments may be repositioned into other lines according to formatting rules.

Example: Value = false

Input 7

<Root>
    <Element1>Text1</Element1>  <!--A comment-->
    <Element2>Text2</Element2><!--Another comment-->
    <Element3>Text3</Element3>
</Root>

Output 7

<Root>
    <Element1>Text1</Element1>
    <!--A comment-->
    <Element2>Text2</Element2>
    <!--Another comment-->
    <Element3>Text3</Element3>
</Root>

Example: Value = true

Input 8

<Root>
    <Element1>Text1</Element1>    <!--A comment-->
    <Element2>Text2</Element2>   <!--Another comment-->
    <Element3>Text3</Element3>
</Root>

Output 8

<Root>
    <Element1>Text1</Element1><!--A comment-->
    <Element2>Text2</Element2><!--Another comment-->
    <Element3>Text3</Element3>
</Root>

Requirements


Installation

Visual Studio Code - Visual Studio MarketPlace

For VSCodium - open-vsx.org


Known Issues

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

Issues can be reported at issues section


For more information