How to Compare Two Code Files Online and Spot Every Change
Paste two versions of code and see added, removed and unchanged lines with line numbers. When to ignore whitespace, how to read the result, and limits.
The short answer
Paste the old version into Original Text and the new version into Changed Text in the Text Diff Checker. It lines the two versions up, marks added lines with + in green and removed lines with − in red and struck through, and shows both line numbers for each row. Tick Ignore whitespace when the only difference you do not care about is indentation, for example after wrapping code in an if block.
When a quick online diff is useful
- Checking what a colleague changed in a snippet they pasted into chat.
- Comparing a config file from production with the one in your repository.
- Seeing what an AI assistant or a formatter changed in your function.
- Reviewing two versions of an SQL query or a JSON payload.
If both files are already in a Git repository, git diff is the natural tool. The online checker is for everything else: code in emails, tickets, chat messages and two browser tabs.
How to compare two versions
The comparison runs in your browser, so pasted code is not sent to a server.
Reading the result: an example
Original:
def total(items):result = 0for item in items:result += item.pricereturn result
Changed:
def total(items, tax=0):result = 0for item in items:if item.active:result += item.pricereturn result * (1 + tax)
With default settings, the tool reports 4 added, 3 removed, 22% similar. The function signature and the return line show as removed and re-added, which is correct. But result += item.price also shows as removed and added, even though only its indentation changed when it moved inside the new if.
Tick Ignore whitespace and the result becomes 3 added, 2 removed, 38% similar. Now the indented line counts as unchanged, and the real edits stand out: a new parameter, a new condition and a new return expression.
What "changed" means here
The tool compares whole lines. A line where one character changed appears twice: once as removed (the old version) and once as added (the new version). It does not highlight the individual characters within a line, so when a removed and an added line sit next to each other, compare them by eye to find the exact edit.
How lines are matched
The checker finds the longest sequence of lines common to both versions, keeping their order, and treats everything else as added or removed. This means inserting a few lines near the top does not make every later line look different; the unchanged lines below still line up.
When to use the options
Ignore whitespace
With this ticked, leading and trailing spaces are ignored and runs of spaces or tabs inside a line count as a single space. Use it when:
- code was re-indented (tabs to spaces, 2 spaces to 4),
- a block was wrapped in a new
if,tryor loop, - a formatter changed alignment.
Do not use it for whitespace-sensitive files where indentation is meaning, such as YAML or Python, if you are specifically checking that indentation is right.
Ignore case
Useful for SQL keywords (select versus SELECT) or HTML tag names. Leave it off for most programming languages, where userId and userid are different names.
The similarity percentage
The badge is the share of rows in the result that are unchanged. It is a rough guide to how much changed, not a quality score. A small edit to a very short snippet can produce a low percentage simply because there are few lines.
Limits to know about
- Line-based only. There is no character-level highlighting inside a line.
- One combined view. Results appear in a single table with both line numbers, not as two separate columns.
- Very long files can be slow. The matching step compares every line of one version with every line of the other, so the work grows quickly with size. For files of many thousands of lines, use a desktop diff tool or
git diff --no-index old.txt new.txt, which compares two files even outside a repository. - Moved blocks. A block moved from the top of a file to the bottom shows as removed in one place and added in another.
A quick review routine
Before you accept someone else's change or paste a new version over an old one:
Tips for cleaner comparisons
- Format both versions the same way first. If one JSON payload is minified and the other is pretty-printed, every line differs. Run both through the JSON Formatter before comparing.
- Compare like with like. Make sure line endings and encoding come from the same kind of source; pasting from a PDF or a rich-text editor can add invisible characters.
- Trim what you do not need. Paste only the function or section in question, and the result is easier to read.
Comparing plain lists rather than code? See How to Compare Two Lists and Find Missing or Extra Items. For prose such as contracts or essays, How to Compare Two Texts and Find the Differences covers what to look for.
Frequently asked questions
How do I compare two code files online?
Paste the old version in Original Text and the new version in Changed Text. Added lines are marked + in green and removed lines − in red, with line numbers for both versions.
How do I ignore indentation changes when comparing code?
Tick Ignore whitespace. Leading and trailing spaces are ignored and runs of spaces or tabs count as one, so re-indented lines show as unchanged.
Does the tool highlight the changed characters inside a line?
No. It compares whole lines, so an edited line appears once as removed and once as added. Compare the two rows by eye to find the exact change.
Is my code uploaded when I compare it?
No. The comparison runs in your browser and the pasted text is not sent to a server.
Put this guide into practice with our free online tool — no signup required.
Open tool