Tool

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.

0 B

Need to strip ads or CMS chrome first? Open HTML Cleaner & Token Saver, or upload a static file to the HTML Translator.

Reference

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

RuleEnforced behaviorFailure prevented
Heading GuardNever ends a chunk on h1 through h6; keeps headings bound to the next content blockOrphaned titles lose topic context in the next prompt
Fake-Heading GuardTreats short bold-only paragraphs under 15 words as headingsCMS step labels detach from the instructions below them
Atomic Block IntegrityKeeps pre, table, blockquote, figure, ul, and ol elements wholeMid-tag cuts break table columns, list nesting, and code samples
Block-Boundary OnlySplits only before standalone block elements, never before inline tags or textSevered 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 sizePrimary workflowBudgeting note
1,000 tokensRAG indexing and semantic retrievalCompact passages keep embedding recall sharp
2,000 tokensHTML localization and structured API loopsLeaves output headroom for 20-35% German or French expansion
4,000 tokensTechnical guides with cross-referencesPreserves section terminology; verify model max output tokens
8,000 tokensLong-context summarization and auditsHigher 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.