diff --git a/Source/HtmlRenderer/Core/Dom/CssBoxProperties.cs b/Source/HtmlRenderer/Core/Dom/CssBoxProperties.cs
index 0167d22a4..8b1891112 100644
--- a/Source/HtmlRenderer/Core/Dom/CssBoxProperties.cs
+++ b/Source/HtmlRenderer/Core/Dom/CssBoxProperties.cs
@@ -1901,7 +1901,8 @@ public double GetEmHeight()
protected string NoEms(string length)
{
var len = new CssLength(length);
- if (len.Unit == CssUnit.Ems)
+ // CssLength reads rem as em with a parse error
+ if (len.Unit == CssUnit.Ems && !len.HasError)
{
length = len.ConvertEmToPixels(GetEmHeight()).ToString();
}
diff --git a/Source/Test/HtmlRenderer.Test/Css/TextPropertyTests.cs b/Source/Test/HtmlRenderer.Test/Css/TextPropertyTests.cs
index 53f68c3ee..eb687ef77 100644
--- a/Source/Test/HtmlRenderer.Test/Css/TextPropertyTests.cs
+++ b/Source/Test/HtmlRenderer.Test/Css/TextPropertyTests.cs
@@ -1,4 +1,5 @@
using HtmlRenderer.Test.CssEngineSupport;
+using HtmlRenderer.Test.TestSupport;
using TheArtOfDev.HtmlRenderer.Core.CssEngine;
namespace HtmlRenderer.Test.Css;
@@ -822,4 +823,14 @@ public void OverflowWrapAlternateNameNoneIllegal()
Assert.IsInstanceOfType(property);
Assert.IsFalse(property.HasValue);
}
+
+ [TestMethod]
+ [DataRow("text-indent")]
+ [DataRow("word-spacing")]
+ public void RemLengthDoesNotFailTheDocument(string property)
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap($"a b
"));
+
+ Assert.IsNotNull(LayoutHarness.FindById(root, "x"));
+ }
}