HTML validation guides

Find HTML parse errors in their source context

·

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.

HTML Validator

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.

Find two issues on the same source line
Example positionDiagnostic codeEdit
Line 2, column 25duplicate-attributeKeep one class attribute.
Line 2, column 48unknown-named-character-referenceUse & for the literal ampersand.

WHATWG HTML, parsing errorsWHATWG HTML, optional tags

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.

WHATWG HTML, optional tagsWHATWG HTML, parsing errors

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