diff --git a/src/HtmlAgilityPack.Shared/HtmlDocument.cs b/src/HtmlAgilityPack.Shared/HtmlDocument.cs
index 34cd7cad..7d863791 100644
--- a/src/HtmlAgilityPack.Shared/HtmlDocument.cs
+++ b/src/HtmlAgilityPack.Shared/HtmlDocument.cs
@@ -210,11 +210,16 @@ public static bool DisableBehaviorTagP
///
public bool OptionWriteEmptyNodes;
- ///
- /// The max number of nested child nodes.
- /// Added to prevent stackoverflow problem when a page has tens of thousands of opening html tags with no closing tags
- ///
- public int OptionMaxNestedChildNodes = 0;
+ ///
+ /// Defines if empty nodes must be written without the additional space. Default is false.
+ ///
+ public bool OptionWriteEmptyNodesWithoutSpace;
+
+ ///
+ /// The max number of nested child nodes.
+ /// Added to prevent stackoverflow problem when a page has tens of thousands of opening html tags with no closing tags
+ ///
+ public int OptionMaxNestedChildNodes = 0;
#endregion
diff --git a/src/HtmlAgilityPack.Shared/HtmlNode.cs b/src/HtmlAgilityPack.Shared/HtmlNode.cs
index 2cd331f3..fac3b4dd 100644
--- a/src/HtmlAgilityPack.Shared/HtmlNode.cs
+++ b/src/HtmlAgilityPack.Shared/HtmlNode.cs
@@ -2073,7 +2073,16 @@ public virtual void WriteTo(TextWriter outText, int level = 0)
if (IsEmptyElement(Name))
{
if ((_ownerdocument.OptionWriteEmptyNodes) || (_ownerdocument.OptionOutputAsXml))
- outText.Write(" />");
+ {
+ if(_ownerdocument.OptionWriteEmptyNodesWithoutSpace)
+ {
+ outText.Write("/>");
+ }
+ else
+ {
+ outText.Write(" />");
+ }
+ }
else
{
if (Name.Length > 0 && Name[0] == '?')