"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.
| Measure | Why it matters |
|---|---|
| Total elements | More memory, longer style and layout calculations |
| Maximum depth | Deep nesting makes CSS selector matching and layout more expensive |
| Most children on one element | Long lists and grids re-layout slowly when anything changes |
Step 1: Find What Adds the Most Elements
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
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
gapusually replace them. - In React, use fragments (
<>...</>) instead of extradivwrappers. - 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.