diff --git a/xarray/core/formatting_html.py b/xarray/core/formatting_html.py
index d8d20a9e2c0..545a8d65b46 100644
--- a/xarray/core/formatting_html.py
+++ b/xarray/core/formatting_html.py
@@ -53,9 +53,20 @@ def format_dims(dims, dims_with_index):
return f"
"
-def summarize_attrs(attrs):
+def summarize_attrs(attrs, max_lines=15, min_lines=10):
+ def attr_cropper(obj):
+ if type(obj) is str:
+ lines = str.splitlines(obj)
+ if len(lines) > max_lines:
+ return (
+ escape("\n".join(lines[: min_lines // 2]))
+ + f"\n... (skipped {len(lines) - min_lines} lines)\n"
+ + escape("\n".join(lines[-min_lines // 2 :]))
+ )
+ return escape(str(obj))
+
attrs_dl = "".join(
- f"{escape(str(k))} :" f"{escape(str(v))}"
+ f"{escape(str(k))} :" f"{attr_cropper(v)}"
for k, v in attrs.items()
)