Skip to content
SEO Optimizer is live, Audit on page SEO and AI-search readiness. Try it free

How to Fix 'Avoid an Excessive DOM Size'

"Avoid an excessive DOM size" is a common performance warning. The DOM is the tree of elements the browser builds from your HTML. Every element costs memory, and every style change, layout and interaction has to walk more of the tree when it is large. An excessive DOM size makes pages slower to render and slower to respond to taps and clicks, which shows up as poor Interaction to Next Paint (INP) and Total Blocking Time.

What Counts as an Excessive DOM Size

Performance audits typically start warning at around 800 elements in the page body and flag it as a problem above about 1,400. They also look at the deepest nesting and the element with the most direct children. There is no hard limit: a page with 2,000 simple elements can be fast, and a page with 1,200 complex ones can be slow. Treat the number as a hint to look for waste.

MeasureWhy it matters
Total elementsMore memory, longer style and layout calculations
Maximum depthDeep nesting makes CSS selector matching and layout more expensive
Most children on one elementLong lists and grids re-layout slowly when anything changes

Step 1: Find What Adds the Most Elements

devtools consoleCount elements and find the biggest containers
// Total elements on the page
document.querySelectorAll("*").length;

// The 10 elements with the most descendants
[...document.querySelectorAll("body *")]
  .map((el) => [el, el.querySelectorAll("*").length])
  .sort((a, b) => b[1] - a[1])
  .slice(0, 10);

Common causes of an excessive DOM size:

  • Mega menus rendered in full on every page, often twice (desktop and mobile).
  • Long product grids, feeds and tables that render hundreds of items at once.
  • Hidden content such as tabs, accordions, modals and carousels that are in the DOM even when not shown.
  • Wrapper divs from page builders and component libraries, several levels deep around every element.
  • Inline SVG icons repeated many times.
  • Third-party widgets such as reviews, chat and social embeds.

Step 2: Render Less Up Front

  • Paginate or load more. Show 24 products and a "Load more" button instead of 200.
  • Virtualize long lists. Render only the rows on screen with a virtual list library, such as TanStack Virtual or react-window.
  • Render hidden panels on demand. Mount modal, tab and accordion content when it is opened, not on page load.
  • Load menus lazily. Build the mobile menu when the menu button is tapped, or reuse one menu for both layouts with CSS.

Step 3: Use content-visibility for Long Pages

styles.cssSkip rendering work for off-screen sections
.below-the-fold-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 800px;
}

content-visibility: auto lets the browser skip layout and painting for sections that are off screen. It does not reduce the number of elements, but it removes much of their cost until the user scrolls to them. Set contain-intrinsic-size to a realistic height so the scrollbar does not jump.

Step 4: Flatten the Markup

  • Remove wrapper elements that exist only for spacing. CSS grid and flexbox with gap usually replace them.
  • In React, use fragments (<>...</>) instead of extra div wrappers.
  • Use an SVG sprite with <use> instead of pasting the same inline SVG many times.
  • In page builders, simplify sections and avoid nesting columns inside columns.

Step 5: Measure the Effect

Run a website audit before and after. The report shows DOM size alongside the metrics it affects most, INP and Total Blocking Time, and links DOM size to them as a likely cause, so you can see whether reducing it actually helped. If interactions are still slow, the JavaScript running on each interaction is usually the bigger problem: see how to fix INP and how to reduce unused JavaScript. For the bigger picture, the Core Web Vitals guide explains how each metric is measured.

When Not to Worry About an Excessive DOM Size

If a page is slightly over the threshold and INP, LCP and CLS are all good, the warning is low priority. Spend the time on whatever is slowest for real users first. An excessive DOM size matters most on pages with lots of interaction, such as filters, carts and dashboards, and on low-end phones.

FAQ

Häufig gestellte Fragen

Performance audits usually warn when a page body has more than about 800 elements and flag it above about 1,400, or when nesting is very deep or one element has very many children.

Yes, mainly Interaction to Next Paint, because every interaction that changes the page has to recalculate styles and layout across more elements. It can also slow initial rendering.

Paginate or virtualize long lists, render modals and tabs only when open, use fragments instead of wrapper divs and avoid rendering desktop and mobile versions of the same component.

No, the elements still exist, but content-visibility: auto lets the browser skip rendering work for off-screen sections, which removes much of their cost.

Kostenlos - keine Anmeldung nötig

Check this on your own site

Run a free scan and see exactly where you stand - no sign-up required.

Kostenlosen Audit starten