HTML-to-LLM Chunk Splitter
Split long HTML articles and documentation exports into balanced, tag-safe chunks for LLM APIs, translation scripts, and RAG indexing without orphaning headings or cutting code blocks.
100% client-side: Your files never leave your browser.
Need to strip ads or CMS chrome first? Open HTML Cleaner & Token Saver, or upload a static file to the HTML Translator.
Tag-safe HTML chunking for LLM APIs and RAG
Automated translation scripts, summarizers, and RAG pipelines routinely break markup when long HTML pages are divided by raw character counts. A fixed slice can leave unclosed tags, detach a heading from its section, or bisect a code block. Structure-aware chunking parses top-level HTML nodes inside the document body and emits balanced fragments ready for JSON batch processing.
Four structure-aware splitting rules
| Rule | Enforced behavior | Failure prevented |
|---|---|---|
| Heading Guard | Never ends a chunk on h1 through h6; keeps headings bound to the next content block | Orphaned titles lose topic context in the next prompt |
| Fake-Heading Guard | Treats short bold-only paragraphs under 15 words as headings | CMS step labels detach from the instructions below them |
| Atomic Block Integrity | Keeps pre, table, blockquote, figure, ul, and ol elements whole | Mid-tag cuts break table columns, list nesting, and code samples |
| Block-Boundary Only | Splits only before standalone block elements, never before inline tags or text | Severed spans, anchors, and sentences corrupt downstream markup |
Recommended chunk budgets
Estimated tokens use a rough four-characters-per-token heuristic. When localizing HTML into verbose target languages such as German or French, choose a smaller input budget so expanded output HTML fits safely below the model response ceiling.
| Chunk size | Primary workflow | Budgeting note |
|---|---|---|
| 1,000 tokens | RAG indexing and semantic retrieval | Compact passages keep embedding recall sharp |
| 2,000 tokens | HTML localization and structured API loops | Leaves output headroom for 20-35% German or French expansion |
| 4,000 tokens | Technical guides with cross-references | Preserves section terminology; verify model max output tokens |
| 8,000 tokens | Long-context summarization and audits | Higher latency per call; best when cross-section context is essential |
FAQ
How are oversized table or pre blocks handled?
Tables, preformatted code blocks, blockquotes, figures, and lists are never cut mid-tag. If a single atomic block or a heading paired with its mandatory next block exceeds the budget, it is emitted whole in its own chunk with an Oversized atomic block badge.
Why does unwrapping a single outer article or main tag matter?
Most exported pages wrap every heading and paragraph inside one article, main, section, or div container. Without descending into that wrapper, a tag-safe splitter sees only one top-level element and cannot divide the document.
How does the JSON chunk output map into a Python script?
The exported html-chunks.json file is an ordered array of objects containing index, firstHeading, estimatedTokens, words, bytes, and html. A Python loop can iterate through each entry, send item['html'] to an LLM or RAG endpoint, and reassemble outputs by index.
How does DOM-block chunking differ from character splitting?
Character splitting slices raw strings at fixed offsets, leaving unclosed tags, severed entities, and orphaned headings. Block-boundary chunking parses balanced HTML nodes so every chunk opens and closes cleanly on standalone block boundaries.
Does splitting upload HTML files to a server?
No. Parsing, optional safe cleaning, and export run locally in the browser. Files stay on the computer, and inputs above 2 MB are paused.
See translating HTML files with Python and BeautifulSoup and extracting translatable strings from HTML to JSON. Strip noisy markup first in HTML Cleaner & Token Saver, translate static files in the HTML translator, browse the tools hub, or return to the HTML Translate home page.