diff --git a/elem.go b/elem.go index 75ac219..cf2d086 100644 --- a/elem.go +++ b/elem.go @@ -112,6 +112,13 @@ type Element struct { } func (e *Element) RenderTo(builder *strings.Builder) { + // The HTML tag needs a doctype preamble in order to ensure + // browsers don't render in legacy/quirks mode + // https://developer.mozilla.org/en-US/docs/Glossary/Doctype + if e.Tag == "html" { + builder.WriteString("") + } + // Start with opening tag builder.WriteString("<") builder.WriteString(e.Tag) diff --git a/elements_test.go b/elements_test.go index 6c6f341..6ec6fa4 100644 --- a/elements_test.go +++ b/elements_test.go @@ -18,7 +18,7 @@ func TestBody(t *testing.T) { } func TestHtml(t *testing.T) { - expected := `Elem Page

Welcome to Elem!

` + expected := `Elem Page

Welcome to Elem!

` el := Html(attrs.Props{attrs.Lang: "en"}, Head(nil, Meta(attrs.Props{attrs.Charset: "UTF-8"}),