The HTML spec says > If current node is a pre, textarea, or listing element, and the first child node of the element, if any, is a Text node whose character data has as its first character a U+000A LINE FEED (LF) character, then append a U+000A LINE FEED (LF) character. https://html.spec.whatwg.org/#html-fragment-serialisation-algorithm This is because otherwise it doesn't round-trip correctly if the data starts with a LF. See https://github.com/whatwg/html/issues/944
https://github.com/whatwg/html/pull/1815