Lighthouse has an audit called "Avoid an excessive DOM size" that starts complaining at 1,500 elements, 32 levels of depth or 60 children on one parent. I have never once seen it fire on our site , so I never thought about the shape of the DOM at all. This week I measured it properly: every element on all 79 pages in the sitemap , the depth of every branch, every text node and every comment node.
const all = [ . . . document . querySelectorAll ( '*' ) ] ; // elements let max = 0 ; ( function walk ( el , d ) { if ( d > max ) max = d ; for ( const c of el . children ) walk ( c , d + 1 ) ; } ) ( document . documentElement , 1 ) ; const tw = document . createTreeWalker ( document . body , NodeFilter . SHOW_TEXT | NodeFilter .…