HTML Comparison Rules
Understand fixed LCS child matching, attributes, meaningful whitespace, comments, doctypes, numeric text, and parse5 recovery limits.
HTML Data Compare uses one fixed set of rules: parse5 builds a virtual-node tree, significant children are aligned with LCS, and matched nodes are compared recursively. There are no HTML comparison settings to configure.
What Data Compare examines
The tree represents:
- Elements, including tag names, attributes, and nested children;
- Text, whose complete non-empty value remains significant;
- Comments, including their content;
- Doctypes, including the name, public identifier, and system identifier supplied by the parser.
Elements with different tags do not match as the same child. Attributes are compared by name and value independently from child matching. Numeric-looking text and attribute values stay strings: 1 and 1.0 are different values.
Data Compare is structural, but it is not a browser-rendering comparison. It does not execute scripts, apply CSS, fetch the page’s assets, or detect visual equivalence.
Fixed LCS child matching
At each parent, whitespace-only text nodes are removed from the matching input. Every remaining child receives a matching key from its node type; an element’s key also includes its tag name. A fixed Longest Common Subsequence (LCS) algorithm aligns equal keys while preserving order.
This is different from an LCS over complete node values. Two li elements can match even when their text differs, after which their contents are compared recursively. Nodes outside the matched sequence are reported as Deleted on Base or Added on Contrast.
There is no By Index, Unordered, ignore-case, or numeric-conversion option for HTML. There is also no special move operation.
Reordering elements with the same tag
Given this Base fragment:
<ul>
<li>Alpha</li>
<li>Beta</li>
</ul>
And this Contrast fragment:
<ul>
<li>Beta</li>
<li>Alpha</li>
</ul>
Both li elements have the same matching key. LCS can align the sequence by tag, so the comparison reports changed text at the two matched positions rather than recognizing a move. It does not infer that the two list items exchanged identities.
Reordering mixed node types
For mixed content, only nodes with compatible type/tag keys can belong to the same matched sequence:
<!-- Base -->
<div><p>Alpha</p><span>Beta</span></div>
<!-- Contrast -->
<div><span>Beta</span><p>Alpha</p></div>
One ordering can be retained as the common subsequence while the other node appears as deleted and added. A rearrangement is therefore not a single move difference. When several alignments are possible, do not assume the result expresses your intended component identity.
Inserting or editing children
An inserted node with no compatible unmatched counterpart is Added. An inserted li, however, can align with other li nodes because matching uses the tag rather than complete contents. Review both structural entries and nested value changes to understand the result.
Editing text, an attribute, or a comment under a matched node produces Value Changed. Replacing a node’s tag prevents that element from matching the old element at the same level.
Attributes and attribute order
Attributes are compared as name/value pairs. These elements are equal in Data Compare:
<button class="primary" type="submit">Pay</button>
<button
type="submit"
class="primary"
>Pay</button>
Changing class, adding disabled, removing type, or changing the element’s text still produces a difference. Attribute values are case-sensitive strings; there is no option to ignore case or convert numeric-looking values.
Whitespace: ignored nodes vs. meaningful text
A text node whose entire value is whitespace is excluded from child matching. Common indentation between elements therefore does not create differences:
<ul>
<li>Alpha</li>
</ul>
<ul><li>Alpha</li></ul>
Whitespace inside a non-empty text node is not generally trimmed, collapsed, or normalized. These paragraphs differ:
<p>Current session</p>
<p>Current session</p>
Leading or trailing whitespace in a node that also contains characters can matter as well. Do not assume that visually similar browser output means the parsed text values are identical. Use Git Diff to inspect exactly where the source whitespace changed.
Comments and doctypes are compared
Comments are not ignored. These fragments produce a comment value change:
<!-- deployed -->
<p>Ready</p>
<!-- proposed -->
<p>Ready</p>
Adding or removing a comment can produce an addition or deletion. Comments participate in the same fixed child matching as other node types.
Doctypes are also represented. Data Compare checks the parsed doctype name, public identifier, and system identifier. For example, changing a legacy public identifier can produce a value change even when the visible body is unchanged. parse5 may normalize source casing while constructing those fields; the comparison uses the parsed values rather than the raw spelling.
parse5 recovery is not standards validation
validateHTML rejects empty input and runs parse5, but it is not a standards-conformance validator. parse5 follows HTML parsing and error-recovery rules, so malformed markup can be accepted and repaired:
<div><span>Account</div>
The parser can construct a tree with an implied closing span instead of reporting mismatched tags as a validation error. Full-document parsing can also create implied elements such as html, head, or body.
Consequently, Same means equal parsed trees, not valid or identical source. Review reconstructed output when recovery is relevant, and use a dedicated conformance validator for standards checks. The comparison also does not establish script safety, accessibility, or rendering equivalence.
Reconstructed Data Compare vs. original-text Git Diff
Data Compare converts the parsed virtual nodes back into displayable HTML. This reconstruction is not an exact mapping to the entered source: line layout, indentation, attribute presentation, and parser-supplied structure can differ. Differences and paths refer to the parsed tree.
Git Diff instead compares the original Base and Contrast text line by line. It can reveal attribute layout, indentation, source casing, and other edits even when Data Compare reports Same. It does not replace structural review, and it has no configurable HTML semantic options.
Troubleshooting unexpected results
A comment change appears. This is expected: comments are compared. There is no ignore-comments setting.
1 and 1.0 differ. Numeric-looking text remains text. There is no numeric conversion option.
A reorder looks like edits or an add/delete pair. Fixed LCS preserves order and matches only node type/tag keys. It does not detect moves or unordered equivalence.
Indentation disappears but a doubled space remains. Whitespace-only nodes are ignored; meaningful non-empty text whitespace is not generally normalized.
Malformed markup still compares. parse5 recovers according to HTML parsing rules. validateHTML is not a standards validator, and the result view is reconstructed.
Start with the HTML Getting Started guide for a complete Base-to-Contrast example, URL loading, result navigation, sharing, and privacy guidance.