diff --git a/plotly/io/_html.py b/plotly/io/_html.py
index 58f123ba3a1..7b9bdb0f760 100644
--- a/plotly/io/_html.py
+++ b/plotly/io/_html.py
@@ -157,8 +157,15 @@ def to_html(fig,
# Get div width/height
layout_dict = fig_dict.get('layout', {})
- div_width = layout_dict.get('width', default_width)
- div_height = layout_dict.get('height', default_height)
+ template_dict = (fig_dict
+ .get('layout', {})
+ .get('template', {})
+ .get('layout', {}))
+
+ div_width = layout_dict.get(
+ 'width', template_dict.get('width', default_width))
+ div_height = layout_dict.get(
+ 'height', template_dict.get('height', default_height))
# Add 'px' suffix to numeric widths
try: