Speed & performance · Guide
How to Reduce DOM Size in WordPress
Short answer
To reduce DOM size in WordPress, measure the page in Lighthouse, then cut the largest branches first: show fewer posts and comments per page, flatten nested builder wrappers, trim menus and widgets, and defer below-fold content until it is needed. Aim for fewer than about 800 nodes in the body, then rerun Lighthouse on the same page to confirm the change.
Key takeaways
- Lighthouse warns above about 800 nodes in the body and errors above about 1,400 nodes, as of November 2026.
- A large DOM slows first render, later updates and interaction, and can raise memory use.
- Long lists, deep builder wrappers, large menus, many widgets and unpaginated comments are the usual causes in WordPress.
- Elementor 3.19 built its Optimized DOM Output changes into the core plugin, so no toggle is needed on later versions.
- Content-visibility skips rendering work for off-screen sections, but it does not remove nodes from the DOM.
- Recheck the same page in Lighthouse after each change and compare total nodes, depth and most children.
What is DOM size in WordPress?
DOM size is the number of elements in the tree a browser builds from your page HTML.
The DOM, or Document Object Model, is the structure of your page HTML. Every heading, link, image wrapper, menu item, widget, form field and builder section adds nodes to that tree.
WordPress does not set the size directly. Your theme, plugins, page builder, menus and content set it together.
A large tree costs time in three ways, as Chrome for Developers explains. It adds data for nodes that are not visible at first load, it forces the browser to recompute positions and styles during use, and it can hold many node references in memory.
How do you check your DOM size in WordPress?
Run Lighthouse, then read the total elements, maximum depth and most children it reports.
Open the page in Chrome, run Lighthouse, and look under Diagnostics for the DOM size audit. Chrome for Developers states that Lighthouse reports the total DOM elements for a page, the maximum DOM depth and its maximum child elements. Write down all three numbers before you change anything, so later runs compare like with like.
You can also count elements in the browser console with one line, as web.dev shows:
document.querySelectorAll('*').length;
Run it after the page has loaded. web.dev notes that you can watch the count change live with the performance monitor tool in Chrome DevTools.
Check the worst page first, such as the home page, a long archive or a product list, not only a short post.
For a wider view of interaction, read the guide on how to improve Interaction to Next Paint in WordPress after you have your baseline numbers.
What DOM size should you aim for?
Aim for fewer than about 800 nodes in the body, and treat more than about 1,400 as a clear fail.
Chrome for Developers states that Lighthouse warns when the body element has more than about 800 nodes and errors when it has more than about 1,400 nodes.
Those are warning levels from the audit, not a ranking cutoff. A page just above 800 is not broken, and a page just below it is not automatically fast.
Use the numbers as a budget for decisions. If a page has 3,000 nodes, look for one large list or one repeated section to cut first.
If it has 900 nodes, check depth and the widest parent before you rebuild the page. Depth matters too, because deeply nested wrappers make each style and layout pass harder.
For context, the 2022 Web Almanac Markup chapter found a median of 653 elements per page on mobile, and 1,832 at the 90th percentile, as reported in the Web Almanac. That shows many real pages sit near the warning level, and the heaviest tenth sit well past it.
What makes a WordPress DOM too large?
Long lists, deep builder wrappers, large menus, many widgets and unpaginated comments are the usual causes.
Each cause adds nodes in a different way, so name the cause before you pick a fix:
- Long post lists and product grids repeat the same card markup for every item.
- Page builders wrap content in sections, columns and inner wrappers, and each wrapper is a node.
- Mega menus put every submenu link in the HTML, even links a visitor never opens.
- Sidebars, footers and popups repeat on every page, so their nodes count on every page.
- Long comment threads add a block of markup for each comment and each reply level.
- Hidden mobile and desktop copies of the same section double the nodes for one visible result.
web.dev explains that a large DOM makes the first render dearer and makes later updates dearer too, because style, layout, compositing and paint work grows with the tree.
The 2025 Web Almanac CMS chapter adds a WordPress angle: page builders change DOM complexity, and they are a major source of performance variation, as reported in the Web Almanac.
In that chapter, WordPress powered about 64% of CMS-driven sites, and Elementor remained the most used page builder at about 43%, down from about 56% in 2024.
Check which cause fits your page by looking at the element Lighthouse names as the widest parent. Fix that branch first.
How do you cut posts and comments on one page?
Show fewer posts per page and split long comment threads into pages.
This is the fastest win on archives and busy posts, because each item you remove takes its whole card or comment block with it. Follow these steps:
- Go to “Settings → Reading” in the WordPress admin.
- Lower “Blog pages show at most” to a smaller number, such as 6 or 9 for a card grid.
- Click “Save Changes” and recheck the archive in Lighthouse.
- In a block theme, open the Query Loop block for that template and set its “Items per page” value to match, then check that its Pagination block is present.
- Go to “Settings → Discussion”.
- Tick “Break comments into pages” and set the number of top level comments per page.
- Save, then open a busy post and check that only one page of comments loads at first.
WordPress.org documents the comment setting as "Break comments into pages with [X] top level comments per page", as shown on the Settings Discussion screen.
The same page notes that threaded comments can go up to 10 levels deep, so a long nested thread can add many nodes even with few top level comments. Lower the thread depth if replies nest too far.
Pick a count that fits the layout and keeps the page useful.
For related page weight work, see how to avoid enormous network payloads in WordPress.
How do you flatten nested builder sections?
Remove wrapper layers you do not need, and use one container instead of a section inside a section inside a column.
web.dev gives the clearest test for this problem: if you see four nested div elements with only content inside the last one, you can probably flatten that structure.
Flattening cuts node count and often lets you simplify the styles that depended on those wrappers. Modern layout modes such as flexbox or grid can replace several nested wrappers with one parent.
Work through the page in this order:
- Open the page in the editor and list each section, column and inner block.
- Delete empty spacers, separators, duplicate headings and empty columns.
- Merge two next-door sections that share the same background and layout.
- Replace a column that holds only one widget with a plain block.
- Check the front end after each change, because a wrapper may carry padding or a background you need to move to the parent.
Elementor states that Optimized DOM Output aims to improve performance by decreasing the number of wrapper elements in the HTML Elementor generates.
The same page states that, starting with Elementor 3.19, those DOM improvements were fully built into Elementor Core and were no longer optional. So if your site runs Elementor 3.19 or later, as of November 2026, do not hunt for that toggle.
If you use Elementor, read how to speed up Elementor for its other settings, and keep builder changes separate from theme changes so you can tell which one helped.
What should you check after flattening?
Check layout, spacing and mobile view on the same page you changed. A flattened section can lose padding that lived on a removed wrapper.
Also check any custom CSS that named a removed class, because that rule will stop matching. Fix the CSS or restore the wrapper before you move to the next page.
How do you trim menus, widgets and footer blocks?
Keep only the links and blocks a visitor needs on that page, and remove the rest from the shared template.
Menus, sidebars and footers repeat on every page, so a small cut there pays off site wide. Go to “Appearance → Menus” and count the items.
A menu with dozens of links adds a list item and a link node for each one, plus wrappers for dropdowns. Remove links that duplicate the footer, merge near-duplicate categories, and move deep levels to a category page instead of the main menu.
Then audit the shared areas:
- Remove a widget that repeats a link already in the main menu.
- Replace three small widgets with one simple block where the content allows it.
- Remove a popup, chat panel or announcement bar from pages where it is not needed, or set it to load only after a click.
- Check for two copies of the same menu, one for desktop and one for mobile, and keep one responsive menu if your theme offers it.
- Remove social icons, badges and counters that add markup but no task.
Hidden content still counts. Chrome for Developers advises that you look for nodes that are not displayed on first load, and create them only after a relevant interaction such as a scroll or a button click. A hidden section is still parsed and styled, even if a visitor never sees it.
How do you defer content that is not needed at first?
Load below-fold sections, tabs, accordions and embeds only when a visitor reaches them or asks for them.
web.dev describes this as an additive approach: omit parts of the DOM on startup, then add them when the user interacts with the part of the page that needs them.
That cuts the first render work and the first HTML payload, and it gives early interactions less competition for the main thread. Show a loading sign while data is fetched, so a visitor knows something is coming.
Use this table to pick the right method for each block:
| Block | Defer it by | Keep in mind |
|---|---|---|
| Long list below the fold | Load more button or pagination | Keep the first items in the HTML for readers |
| Tab or accordion panel | Create its content on first click | Keep the tab label and heading visible |
| Video or map embed | Click-to-load image first | The embed still needs a clear label |
| Comments | Paginate, or load on click | Keep the comment count visible |
| Off-screen section | content-visibility: auto in CSS | Nodes stay in the DOM, but rendering is skipped |
The last row needs care. web.dev explains that the content-visibility property lazily renders off-screen DOM elements, and they are rendered on demand as they approach the viewport.
It cuts rendering work, but it does not remove nodes from the DOM or stop scripts from running. Pair it with contain-intrinsic-size so the page keeps a placeholder height and does not jump when the section renders.
Do not defer the main heading, the first paragraph or the main image. Those belong in the first view, and hiding them will hurt readers and the largest contentful paint. For that metric, see how to improve Largest Contentful Paint in WordPress.
How do you simplify CSS selectors?
Use short, simple selectors, and avoid rules that force the browser to walk the whole tree for every change.
Chrome for Developers notes that if you cannot avoid a large DOM tree, simplifying your CSS selectors is another way to improve rendering performance.
web.dev adds that complex selectors add work both at first render and when the page changes after an interaction. The browser must traverse the DOM to work out where each selector applies.
Practical steps are:
- Replace a long chain such as
body .site .content .list .item awith a single class on the link. - Avoid the universal selector and broad tag rules where a class will do.
- Remove CSS for blocks, widgets and sliders you deleted.
- Keep the number of rules that match many elements low, especially rules that change on hover or focus.
You do not need to rewrite a whole theme stylesheet in one pass. Start with the rules that target the widest parent or the deepest branch you found in Lighthouse. That is where selector work is dearest.
How do you check that reducing DOM size worked?
Rerun the same Lighthouse audit on the same page, and compare total nodes, depth, most children and INP.
Allow 30 to 60 minutes for a first pass on one template, then recheck. Use the same page, the same device type and the same test settings each time, or the numbers will not compare. Record the three Lighthouse numbers before and after each change, and change one thing at a time where you can.
Look beyond the node count too. web.dev shows how to select a “Recalculate Style” item in the Chrome DevTools performance panel and read how many DOM elements it affected.
In its example, one style recalculation affected 2,547 DOM elements, and the shaded part passed 200 milliseconds, which the guide calls the designated “good” threshold for INP.
Also check the page by hand. Click the menu, open tabs and accordions, submit a form and scroll to the footer.
A cut that breaks a menu or hides a form is not a win. If you changed CSS, check the page on a phone width as well as a desktop width.
For a full pass, follow how to pass Core Web Vitals in WordPress and recheck the other metrics that a large DOM can drag down.
Render-blocking work is one of those metrics, as covered in how to eliminate render-blocking resources in WordPress.
What mistakes should you avoid?
Do not chase the node count by deleting content, hiding the main content, or adding a cache plugin and expecting the DOM to shrink.
A cache plugin does not remove DOM nodes, because the nodes come from the HTML your theme and content produce. Deleting useful sections, hiding the main heading or removing form fields will lower the count and hurt the page. Keep the content a visitor came for, and cut wrappers, repeats and deferred blocks instead.
Other mistakes to avoid are:
- Changing five things at once, then not knowing which one helped.
- Removing a wrapper that carried padding, then leaving a broken layout.
- Deleting a menu link that was the only path to a key page.
- Using
display: noneon a large section and assuming it no longer costs anything. - Forgetting to recheck after a theme or plugin update, which can add wrappers back.
If the count stays high after you cut lists, menus and wrappers, check whether a plugin injects a large block on every page, such as a review widget. Disable it on a staging copy, measure again, and only then decide whether to keep or limit it.
Frequently asked questions
What is a good DOM size for a WordPress page?
Aim for fewer than about 800 nodes in the body of the page. Lighthouse warns above that level and errors above about 1,400 nodes. Treat those levels as a budget, not a strict pass mark. A page just above 800 can still work well, and a page below it can still be slow if scripts or images are heavy.
Does a cache plugin reduce DOM size?
No. A cache plugin stores and serves pages faster, but it does not remove HTML elements from the page. DOM nodes come from your theme, page builder, menus, widgets and content. To cut nodes, you must remove or defer markup, flatten wrappers, or show fewer items per page.
Will reducing DOM size improve my Core Web Vitals?
It can help, mainly by cutting style and layout work when a page renders or changes. That work feeds into interaction speed and can affect Largest Contentful Paint on heavy pages. It is only one factor, so also check images, scripts and server response time if scores stay low after you cut nodes.
How many posts should I show per page in WordPress?
There is no single right number. Many card grids work well with 6, 9 or 12 posts per page, while a simple text list can show more. Pick a count that fits your layout, keeps the page useful, and keeps the node count near your budget. Then check the archive in Lighthouse and adjust if needed.
Is it safe to delete builder wrappers to cut DOM size?
It is safe if you check the result. Wrappers can carry padding, backgrounds or custom CSS rules. After you remove one, check the page on desktop and phone widths, click menus and tabs, and look for lost spacing. Make the change on a staging copy first if the page is important.
Does content-visibility remove elements from the DOM?
No. Content-visibility tells the browser to skip rendering work for off-screen elements until they are needed. The elements stay in the DOM and remain in the page structure. Use it to cut rendering work on long pages, and pair it with a placeholder size so the page does not jump when a section renders.
Sources
- Avoid an excessive DOM size Chrome for Developers
- How large DOM sizes affect interactivity, and what you can do about it web.dev
- Markup | 2022 | The Web Almanac by HTTP Archive HTTP Archive
- CMS | 2025 | The Web Almanac by HTTP Archive HTTP Archive
- Settings Discussion screen WordPress.org
- Optimized DOM Output and custom code Elementor
- Core Blocks Reference WordPress Developer Resources
Is your product missing, or something out of date?
Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.
Thanks — we review requests within 3 business days.
