Frontend Guide · Complex Tables · 9 min read

How to Handle Merged Cells and Responsive Layout After Converting an Image to HTML Table

Merged cells are where a table that looks correct can become structurally wrong. Review spans as part of the data grid first, then solve mobile presentation with CSS without changing the meaning of the table.

Simple tables are relatively easy to reconstruct: one visible cell becomes one HTML cell. Complex tables introduce grouped headings, cells that span several columns, row labels covering several records, blank separators, subtotals and notes. LoveOCR’s Image to HTML Table tool can detect table grids and generate semantic markup, including complex structures, but merged cells deserve a deliberate review because one incorrect span can offset the rest of the row.

The safest approach is to separate two concerns. First, make the underlying HTML grid logically correct. Second, make that correct table usable on different screen sizes. Do not solve a structural problem with CSS positioning or solve a mobile problem by deleting meaningful columns.

Understand what rowspan and colspan actually change

colspan="3" means one cell occupies three column positions in the logical grid. rowspan="2" means a cell continues into the next row’s position. The following rows therefore contain fewer explicit cell elements because part of their grid is already occupied.

This is why a visually small OCR mistake can cascade. If a header should span two columns but is generated with three, every later cell can appear under the wrong heading even if the browser still renders a neat rectangle.

Draw a logical grid when the table is complicated

For a difficult header, temporarily number the final leaf columns: 1, 2, 3, 4 and so on. Then map every spanning header to the range it should cover. A group “Revenue” might cover columns 2–4 while “Costs” covers 5–6. This makes colspan review mechanical rather than visual guesswork.

Do the same vertically for row spans. If a category label applies to three item rows, confirm it occupies exactly those three logical row positions and that later labels begin at the correct row.

Grouped headers need accessible associations

Simple scope="col" headers work well for straightforward tables. Multi-level headers can require more careful markup so users of assistive technology can understand both the group and leaf header associated with a data cell. Depending on complexity, explicit header IDs and headers references may be appropriate.

If the original table is so visually complicated that relationships are difficult even for sighted users, consider simplifying it into multiple smaller tables with clear headings. Fidelity to a confusing source is not always better usability.

Do not use empty cells to imitate visual spacing

Scanned tables sometimes include blank rows or columns for visual breathing room. In HTML, layout spacing belongs in CSS. An empty cell should exist only if it represents a real position in the data grid. Extra cells inserted for appearance can break header associations and field counts.

Validate every row against the final column count

For each row, add the widths contributed by ordinary cells and colspans while accounting for active rowspans from earlier rows. The total should equal the table’s logical column count. This calculation catches many subtle span errors that a browser’s forgiving rendering can hide.

Automated tests can parse the DOM and verify grid width, but manual comparison with the source is still needed to confirm the chosen spans represent the intended grouping.

Use horizontal scrolling as the safe mobile baseline

Many data tables simply cannot fit on a narrow phone screen without losing information. Wrapping the table in a container with horizontal overflow is often the most honest responsive behavior. Users retain all columns, header relationships remain intact, and font size stays readable.

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-scroll table {
  min-width: 720px;
  border-collapse: collapse;
}

The exact minimum width should reflect your content. Avoid setting a large fixed width without testing common devices.

Sticky headers can help, but test them

For long tables, sticky column or row headers can improve orientation. They also introduce layering, clipping and overflow interactions. Test keyboard focus, zoom and small screens. Do not let sticky cells cover the data a user is trying to read.

Be cautious with “card” transformations

A popular mobile pattern converts each row into a card and repeats column labels beside every value. This can be useful for simple records, but it changes table semantics and may duplicate header text in the accessibility tree if implemented carelessly. If you use it, test screen-reader output and ensure the desktop table and mobile representation do not expose confusing duplicate content.

Keep units and context attached to headers

A source table may place “USD thousands” or “%” in a merged header above several columns. If the conversion loses that group label, values remain numerically recognizable but semantically incomplete. Preserve units as part of the relevant header structure or nearby explanatory text.

Test zoom, not only viewport width

Responsive testing should include browser zoom and larger text settings. A layout that works at 375 CSS pixels can fail when users enlarge text. Allow cells to wrap where appropriate and avoid fixed heights that clip multi-line content.

Use a complex-table verification routine

  1. Count leaf columns. Establish the logical grid width.
  2. Map each colspan. Confirm grouped headers cover the intended leaf columns.
  3. Map each rowspan. Track occupied positions across later rows.
  4. Verify header associations. Test with assistive technology for complex structures.
  5. Remove layout-only blanks. Use CSS spacing instead.
  6. Add a mobile overflow strategy. Preserve information rather than hiding it.
  7. Test zoom and keyboard navigation. Complex tables must remain operable beyond a desktop screenshot.

Prefer simpler markup when the source allows it

Not every visual merge needs to survive. Decorative title cells can sometimes become a heading or caption outside the table. Repeated group labels can sometimes be normalized into a clearer column. Preserve data relationships and meaning first; preserve ornamental geometry only when it helps users understand the information.

Privacy and responsible handling

LoveOCR states that uploaded and generated files are transferred securely and automatically removed from its servers within three hours. That reduces temporary server retention, but it does not replace your own data-handling responsibilities. Only process material you are authorized to use, avoid exposing secrets or personal information unnecessarily, and store downloaded results according to the rules that apply to your project or organization.

For code, database definitions, structured data, and machine-readable exports, treat generated output as a starting point that still needs human review. A file can be syntactically valid while being semantically wrong. Compare important names, identifiers, numbers, relationships, URLs, and business facts with the source before you execute, publish, import, or automate anything.

Related LoveOCR resources

Frequently asked questions

What does colspan change?

It makes one cell occupy multiple logical column positions, so later rows and headers must be reviewed against the same grid.

Is horizontal scrolling bad for mobile tables?

Not necessarily. For wide data tables it is often safer than shrinking text or hiding columns, provided the scroll area is usable.

Can I replace a table with cards on mobile?

You can for suitable data, but test semantics and screen-reader behavior because the transformation may duplicate or lose header relationships.

How do I check a complex rowspan?

Track which logical row positions the spanning cell occupies and make sure following rows do not insert another cell into those positions.

Should decorative merged title cells remain inside the table?

Not always. A heading or caption outside the grid can be semantically clearer when the cell does not label actual data columns.

Editorial note: This guide is based on the documented behavior of LoveOCR’s Image to HTML Table tool and focuses on validation, limitations, and practical downstream use instead of promising perfect output.

Updated: August 29, 2026 · Published by LoveOCR.

Convert complex tables into reviewable HTML

Generate the first table structure, then verify spans against the logical grid and add responsive CSS without changing the data relationships.

Open Image to HTML Table →