# Reduce DOM complexity

- Check 06.21 · Performance and Core Web Vitals · Important
- Source: https://checklist-seo-geo.com/en/performance-core-web-vitals/reduce-dom-complexity
- Measure the size and depth of the DOM, then slim it down: pagination, flatter markup, menus, page builders, on common CMSs and frameworks.
- Updated on 2026-11-25
- Licence: CC BY 4.0. Credit “Checklist SEO & GEO” with a link to https://checklist-seo-geo.com/en/performance-core-web-vitals/reduce-dom-complexity.
- Plugin checklist-seo-geo: 1.3.1 · https://github.com/maximegaul/checklist-seo-geo

## In short

The DOM (Document Object Model) is the tree of elements the browser builds from the HTML. The more nodes it has and the deeper it is, the more expensive every style calculation, every layout and every interaction becomes. This check consists of measuring this tree, finding the blocks that bloat it (page builder, mega menu, long lists, duplicate markup for mobile and desktop) and slimming them down without removing useful content. Expected result: pages that are lighter to parse and more responsive, especially on modest phones.

## Why it matters

A large DOM weighs on three moments:

- **At load time**: the HTML is heavier to transfer and parse, and a large share of the nodes is not even visible in the first screen.
- **At runtime**: on every change (opening a menu, adding to the cart, typing in a field), the browser recalculates the styles and the position of the elements concerned. The larger the tree and the broader the CSS selectors, the longer this calculation takes. It is a direct cause of poor INP (Interaction to Next Paint, the responsiveness to interactions).
- **In memory**: scripts that traverse or hold on to large sets of nodes saturate entry-level devices. On a site rendered by a JavaScript framework, the cost of hydrating each component comes on top.

Lighthouse flags the problem based on documented thresholds: a warning beyond about 800 nodes in the `<body>`, an error beyond about 1,400. It also reports the maximum depth and the largest number of children of a single parent. These thresholds are audit benchmarks, not ranking factors: what matters is the responsiveness measured for your visitors.

## What it improves

- **INP**: this is the main benefit. See [target INP ≤ 200 ms at the 75th percentile](https://checklist-seo-geo.com/en/performance-core-web-vitals/target-inp-200-ms-at-75th-percentile).
- **Rendering time**: styles and layout are calculated faster, so first display and LCP (Largest Contentful Paint) improve slightly.
- **HTML weight**: fewer bytes to transfer and parse, for visitors as well as crawlers.
- **Maintenance**: flatter markup is easier to style and evolve.
- **Rankings**: indirect effect, through Core Web Vitals. DOM size is not a factor in itself.

## How to check

In the console, on the loaded page:

```js
const nodes = [...document.querySelectorAll('body *')];

const depthOf = (element) => {
  let depth = 0;

  while (element.parentElement) {
    element = element.parentElement;
    depth += 1;
  }

  return depth;
};

console.log('Nodes:', nodes.length);
console.log('Maximum depth:', nodes.reduce((max, el) => Math.max(max, depthOf(el)), 0));
console.log('Largest number of children:', nodes.reduce((max, el) => Math.max(max, el.children.length), 0));
```

Then spot the heaviest blocks:

```js
console.table(
  [...document.body.children]
    .map((element) => ({
      bloc: element.tagName.toLowerCase() + (element.id ? '#' + element.id : ''),
      noeuds: element.querySelectorAll('*').length,
    }))
    .sort((a, b) => b.noeuds - a.noeuds)
);
```

Repeat the second command, replacing `document.body` with the heaviest block (`document.querySelector('#main')`), to go down the tree until you find the culprit.

Other methods:

- **PageSpeed Insights or Lighthouse**: the DOM size audit gives the total number of elements, the maximum depth and the element with the most children. See [analyze PageSpeed Insights and Lighthouse](https://checklist-seo-geo.com/en/performance-core-web-vitals/analyze-pagespeed-insights-lighthouse).
- **Performance tab**: record a slow interaction. Long “Recalculate style” or “Layout” tasks point to an oversized DOM or overly broad selectors.

Check each template: home, category, product page, article. List pages are almost always the heaviest.

## How to implement

### Before you start

Techniques that apply everywhere, from the most cost-effective to the most fine-grained:

- **Paginate long lists** (products, articles, comments, table rows), with real links to the next pages so that crawlers follow them. See [check dynamic pagination](https://checklist-seo-geo.com/en/javascript-html-rendering/check-dynamic-pagination).
- **Do not duplicate markup** for mobile and desktop. Two menus, two headers or two grids, one of which is hidden in CSS, double the number of nodes: an element hidden with `display: none` stays in the DOM. Write a single responsive markup.
- **Slim down the mega menu**: keep in the HTML the navigation links that matter for internal linking, and remove the thumbnails, promotions and rarely visited third levels. See [optimize mobile menus](https://checklist-seo-geo.com/en/mobile-first-responsive-design/optimize-mobile-menus).
- **Flatten containers**: CSS Grid and Flexbox (with `gap`) replace the row, column, wrapper, content stacks inherited from older grid systems.
- **Only render modals, panels and tooltips when they open**, unless they carry content to be indexed.
- **Move large SVGs out of the HTML**: an inline vector illustration can count hundreds of nodes. Serve it as a file (`<img src="illustration.svg">`). For repeated icons, use a sprite and `<use>`.
- **Limit the rendering work of lower sections** with `content-visibility`. The nodes remain, but the browser only computes their rendering as they approach the visible area:

```css
.below-the-fold {
  content-visibility: auto;
  contain-intrinsic-size: auto 800px;
}
```

```html
<section class="below-the-fold">
  <h2>Customer reviews</h2>
</section>
```

> **Warning:** do not slim down the DOM by removing from the HTML content or links that search engines need to see. Paginating, simplifying markup and removing duplicates cost nothing in SEO terms; loading the main text on scroll or on click does.

### WordPress

Versions: WordPress 6.4 and later (up to 7.1), WooCommerce 8 and later.

Page builders are the leading cause of an excessive DOM: every section, column and widget adds several levels of wrappers.

- **Elementor**: build with Flexbox and Grid containers rather than the old sections and columns structure, and enable, in Elementor's settings, on the features tab (`Elementor > Settings > Features` on Elementor 3.x), the optimized markup options your version offers. Replace nested inner sections with a single container.
- **Divi, WPBakery, Beaver Builder**: same logic. Limit nesting, delete modules hidden per device (they stay in the HTML) and prefer a single responsive module.
- **Block editor**: the markup is much lighter. For a critical template (home page, sales page), rebuilding it with native blocks is often the clearest gain.

Additional settings:

- **Posts per page**: `Settings > Reading`.
- **Comments**: `Settings > Discussion`, the option to break comments into pages.
- **WooCommerce**: with a classic theme, `Appearance > Customize > WooCommerce > Product Catalog`, products per row and rows per page. With a block theme, these settings are made in the product grid block (Product Collection), from `Appearance > Editor`.
- **Menus**: `Appearance > Menus` (or the Navigation block), reduce the depth. Mega menu plugins generate a lot of markup: check their share with the command in the previous section.
- **Footer and sidebar widgets**: remove those that no longer serve a purpose.

### Shopify

Versions: Online Store 2.0 themes (Liquid), November 2026.

Paginate collections and limit what each product card displays:

```liquid
{% paginate collection.products by 24 %}
  <ul class="product-grid">
    {% for product in collection.products %}
      <li>{% render 'card-product', card_product: product %}</li>
    {% endfor %}
  </ul>

  {{ paginate | default_pagination }}
{% endpaginate %}
```

The usual sources of excess: every variant rendered as swatches in each card, a mobile menu and a desktop menu generated separately, many sections stacked on the home page, and app blocks. In the theme editor, delete hidden sections and blocks rather than leaving them disabled in CSS.

### PrestaShop

Versions: PrestaShop 8 and 9.

- **Products per page**: `Shop Parameters > Product Settings`, Pagination section.
- **Faceted navigation**: in the faceted search module, limit the number of filters and values displayed per category. Each value is a group of nodes.
- **Main menu**: reduce the depth in the menu module's configuration.
- **Modules hooked to the home page**: each product carousel adds a complete grid. Keep one or two (`Design > Positions`).

### Magento

Versions: Magento Open Source and Adobe Commerce 2.4 (up to 2.4.9).

- **Products per page**: `Stores > Configuration > Catalog > Catalog > Storefront`, allowed values and default value for the grid.
- **Menu depth**: same catalog configuration screen, Category Top Navigation section, maximal depth.
- **Layered navigation**: limit filterable attributes to those customers actually use.

The Luma theme produces bulky markup. The Hyvä theme greatly reduces the DOM and the JavaScript: it is a theme rebuild, to be assessed as a project.

### Drupal

Versions: Drupal 10 and 11.

Drupal wraps each field and each block in several `<div>` elements. Override the relevant Twig templates (`field.html.twig`, `block.html.twig`, `views-view-unformatted.html.twig`) in your theme to remove unnecessary wrappers. In views, enable a pager and limit the number of items per page (`Structure > Views`, Pager section). With Paragraphs or Layout Builder, avoid nesting more than two levels deep.

### Wix

Versions: Wix (Wix Editor and Wix Studio) and Squarespace, November 2026.

You do not control the generated markup. Your levers: fewer sections and elements per page, no duplicate elements hidden for mobile when a single one can adapt, and lists and galleries limited with a button or pagination. Same approach on Squarespace.

### Webflow

Versions: Webflow, all plans, November 2026.

The markup matches what you build in the Navigator: delete intermediate `div` blocks that serve no purpose, use Grid and Flexbox on the parent, limit the number of items in Collection lists and enable their pagination.

### Laravel

Versions: Laravel 11 to 13, Livewire 3 and later.

Paginate on the server side and keep Blade components free of superfluous wrappers:

```php
$products = Product::query()
    ->with('category')
    ->latest()
    ->paginate(24);
```

```html
<ul class="product-grid">
    @foreach($products as $product)
        <li><x-product-card :product="$product" /></li>
    @endforeach
</ul>

{{ $products->links() }}
```

With Livewire, a large DOM costs twice: at render time, then on every update, when the component compares the old and new HTML. Split long lists into paginated components.

### Symfony

Versions: Symfony 6.4 and later (up to 8.1), Symfony UX Turbo.

Same approach with Doctrine's paginator or a pagination bundle. In Twig, prefer `{{ include('product/_card.html.twig') }}` without an extra container around each include, and render modals on demand (Turbo Frames with Symfony UX) rather than one per list row.

### Next.js

Versions: Next.js 15 and 16 (App Router).

- **Fragments**: `<>...</>` avoids adding a `<div>` per component.
- **Conditional rendering**: only mount a modal or a panel when it is open (`{open && <Dialog />}`), instead of hiding it in CSS.
- **URL-based pagination** (`searchParams`) for lists that need to be indexed.
- **Virtualization** (TanStack Virtual, react-window) for very long interface lists, which only render the visible rows. Keep it for application screens: virtualized content is not in the HTML.

Server components reduce JavaScript and hydration, not the number of nodes.

### Nuxt

Versions: Nuxt 3 and 4.

Same principles: `v-if` removes the element from the DOM while `v-show` keeps it hidden; a `<template>` groups elements without adding a node; long interface lists are virtualized with a dedicated library; content lists are paginated through the URL.

### Astro

Versions: Astro 5 to 7.

Astro adds almost no markup: the DOM is that of your components. Keep an eye on framework islands, each instance of which adds its own tree, and paginate collections with the `paginate()` function of dynamic routes.

## Common mistakes

- **Hiding instead of removing**: `display: none` and the builders' “hide on mobile” options leave the nodes in place.
- **Unlimited infinite scroll**: each batch added grows the DOM, and the page slows down as the visitor scrolls.
- **Virtualizing or loading on click content that needs to be indexed**: crawlers no longer see it.
- **Removing navigation links useful for internal linking** to save a few nodes.
- **Aiming for the Lighthouse threshold rather than real responsiveness**: a category page can exceed the threshold and stay smooth, while a smaller page can be slow because of its scripts.
- **Stacking layers**: theme, page builder, mega menu plugin and carousel plugin each add their own wrappers.
- **Writing universal or very broad CSS selectors** (`* { ... }`, `div div div a`) on a large DOM: every style recalculation becomes heavier.

## Frequently asked questions

### How many DOM nodes are acceptable?

Lighthouse warns beyond about 800 nodes in the body and reports an error beyond about 1,400. These thresholds are audit benchmarks, not ranking factors: a category page can exceed them and stay smooth, while a smaller page can be slow because of its scripts. What matters is the responsiveness measured for your visitors, in particular INP.

### Does hiding an element in CSS reduce DOM size?

No. An element hidden with display: none, or with a page builder's “hide on mobile” option, stays in the DOM and still weighs on parsing and style recalculations. To reduce the DOM, write a single responsive markup rather than separate mobile and desktop versions, and only render modals and panels when they open, unless they carry content to be indexed.

### Do page builders bloat the DOM?

Yes, they are the leading cause of an excessive DOM on WordPress: every section, column and widget adds several levels of wrappers. With Elementor, prefer Flexbox and Grid containers to the old sections and columns structure; with Divi, WPBakery or Beaver Builder, limit nesting and delete modules hidden per device. For a critical template, rebuilding it with native blocks often pays off most.

### Does reducing DOM size improve SEO?

Indirectly. DOM size is not a factor in itself; it weighs on INP, because every interaction forces the browser to recalculate styles and layout, and slightly on LCP. Be careful with the method: paginating, flattening markup and removing duplicates cost nothing in SEO terms, but removing from the HTML links or content that search engines need to see does harm.

## Resources

- [Chrome for Developers: Avoid an excessive DOM size](https://developer.chrome.com/docs/lighthouse/performance/dom-size?hl=en)
- [web.dev: How large DOM sizes affect interactivity](https://web.dev/articles/dom-size-and-interactivity?hl=en)
- [web.dev: content-visibility](https://web.dev/articles/content-visibility?hl=en)
- [MDN: content-visibility](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/content-visibility)
- [Shopify: paginate tag](https://shopify.dev/docs/api/liquid/tags/paginate)
- [Laravel: Pagination](https://laravel.com/docs/pagination)
- [Astro: Pagination](https://docs.astro.build/en/guides/routing/#pagination)

Next steps: [remove unused CSS and JavaScript](https://checklist-seo-geo.com/en/performance-core-web-vitals/remove-unused-css-js) and [defer non-essential scripts](https://checklist-seo-geo.com/en/performance-core-web-vitals/defer-non-essential-scripts).
