Last Updated: 30 Nov, 2026

hOCR vs. ALTO XML: Which OCR Format Is Better for Digital Libraries?

Digitizing physical collections—whether 19th-century newspapers, rare monographs, or municipal archives—requires far more than running an Optical Character Recognition (OCR) engine and dumping the output into a plain text file. When plain text strips away bounding boxes, column hierarchy, font styles, and confidence scores, downstream search interfaces cannot highlight hit terms on page images, and long-term preservation repositories lose critical structural context.

To preserve both text and spatial layout, digital library architects typically choose between two dominant open standards: hOCR and ALTO XML. While both formats encode recognized text alongside geometric coordinates, they were built with fundamentally different philosophies, governance models, and repository ecosystems in mind.

Understanding hOCR: The Web-Native Microformat

Created by Thomas Breuel in 2007, hOCR takes a pragmatic, web-first approach to OCR serialization. Rather than inventing a custom XML vocabulary from scratch, hOCR embeds layout, bounding box, and recognition confidence metadata directly inside valid HTML or XHTML documents using standardized class and title attributes.

How hOCR Structures Data

An hOCR file is immediately renderable in any web browser. Structural hierarchy is expressed through standard HTML elements paired with semantic class names:

  • ocr_page: Represents the scanned page image and its pixel dimensions.
  • ocr_carea: Defines a content area or column block.
  • ocr_par: Represents a logical paragraph.
  • ocr_line: Captures a single line of text along with baseline geometry.
  • ocrx_word: Wraps an individual token, storing bounding boxes (bbox) and engine confidence (x_wconf) inside the title attribute.
<!DOCTYPE html>
<html xmlns="[http://www.w3.org/1999/xhtml](http://www.w3.org/1999/xhtml)" xml:lang="en" lang="en">
<head>
  <title>Digitized Page 001</title>
  <meta name="ocr-system" content="tesseract 5.4.1" />
  <meta name="ocr-capabilities" content="ocr_page ocr_carea ocr_par ocr_line ocrx_word" />
</head>
<body>
  <div class="ocr_page" id="page_1" title="image 'scan_001.tif'; bbox 0 0 2480 3508; ppageno 0">
    <div class="ocr_carea" id="block_1_1" title="bbox 210 340 2250 520">
      <p class="ocr_par" id="par_1_1" title="bbox 210 340 2250 520">
        <span class="ocr_line" id="line_1_1" title="bbox 215 345 1420 410; baseline -0.002 -12">
          <span class="ocrx_word" id="word_1_1" title="bbox 215 345 480 410; x_wconf 96">Archive</span>
          <span class="ocrx_word" id="word_1_2" title="bbox 505 348 890 408; x_wconf 94">Collection</span>
        </span>
      </p>
    </div>
  </div>
</body>
</html>

Strengths of hOCR

  • Zero-Friction Web Tooling: Developers can parse hOCR using standard HTML parsers (BeautifulSoup, lxml, browser DOM APIs) and style or inspect layouts directly with CSS.
  • Fast PDF Layer Generation: Open-source utilities like OCRmyPDF use hOCR natively to sandwich invisible, searchable text layers onto scanned TIFF or PDF images with minimal transformation overhead.
  • Lightweight Footprint: Without verbose nested XML tags for every whitespace or font attribute, hOCR files are compact and fast to generate in high-throughput batch pipelines.

Understanding ALTO XML: The Archival Preservation Standard

ALTO (Analyzed Layout and Text Object) is an open XML schema maintained by the Library of Congress. Originally developed during the European Union’s METAe project, ALTO was engineered specifically for cultural heritage institutions, national libraries, and large-scale preservation repositories.

How ALTO XML Structures Data

Unlike hOCR, which overloads HTML attributes, ALTO enforces strict, strongly typed XML Schema Definitions (XSD). An ALTO file divides each document into three core sections:

  1. <Description>: Captures measurement units (pixel, mm10, or inch1200), source image identifiers, and OCR processing history.
  2. <Styles>: Centralizes font definitions (FONTFAMILY, FONTSIZE, FONTSTYLE) and paragraph alignments so individual words do not repeat styling metadata.
  3. <Layout>: Maps physical page regions (TopMargin, LeftMargin, RightMargin, BottomMargin, and PrintSpace) down to TextBlock, TextLine, String, and explicit SP (whitespace) elements.
<?xml version="1.0" encoding="UTF-8"?>
<alto xmlns="[http://www.loc.gov/standards/alto/ns-v4#](http://www.loc.gov/standards/alto/ns-v4#)"
      xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)"
      xsi:schemaLocation="[http://www.loc.gov/standards/alto/ns-v4#](http://www.loc.gov/standards/alto/ns-v4#) [http://www.loc.gov/standards/alto/v4/alto-4-4.xsd](http://www.loc.gov/standards/alto/v4/alto-4-4.xsd)">
  <Description>
    <MeasurementUnit>pixel</MeasurementUnit>
    <sourceImageInformation>
      <fileName>scan_001.tif</fileName>
    </sourceImageInformation>
  </Description>
  <Styles>
    <TextStyle FONTFAMILY="Times New Roman" FONTSIZE="14" FONTSTYLE="bold" ID="STYLE_1"/>
  </Styles>
  <Layout>
    <Page HEIGHT="3508" ID="PAGE_1" PHYSICAL_IMG_NR="1" WIDTH="2480">
      <PrintSpace HEIGHT="2900" HPOS="200" VPOS="300" WIDTH="2080">
        <TextBlock HEIGHT="180" HPOS="210" ID="TB_1" VPOS="340" WIDTH="2040">
          <TextLine HEIGHT="65" HPOS="215" ID="TL_1" VPOS="345" WIDTH="1205">
            <String CONTENT="Archive" HEIGHT="65" HPOS="215" ID="ST_1" STYLEREFS="STYLE_1" VPOS="345" WC="0.96" WIDTH="265"/>
            <SP HPOS="480" VPOS="345" WIDTH="25"/>
            <String CONTENT="Collection" HEIGHT="60" HPOS="505" ID="ST_2" STYLEREFS="STYLE_1" VPOS="348" WC="0.94" WIDTH="385"/>
          </TextLine>
        </TextBlock>
      </PrintSpace>
    </Page>
  </Layout>
</alto>

Strengths of ALTO XML

  • METS & Repository Interoperability: ALTO is designed to sit inside a METS (Metadata Encoding and Transmission Standard) wrapper, linking structural page maps, descriptive MARC/Dublin Core records, and preservation metadata (PREMIS) into a single archival Submission Information Package (SIP).
  • Rich Typographic and Margin Modeling: ALTO explicitly separates running headers, footers, marginalia, illustrations (Illustration), and graphical dividers (GraphicalElement) from main body text.
  • Modern Polygonal & HTR Support: Starting with ALTO v4, the schema added native support for polygonal bounding shapes and baseline polylines, making it compatible with Handwritten Text Recognition (HTR) tools like Transkribus and eScriptorium.

Side-by-Side Comparison: hOCR vs. ALTO XML

Feature / CriterionhOCRALTO XML
Underlying SyntaxHTML / XHTML with microformats (class, title)Strongly typed XML governed by XSD schemas
Maintaining BodyCommunity-maintained open specification (kba/hocr-spec)Library of Congress (ALTO Editorial Board)
Schema ValidationLoose; relies on HTML validators and custom attribute lintersStrict XSD validation guarantees structural consistency
Metadata & Coordinate StorageSemicolon-delimited key-value strings inside title attributesExplicit typed XML attributes (HPOS, VPOS, WIDTH, HEIGHT, WC)
Typography & Font ModelingMinimal; rarely standardized across OCR enginesDedicated <Styles> block with TextStyle and ParagraphStyle references
Page Zone GranularityBasic blocks, paragraphs, lines, and wordsExplicit margins (TopMargin, BottomMargin), PrintSpace, tables, and illustrations
METS / PREMIS IntegrationRequires custom wrapping or conversionNative companion standard for METS/PREMIS archival packages
OCR Engine SupportTesseract, OCRopus, Calamari, KrakenTesseract (v4.1+), ABBYY FineReader, Transkribus, eScriptorium
File VerbosityCompact and lightweightVerbose due to explicit <SP> tags and attribute schemas

Key Architectural Differences That Impact Digital Libraries

1. Schema Validation vs. String Parsing

In ALTO XML, every coordinate, confidence score, and style reference is an explicit XML attribute validated against an official XSD schema. If an OCR pipeline emits a malformed coordinate or an invalid reference ID, automated ingest validation catches it immediately before corrupting the repository.

In hOCR, critical geometric data is packed into unstructured text strings inside the HTML title attribute (for example, title="bbox 215 345 480 410; x_wconf 96"). Consumers must write secondary string-splitting parsers to extract coordinates and confidence values, and standard HTML5 validators will not flag typos inside title strings.

2. Newspaper and Complex Layout Segmentation

Historical newspapers and multi-column periodicals pose severe challenges for search and discovery platforms. If an OCR engine merges running headers, page numbers, advertisements, and article columns into a single reading stream, full-text search relevance degrades rapidly.

ALTO XML solves this structurally by separating page geometry into distinct zones (TopMargin, PrintSpace, ComposedBlock, Illustration) and encoding explicit reading order attributes (IDNEXT). While hOCR supports ocr_carea and ocr_header classes, implementations vary significantly between OCR engines.

3. Discovery Layers and IIIF Integration

Modern digital libraries rely heavily on the International Image Interoperability Framework (IIIF) and viewers like Mirador or Universal Viewer to display high-resolution scans with hit-highlighting overlays.

  • ALTO XML integrates out of the box with major repository platforms—including Islandora, Samvera/Hyrax, DSpace, Kitodo, and Goobi—as well as IIIF Content Search servers (such as iiif-content-search and Solr-based OCR plugins like solr-ocrhighlighting).
  • hOCR works seamlessly with lightweight web viewers and solr-ocrhighlighting as well, especially when teams build custom Python or Node.js front ends without a full METS/ALTO repository stack.

4. Storage Overhead and Processing Speed

Because ALTO XML records explicit <SP> elements for every space between words alongside detailed coordinate attributes, an ALTO file is typically 30% to 60% larger than an equivalent hOCR file for the same page. For collections spanning tens of millions of pages, that difference impacts storage budgets and XML indexing throughput—though gzip compression reduces the disk footprint substantially.

Practical Workflow: Converting Between hOCR and ALTO XML

Digital libraries are rarely locked into a single format permanently. Because both formats represent hierarchical bounding boxes and text tokens, you can convert between them using established open-source tools:

  1. Direct Export from Tesseract: Modern Tesseract releases natively output both formats from a single recognition pass without extra conversion steps:
tesseract page_001.tif output_base -l eng hocr alto
  1. XSLT Transformations (hOCR-to-ALTO): Standardized XSLT 2.0 stylesheets (maintained in the open-source filak/hOCR-to-ALTO repository) convert legacy Tesseract hOCR archives into valid ALTO v2.0, v2.1, v3, or v4 XML using Saxon-HE.
  2. Python Libraries (ocr-fileformat): For automated ingestion pipelines, command-line wrappers like ocr-fileformat normalize conversions across hOCR, ALTO XML, and PAGE XML.

Which OCR Format Should Your Digital Library Choose?

Choosing between hOCR and ALTO XML comes down to whether your priority is long-term archival stewardship or agile web-centric processing:

  • Choose ALTO XML if:

    • You manage a university, museum, or national library repository built on METS, PREMIS, Islandora, Samvera, Kitodo, or Goobi.
    • Your collections include complex multi-column newspapers, periodicals, or historical books requiring strict separation of headers, footers, illustrations, and body text.
    • Your funding grants or institutional preservation policies mandate adherence to Library of Congress archival standards with strict XSD schema validation.
  • Choose hOCR if:

    • Your primary goal is generating searchable PDF/A derivatives via OCRmyPDF or powering lightweight web search overlays.
    • You are building a custom, developer-led digitization pipeline in Python or JavaScript where standard HTML DOM tooling accelerates development.
    • You want compact intermediate OCR files during rapid prototyping before archiving final derivatives.

For most institutional digital libraries tasked with preserving cultural heritage over decades, ALTO XML (v4.x) remains the stronger long-term standard—while hOCR serves as an ideal lightweight companion for fast web delivery and PDF generation.

Frequently Asked Questions (FAQ)

Q1. Can Tesseract OCR generate both hOCR and ALTO XML files at the same time? Yes, Tesseract allows you to pass both hocr and alto config arguments in a single command to output both files simultaneously from one OCR pass.

Q2. Which OCR format works better with METS and PREMIS archival packages? ALTO XML is specifically designed as a companion standard to METS and PREMIS for structured digital preservation workflows.

Q3. Is hOCR or ALTO XML better for creating searchable PDFs? hOCR is generally faster and more widely supported as a native intermediate format in open-source tools like OCRmyPDF for embedding hidden text layers.

Q4. Can you convert existing hOCR files into valid ALTO XML without re-running OCR? Yes, you can use open-source XSLT stylesheets (such as hOCR-to-ALTO) or Python tools like ocr-fileformat to transform hOCR into schema-valid ALTO XML.

Q5. Does ALTO XML support handwritten text recognition (HTR) baselines? Yes, starting with ALTO version 4, the schema supports polygonal coordinates and baseline polylines suitable for HTR engines like Transkribus and eScriptorium.

See Also