Text Compare
Operator: Abdulla Al Fahad. How tools are built and checked
Text Compare lines up two versions of the same text and marks what changed. Deleted words are struck through in red, inserted words are underlined in green, and a line where only one or two words moved shows just those words highlighted instead of the whole line. You can paste each version or load it from a .txt, .md or .html file, read the result side by side or as a single inline column, and save it as an HTML report.
It is built for prose as much as for code: a tenancy clause that went from "24 hours' notice" to "48 hours' written notice" comes back as one replaced number and one inserted word, with the rest of the sentence left plain, so you can see the edit without rereading the paragraph.
Key features
- Line-level comparison with word-level highlights inside edited lines
- Side-by-side view with line numbers for both versions
- Inline view that shows each deletion directly before the text that replaced it
- Counts of added words, removed words, changed, added, removed and unchanged lines
- Option to ignore letter case
- Option to ignore differences in spacing, indentation and blank lines
- Upload .txt, .md or .html, or paste text into either side
- Standalone HTML report with every piece of your text escaped
Each side accepts pasted text or one uploaded file of up to 5 MB. Plain text and Markdown files are compared as written, so Markdown syntax such as **bold**, # headings and link brackets is part of the comparison; a heading that changed from ## to ### shows up as a changed line. Files that start with a UTF-16 byte-order mark are decoded as UTF-16; every other file is read as UTF-8.
An HTML file is reduced to its visible text before comparing. The page parses the markup into a detached document, removes <script>, <style>, <noscript> and <template> elements, turns paragraphs, headings, list items, table rows and <br> tags into line breaks, separates table cells with a tab, and then reads the text of <body>. Attributes, link targets, image sources and CSS are not compared at all, so a changed href or class name produces no difference.
Each side can hold up to 500,000 characters. Above that the counter turns red and Compare stays disabled until the text is shorter. The downloadable report is a single .html file with its styles inline and no scripts; it opens in any browser and can be attached to an email or saved next to the documents it describes.
How it works
The comparison runs in two passes. First, both texts are split into lines and compared with the Myers difference algorithm, which finds the smallest set of whole-line insertions and deletions that turns the old text into the new one. Lines that match exactly are shown as unchanged.
Second, every run of deleted lines is matched against the run of inserted lines next to it. A deleted line is paired with the first inserted line, within the next 20, that shares at least 40% of its visible characters with it, and pairs never cross each other. Each pair is compared again word by word, where a word is a run of letters, digits, apostrophes or underscores, each punctuation mark is its own token, and each run of spaces is a token too. Lines that find no partner are shown as wholly deleted or wholly inserted.
The word counts in the summary count only tokens that contain a letter or a digit. Replacing a comma with a semicolon therefore marks the line as changed but adds nothing to the word totals, and "5%" counts as one word because the percent sign is punctuation.
Common use cases
- Checking what a co-author or editor changed in a returned essay draft when they did not use tracked changes.
- Reviewing a revised policy or contract clause from the other party before signing, to spot a number or a single word that changed.
- Comparing two exports of the same Markdown README to find which section a teammate rewrote.
- Seeing what changed between two saved copies of a web page, after saving each as HTML.
- Confirming that a translation agency returned the file you sent, with only the lines you asked for edited.
How to use this tool
- Paste the older version into Original text, or press Upload file above it and pick a .txt, .md or .html file.
- Put the newer version into Changed text the same way. You can also drop a file onto either side.
- Tick Ignore letter case or Ignore whitespace differences if those changes should not count.
- Press Compare and read the summary counts.
- Switch between Side by side and Inline to read the changes the way that suits the text.
- Press Download HTML report to keep a copy of the comparison.
Example
Two drafts of a tenancy clause
Original text
The tenant pays rent on the first day of each month.
Late payments incur a fee of 5% of the monthly rent.
The landlord may enter with 24 hours' notice.
Changed text
The tenant pays rent on the fifth day of each month.
The landlord may enter with 48 hours' written notice.
Pets are not permitted.Inline view ([-deleted-] and {+inserted+} stand in for the red and green marks)
1 1 The tenant pays rent on the [-first-]{+fifth+} day of each month.
2 [-Late payments incur a fee of 5% of the monthly rent.-]
3 2 The landlord may enter with [-24-]{+48+} hours' {+written+} notice.
3 {+Pets are not permitted.+}
Added words 7 | Removed words 13 | Changed lines 2
Added lines 1 | Removed lines 1 | Unchanged lines 0Tips for best results
- Put the older version on the left. The labels and colours assume left is the original, so swapping sides turns every deletion into an insertion.
- If the summary shows many changed lines but each highlight is only a space, turn on Ignore whitespace differences; indentation and double spaces after full stops stop counting.
- When comparing text copied from a PDF, paste both versions from the same viewer. Different viewers break lines in different places, and that alone makes every line look changed.
- Use the inline view for prose and the side-by-side view for lists, configuration files or anything where line numbers matter.
- The report file name is always text-comparison.html; rename it after downloading if you keep several.
Common pitfalls
The comparison is line first. If one version was rewrapped, for example a paragraph saved as one long line in one file and broken at 80 characters in the other, the lines no longer correspond and the result shows large deleted and inserted blocks even though the words are the same. Ignore whitespace does not fix this, because it works inside lines and on blank lines, not across line breaks. Join the paragraphs into single lines on both sides first.
There is no move detection. A paragraph cut from the top and pasted at the bottom appears as a deletion in one place and an insertion in another.
With Ignore whitespace differences on, blank lines are skipped entirely, so they disappear from the view and the line numbers jump over them. With Ignore letter case on, text that differs only in case is shown in the changed version's spelling.
When two texts share almost nothing, the search for the smallest difference is stopped after a fixed amount of work and the remaining block is shown as one deletion followed by one insertion. A yellow note appears above the result when that happens.
Common errors and how to fix them
- "is not a supported file" after uploading a Word document or PDF.
- Only .txt, .md, .markdown, .html and .htm files can be loaded. Open the document, copy its text and paste it into the box instead, or save it as plain text first.
- "looks like a binary file, not plain text".
- The first 8 KB of the file contains a zero byte, which plain text never has unless it is UTF-16 with a byte-order mark. The file is probably a renamed .docx, .pdf or image. Export it as text from the program that made it.
- Accented letters appear as � symbols.
- The file was saved in a legacy encoding such as Windows-1252, and the page reads files as UTF-8. Re-save it as UTF-8 in your editor, or open it and paste the text.
- Compare stays greyed out.
- Either both boxes are empty or one of them is above 500,000 characters. The counter under each box shows which.
Best practices
- Keep a copy of the HTML report with the two source files when the comparison is part of a review or approval, so the record shows what was compared and with which options; the options are printed at the top of the report.
- Compare clean text, not formatted output. A Markdown source or a plain-text export gives a clearer result than text copied from a rendered page with its menus and footers.
- For long documents, compare section by section. Smaller inputs give a result you can actually read, and a change cannot hide in a long unchanged stretch.
What the HTML report contains
The report repeats the side-by-side view as a table: line numbers for each version, unchanged lines in plain text, deleted lines on a red background with the text struck through, inserted lines on a green background with the text underlined, and edited lines with only the changed words marked. Above the table it lists the six counts, the two labels (the file names, or Original text and Changed text for pasted input), which options were on, and the time it was generated.
Every character that came from your text, including file names, is written as escaped HTML, so a pasted <script> tag or an ampersand appears in the report as literal text and never runs or changes the layout. Because the styles are inline and the file has no scripts, it looks the same offline and in an email attachment preview.
Frequently asked questions
Why is a whole line marked as deleted and another as inserted, instead of showing the changed words?
Word-level highlights are only used when the two lines share at least 40% of their visible characters. A line that was rewritten more heavily than that is shown as a deletion and an insertion, because marking every word in it would be harder to read than the two lines on their own.
Can it compare Word documents or PDFs?
Not directly. Copy the text out of each document and paste it into the two boxes. Formatting such as bold, fonts or comments is not compared in any case; only the characters are.
Does Ignore whitespace treat a missing space between two words as no change?
No. It treats a run of spaces or tabs as equal to a single space and ignores spaces at the start and end of a line, but "to day" and "today" are still different, because one has a space and the other has none.
Is the HTML in an uploaded .html file ever shown as a page?
No. The markup is parsed into a document that is never attached to the page, only the text of its body is read, and that text is displayed as text. Scripts in the file are removed before reading and never run.