# Why malformed table markup moves text outside the table

Canonical: https://githtml.com/guides/invalid-table-markup-moves-content
Published: 2026-11-23
Publisher: WaveTech LLC / gitHtml

When text unexpectedly appears before or outside a table, inspect the table's HTML structure before adjusting CSS. Browsers repair malformed markup, and content placed where rows or cells are expected can be relocated in the parsed document. Compare the parsed DOM with the source and fix the structure rather than positioning the displaced text visually.

## Identify the specific failure

A paragraph inserted directly inside a table can be handled differently from a paragraph inside a cell. The browser's recovery rules make the page render, but not necessarily in the order the author imagined. Visual patching can preserve the underlying error.

## Make a narrow correction

Place explanatory prose before or after the table, or inside an appropriate cell when it belongs to that cell. Check row groups, rows, and cells for mismatched tags. Keep captions as captions rather than arbitrary text between rows.

1. Compare the source with the browser's parsed table structure.
2. Move explanatory prose to a valid location and repair row and cell nesting.
3. Recheck captions, headers, and reading order after structural corrections.

````html
<p>Explanation before the table.</p>
<table><caption>Observed values</caption><tbody><tr><th scope="row">Count</th><td>12</td></tr></tbody></table>
````

## Repair structure before compensating for the browser's recovery

Consider a table whose source places a paragraph directly between the opening table tag and its first row. The author expects the paragraph to appear as a table introduction. The HTML parser can move unexpected table content outside the table as part of its recovery behavior, so the inspected DOM no longer matches the source's apparent nesting. Move the introduction before the table, use a caption if it names the table, or place information inside an actual cell when it belongs to that row. Do not use margins or absolute positioning to push the recovered paragraph back into the desired visual location.

Inspect a small failing excerpt rather than the entire report at once. Include the table's opening tag, caption if present, row-group boundaries, and the rows around the displaced text. Check that cell content is inside th or td and that explanatory prose has a valid home. The browser may insert structural elements as part of parsing, so compare actual parent-child relationships rather than treating every difference between source and DOM as an error. The actionable problem is malformed or misplaced content that changes meaning, order, or associations.

After the structural correction, verify the data relationships independently of appearance. A misplaced closing tag can shift a value into the wrong row or leave a header associated with the wrong group. Compare one ordinary row and one row with spans or long explanatory content against the source data. Check the caption and introductory paragraph in reading order, then navigate the table nonvisually if that workflow is in scope. A visually aligned grid is not enough: each value must still have the intended row, column, unit, and scope after the parser no longer needs to repair the malformed structure.

## Verify the repaired artifact

After correcting markup, inspect both visual order and nonvisual table navigation. A neat appearance alone does not establish valid relationships.

## Sources and further reading

- [MDN: table](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/table)

## Related guides

- [Find images that were never loaded before saving](https://githtml.com/guides/lazy-images-missing-saved-report)
- [Why module scripts behave differently in file-based HTML](https://githtml.com/guides/module-script-local-html-fails)
- [Stop object-fit from cropping important screenshot labels](https://githtml.com/guides/object-fit-crops-screenshot-labels)
- [Find the overlay hiding an HTML report](https://githtml.com/guides/overlay-z-index-reading-document)

Editorial approach: https://githtml.com/guides/about
