Inferensys

Glossary

hOCR Format

An open standard for representing OCR output using HTML-like markup to encode the recognized text, its layout properties, and confidence scores for each recognized word.
Stylish WeWork-like workspace with hot desks and document wall, professional searching through enterprise knowledge base on a mounted ultrawide display, warm industrial pendants overhead.
OCR MARKUP STANDARD

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.

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.

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.

OCR MARKUP STANDARD

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.

01

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.

02

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
0-100
Confidence Range
03

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.

04

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.

05

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.
06

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
HOCR FORMAT

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.

Prasad Kumkar

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.