The hOCR format is an open specification that represents optical character recognition (OCR) results using HTML and CSS-like classes. It encodes the recognized text, its precise spatial layout on the page, and per-word confidence scores within a single, machine-readable document. By embedding this metadata directly into the markup, hOCR bridges the gap between a raw image and a structured, searchable text layer.
Glossary
hOCR Format

What is hOCR Format?
hOCR is an open standard for encoding OCR output in an HTML-like markup, embedding recognized text, layout coordinates, and confidence scores directly into a structured document.
Each recognized element—a word, line, or block—is wrapped in a <span> or <div> tag with a class attribute like ocrx_word. The element's bounding box is stored in a title attribute as bbox x0 y0 x1 y1, while the OCR engine's confidence in that recognition is recorded as x_wconf. This structured approach allows downstream legal document parsers to reconstruct complex page layouts and correlate extracted text with its original visual position.
Key Features of hOCR
hOCR is an open standard for encoding OCR output in HTML-like markup, embedding recognized text, layout coordinates, and confidence scores directly into a structured, machine-readable format.
Embedded Layout Geometry
hOCR encodes precise spatial information for every recognized element using the bbox property within the title attribute of span tags. This captures the x0 y0 x1 y1 coordinates of each word's bounding box, allowing downstream applications to reconstruct the original page layout without referencing the source image. This is critical for zonal OCR and optical layout analysis tasks where the physical position of a clause on a page carries legal significance.
Per-Word Confidence Scores
A defining feature of hOCR is the x_wconf attribute, which exposes the OCR engine's confidence level for each recognized word as a percentage (0-100). This granular data enables:
- Flagging uncertain text for human review in high-stakes legal workflows
- Selective reprocessing of low-confidence regions with alternative OCR engines
- Weighted downstream analysis, where predictions from token classification for boundaries or named entity recognition can be calibrated based on input quality
HTML-Based Semantic Structure
hOCR leverages standard HTML elements to represent document hierarchy. div tags denote pages, p tags represent paragraphs, and span tags encapsulate individual lines and words. This design allows any standard Document Object Model (DOM) parser to navigate the output, eliminating the need for proprietary parsing libraries. The class attribute carries semantic meaning, with values like ocr_page, ocr_par, ocr_line, and ocrx_word defining the structural role of each element.
Integration with OCR Engine Ecosystems
hOCR is the native output format for Tesseract OCR, one of the most widely deployed open-source recognition engines, ensuring broad compatibility. The format serves as a common interchange layer between the recognition phase and structural analysis tools like LayoutLM, which can consume the text and bounding box data jointly. This interoperability makes hOCR a foundational component in pipelines performing PDF structural extraction and header hierarchy extraction.
Capabilities and Limitations
While hOCR excels at encoding text content and spatial layout, it has defined boundaries:
- Capabilities: Captures word coordinates, confidence scores, font attributes, and basic reading order
- Limitations: Does not natively represent complex semantic structures like tables, footnotes, or cross-references. For full logical structure, hOCR is often paired with complementary standards like ALTO XML or used as an intermediate step before transformation into Legal XML Schema formats.
Role in Legal Document Pipelines
In legal AI, hOCR acts as the critical bridge between scanned document images and machine-readable text. The format's ability to preserve exact spatial coordinates is essential for:
- Bates number extraction from fixed stamp locations
- Zonal OCR targeting specific regions like signature blocks
- Reading order detection in multi-column pleadings
- Providing the layout features required by multimodal models for section boundary detection
Frequently Asked Questions
Clear, technical answers to the most common questions about the hOCR open standard for representing OCR output, its structure, and its application in legal document parsing pipelines.
The hOCR format is an open standard for representing the output of optical character recognition (OCR) engines using HTML-like markup. It works by embedding recognized text, layout properties, and confidence metrics directly into the class names and title attributes of standard HTML elements like <span> and <div>. Each recognized word, line, and block is wrapped in a tag whose title attribute carries structured key-value pairs—such as bbox for bounding box coordinates and x_wconf for word confidence scores. This design allows the OCR result to be viewed as a formatted page in any browser while remaining machine-parseable for downstream document analysis pipelines, making it a critical bridge between raw pixel data and structured legal text extraction.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
HOCR sits within a broader ecosystem of standards and techniques for representing and extracting document structure. These related terms are essential for building complete legal document parsing pipelines.
ALTO XML
An open XML Schema maintained by the Library of Congress that describes layout and OCR information for text blocks, illustrations, and page elements. Unlike HOCR's HTML-based approach, ALTO uses a dedicated XML vocabulary with explicit measurement coordinates and block-level confidence scores. It is widely used in large-scale digitization projects and often serves as the interchange format between OCR engines and downstream text correction tools.
Optical Layout Analysis
The computational process of segmenting a document image into regions of interest before text recognition occurs. This step identifies text columns, images, tables, and marginalia. HOCR encodes the output of this analysis as bounding boxes with class attributes (e.g., ocr_par, ocr_carea), making the spatial relationships between elements machine-readable and enabling downstream structural reasoning.
Reading Order Detection
The algorithmic determination of the logical sequence in which text blocks should be read in complex layouts. HOCR supports this through the reading_order property on carea elements. This is critical for multi-column legal documents where a naive top-to-bottom, left-to-right extraction would scramble the intended narrative flow of a contract or judicial opinion.
PDF Structural Extraction
The process of reconstructing logical document structure from the unstructured stream of drawing commands in a PDF. HOCR is often the intermediate representation generated after rendering PDF pages to images and applying OCR. The resulting HOCR markup can then be parsed to rebuild paragraphs, headings, and lists that were lost in the PDF's raw instruction stream.
Zonal OCR
A technique where optical character recognition is applied only to user-defined regions of a document, ignoring irrelevant areas like headers, footers, or marginalia. HOCR's coordinate system enables precise zonal targeting by allowing post-processing scripts to filter recognized text based on its bounding box position, effectively implementing zonal extraction after full-page recognition.
BIO Tagging Scheme
A token-level annotation standard where tokens are tagged as the Beginning, Inside, or Outside of a named entity. When building machine learning models for legal structure parsing, HOCR output is often tokenized and converted to BIO format to train sequence labeling models that identify clause boundaries, party names, and statutory references within the recognized text stream.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us