diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
index 73de1cd369..ed1efe27c2 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
@@ -149,17 +149,33 @@ int HTMLElement::offset_left() const
// https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetwidth
int HTMLElement::offset_width() const
{
- if (auto* paint_box = this->paint_box())
- return paint_box->border_box_width();
- return 0;
+ // NOTE: Ensure that layout is up-to-date before looking at metrics.
+ const_cast(document()).update_layout();
+
+ // 1. If the element does not have any associated CSS layout box return zero and terminate this algorithm.
+ if (!paint_box())
+ return 0;
+
+ // 2. Return the width of the axis-aligned bounding box of the border boxes of all fragments generated by the element’s principal box,
+ // ignoring any transforms that apply to the element and its ancestors.
+ // FIXME: Account for inline boxes.
+ return paint_box()->border_box_width();
}
// https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetheight
int HTMLElement::offset_height() const
{
- if (auto* paint_box = this->paint_box())
- return paint_box->border_box_height();
- return 0;
+ // NOTE: Ensure that layout is up-to-date before looking at metrics.
+ const_cast(document()).update_layout();
+
+ // 1. If the element does not have any associated CSS layout box return zero and terminate this algorithm.
+ if (!paint_box())
+ return 0;
+
+ // 2. Return the height of the axis-aligned bounding box of the border boxes of all fragments generated by the element’s principal box,
+ // ignoring any transforms that apply to the element and its ancestors.
+ // FIXME: Account for inline boxes.
+ return paint_box()->border_box_height();
}
bool HTMLElement::cannot_navigate() const