Feedback

Reduce DOM size

Updated

The Lighthouse finding Avoid an excessive DOM size counts the elements on a page; its successor in Lighthouse 13 also checks whether the size actually makes style and layout work slow. The DOM is the browser's in-memory model of the HTML; every element in it has to be styled, laid out and kept up to date. A page with several thousand elements costs more memory, more time for every style recalculation and every layout, and more work for each interaction that changes the page. It rarely shows up as a single slow request, which is why it is easy to overlook, and it is one of the most common hidden causes of a poor Interaction to Next Paint.

From PerfDelta's measurements: In the mobile lab test, 44% of 41,147 home pages have a good Total Blocking Time and 31% a poor one. The median is 265 ms, with the middle half between 54 ms and 774 ms. More in the data section below.

Optimize DOM size: the Lighthouse 13 insight

In Lighthouse 13, and so in PageSpeed Insights, this audit appears as the insight Optimize DOM size. It replaces "Avoid an excessive DOM size" (Lighthouse source code, replacesAudits in core/audits/insights, version 13.5, retrieved 17 October 2026). The causes and fixes below apply under both names.

What the audit checks

Lighthouse reports three numbers: the total number of DOM elements (including elements inside shadow roots, but not iframe content), the maximum depth of nesting, and the element with the most children. Up to Lighthouse 12 the old audit warned above roughly 800 elements and failed above 1,400. The Lighthouse 13 insight no longer judges the element count. It is flagged only when the trace contains a large layout (more than 100 layout objects) or a large style recalculation (more than 300 elements) that takes longer than 40 milliseconds (Chrome for Developers, Optimize DOM size). That matches practice: a page of 1,000 simple elements can be fine, while 600 elements with complex CSS selectors and frequent updates can be slow. The three numbers together point at the cause: a huge total suggests rendered-but-hidden content, deep nesting suggests wrapper divs from a page builder or a component framework, and a very wide parent suggests a long list rendered in full.

Why a large DOM is slow

How to reduce DOM size

1. Find where the elements come from

In Chrome DevTools, the Elements panel shows the tree; the console command document.querySelectorAll('*').length gives the count. To find the heavy branches, count children per section:

// Top-level sections sorted by element count
[...document.body.children]
  .map(el => [el.tagName + (el.id ? '#' + el.id : ''), el.querySelectorAll('*').length])
  .sort((a, b) => b[1] - a[1]);

Typical offenders are mega menus rendered in full, hidden mobile and desktop variants of the same component, carousels with every slide in the DOM, long product grids, embedded widgets, and SVG icons inlined hundreds of times.

2. Stop rendering what is not visible

Content behind tabs, accordions, mega menus and modals does not need to exist until it is opened. Render it on demand where you can, because only that removes elements from the DOM. For long sections below the fold, content-visibility: auto lets the browser skip style, layout and paint for off-screen content. The elements stay in the DOM and still count, but they cost far less work until they scroll into view:

.long-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 800px; /* reserve space, remember the real height once rendered */
}

3. Virtualize long lists

A table with 2,000 rows or a feed with hundreds of cards should render only the rows in and near the viewport. List virtualization libraries exist for every framework; for plain pages, pagination or a "load more" button does the same job with less code.

4. Remove wrapper elements

Page builders and component libraries often wrap each block in three to six divs for spacing and alignment. Modern CSS (grid, flexbox, gap, logical properties) removes the need for most of them. On WordPress, choosing a block-based theme over a shortcode-heavy builder, or switching a builder's output to its leaner markup mode, can halve the DOM.

5. Do not ship two layouts

Rendering a mobile and a desktop version of the header, navigation or product grid and hiding one with CSS doubles the DOM for that component. Build one responsive version. Where two versions are unavoidable, render the second one only at the breakpoint where it is used.

6. Reference repeated SVG icons from a sprite

Inlining the same 40-element SVG icon in 100 list items adds 4,000 elements. Reference a sprite with <use> instead, or load icons as images where interactivity is not needed.

7. Watch third-party embeds

Chat widgets, review carousels, social feeds and cookie banners add their own subtrees, sometimes thousands of elements inside an iframe or directly in the page. The third-party code guide covers loading them later or replacing them with lighter alternatives.

Platform notes

Frequently asked questions

Is 1,400 elements a hard limit?

No. It was the point where the old audit failed up to Lighthouse 12. The Lighthouse 13 insight is only flagged when a style recalculation or layout on a large DOM takes longer than 40 milliseconds. Pages with simple elements and little interaction can be fine above 1,400 elements, and complex pages can be slow below it. Treat the number as a prompt to look for rendered-but-unused content.

Does DOM size affect Core Web Vitals directly?

Indirectly but strongly. Large DOMs make layout and style work slower, which increases INP, and they add to the HTML the browser has to parse before the first paint.

Can I reduce DOM size without changing the design?

Usually. Most of the excess comes from hidden content, duplicate layouts, wrapper elements and full-length lists, none of which the visitor sees. The visible design can stay the same.

How do I find the biggest contributors quickly?

Count elements per top-level section in the DevTools console, then open the largest section in the Elements panel. The pattern is usually obvious within a minute.

What PerfDelta's measurements show

In the mobile lab test, 44% of 41,147 home pages have a good Total Blocking Time and 31% a poor one. The median is 265 ms, with the middle half between 54 ms and 774 ms.

PerfDelta does not store the number of DOM elements as a metric of its own. A large DOM lengthens style recalculation and layout on the main thread, so it shows up in the lab as Total Blocking Time and in the field as INP.

By industry, the median ranges from 187 ms in Public sector and non-profit to 848 ms in Online retail.

Data as of November 30, 2026, recalculated daily. Source: PerfDelta's own measurements (Chrome UX Report and Lighthouse); details in the website speed statistics and the methodology.

Thresholds and sources

Lab test (Lighthouse):

Sources:

All sources retrieved on November 16, 2026. Thresholds and documentation change; the linked page is authoritative.

Test your site

Run a free scan to see whether this applies to your pages, on mobile and desktop, with lab and field data side by side.

Run a free test

A free account saves your tests and shows how your values change from one test to the next. Website performance monitoring with field data and alerts starts with the Solo plan.

Related audits