DOM Size Limits for Large Lists | Generated by AI

Home 2026.04

Question: What is the maximum number of such li items that can render in a browser? I now have 7000+ items, is it ok? How about 20k?

Answer:

There is no hard technical limit in modern browsers (Chrome, Firefox, Edge, Safari) on the number of <li> elements you can put inside a <ul> or similar container like a Bootstrap .list-group. Browsers can technically handle tens of thousands of DOM elements.

However, performance is the real constraint, not a strict maximum. Here is a clear breakdown based on current web performance guidelines (as of 2026):

Performance Guidelines for DOM Size

Your single <li class="list-group-item"> element contains:

This means one list item ≈ 5–6 DOM nodes (plus any Bootstrap-added classes or pseudo-elements).

Why Large Lists Cause Problems

The browser must:

Even if the list renders, scrolling through 7k+ or 20k items becomes unpleasant without optimization.

For lists this large, do not render every item at once. Use one of these approaches:

  1. Virtual Scrolling / Windowing (Best for 7k–20k+ items)
    Only render the items currently visible in the viewport (usually 10–30 items at a time). As the user scrolls, new items are added and old ones removed from the DOM.
    Popular libraries:
    • React: react-window or react-virtualized
    • Vue: vue-virtual-scroller
    • Angular: Angular CDK Virtual Scrolling
    • Vanilla JS: Clusterize.js or custom Intersection Observer implementation
  2. Pagination
    Show 50–200 items per page with “Load more” or page numbers.

  3. Infinite Scroll (with virtualization)
    Load more items as the user scrolls, but still only keep a limited number in the DOM.

  4. Filtering/Search on the server or client
    Let users search or filter first so fewer items are shown.

  5. Simple optimizations if you must keep all items
    • Use will-change: transform; or CSS containment
    • Avoid heavy CSS (complex selectors, shadows, etc.) on list items
    • Use document.createDocumentFragment() when building the list in JavaScript
    • Consider a <table> with fixed layout or a canvas-based list for extreme cases

Quick Test Recommendation

Try rendering your 7,000 items in an incognito window and check:

If you notice lag with 7,000 items, you should implement virtualization before going to 20,000.

In summary:

Switching to virtual scrolling will let you comfortably handle 20k, 50k, or even 100k+ items with smooth performance.

References:


Back Donate