Skip to content

Commit 33892af

Browse files
authored
Merge pull request #5693 from plotly/mishrakushal-add-doctype-to_html
Add <!doctype html> to the to_html template
2 parents b19eeb4 + 26da2aa commit 33892af

5 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
66

77
### Fixed
88
- Fix `hex_to_rgb` parsing of 3-digit shorthand hexadecimal colors such as `#FFF` [[#5662](https://github.com/plotly/plotly.py/pull/5662)], with thanks to @genrichez for the contribution!
9+
- Add `<!doctype html>` to the `to_html()` template to comply with modern web standards [[#5693](https://github.com/plotly/plotly.py/pull/5693)], with thanks to @mishrakushal for the contribution!
910

1011

1112
## [6.9.0] - 2026-07-09

‎plotly/io/_html.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,12 @@ def to_html(
339339

340340
if full_html:
341341
return """\
342+
<!doctype html>
342343
<html>
343-
<head><meta charset="utf-8" /></head>
344+
<head>
345+
<meta charset="utf-8" />
346+
<style>html, body {{height: 100%;}}</style>
347+
</head>
344348
<body>
345349
{div}
346350
</body>

‎tests/test_core/test_offline/test_offline.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_default_plot_generates_expected_html(self):
108108
self.assertIn(plotly_config_script, html) # so is config
109109
self.assertIn(PLOTLYJS, html) # and the source code
110110
# and it's an <html> doc
111-
self.assertTrue(html.startswith("<html>") and html.endswith("</html>"))
111+
self.assertTrue(html.startswith("<!doctype html>") and html.endswith("</html>"))
112112

113113
def test_including_plotlyjs_truthy_html(self):
114114
# For backwards compatibility all truthy values that aren't otherwise

‎tests/test_io/test_renderers.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ def test_plotly_mimetype_renderer_show(fig1, renderer):
133133
# HTML
134134
# ----
135135
def assert_full_html(html):
136-
assert html.startswith("<html")
136+
assert html.startswith("<!doctype html")
137137

138138

139139
def assert_not_full_html(html):
140-
assert not html.startswith("<html")
140+
assert not html.startswith("<!doctype html") and not html.startswith("<html")
141141

142142

143143
def assert_html_renderer_connected(html):

‎tests/test_optional/test_offline/test_offline.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,6 @@ def test_default_mpl_plot_generates_expected_html(self):
8888
self.assertTrue(data_json in html) # data is in there
8989
self.assertTrue(PLOTLYJS in html) # and the source code
9090
# and it's an <html> doc
91-
self.assertTrue(html.startswith("<html>") and html.endswith("</html>"))
91+
self.assertTrue(
92+
html.startswith("<!doctype html>") and html.endswith("</html>")
93+
)

0 commit comments

Comments
 (0)