Find HTML parse errors in their source context
Admin ·
A CMS fragment can look fine in a browser even when the browser had to recover from invalid source. Use line and column numbers to find each reported problem in the original code.
Find two issues on the same source line
Open HTML Validator, choose Load example and select Validate HTML. The report has two findings on line 2. The paragraph repeats the class attribute and uses a named character reference called route, which the parser does not recognize.
Keep class="intro" and remove class="fallback". If the text is meant to say Maps &route; with a literal ampersand, write Maps &route; in the source. Validate again. The local parse checks should now report no issues.
| Example position | Diagnostic code | Edit |
|---|---|---|
| Line 2, column 25 | duplicate-attribute | Keep one class attribute. |
| Line 2, column 48 | unknown-named-character-reference | Use & for the literal ampersand. |
Validate a row in its table context
Paste <tr><td>East</td></tr> with body selected. The checker flags the table elements the parser did not keep in that context. Change Fragment context to table and run the check again. The table context can accept the row and supply the table section during parsing.
Select HTML document when you have the whole page source. A complete HTML document needs a doctype. The fragment example contains none because it is meant to go inside another document.
WHATWG HTML, fragment parsing algorithmWHATWG HTML, parsing errors
Keep a report from the corrected source
Download JSON to keep the selected scope, parser findings and source positions. Fix the earliest findings first when several are close together, then rerun the check on the edited HTML.
The example includes optional li end tags. The HTML standard permits leaving them out in this case. The report covers local parsing and selected ignored tags. Accessibility and full element and attribute conformance require additional checks.
Common questions
What if I have only table cells?
Choose the tr fragment context to parse td or th elements as the children of a row.
Will the findings tell me whether an image is reachable?
The checker inspects the supplied source locally. Checking the response from an image address requires a separate request to its host.
Sources
Put it into practice.
Related guides
- How to Convert an HTML Fragment to JSX
- How to Keep Lists When Extracting HTML Text
- How to Format HTML Code for Readability
- Resolve Two Links to the Same Journal Map
- Trace Markup Accessibility Issues to Source
- Check How the HTML Parser Repairs Broken Tags
- Measure Inline Content in Saved HTML
- Generate Srcset and Check Candidate Widths