ToolsHub4u

Compare two versions of code line by line

Paste the old version and the new one. The comparison marks added and removed lines, keeps the unchanged ones in place and reports how similar the two versions are.

  • Line-by-line diff
  • Similarity score
  • Nothing uploaded
Ready Developer & Utility
1Enter
2Adjust
3Copy result

Code Diff Checker

1

Two versions

Comparison options

Ignoring whitespace treats indentation changes as unchanged lines. It does not change the files themselves.

No data yet Live
2

Differences

4 lines added and 3 removed.

Similarity

36.4%

Line differences between version A and version B
ABChangeLine
1Removed: function greet(name) {
2Removed: return "Hello " + name;
1Added: function greet(name, punctuation) {
2Added: return "Hello " + name + punctuation;
33}
44
5Removed: console.log(greet("world"));
5Added: console.log(greet("world", "!"));
6Added: console.log("done");
  • Changed lines are highlightedAdditions come from version B; removals come from version A. Unchanged lines are shown for context.
  • Whitespace or case differences ignoredSome differences are treated as equal. Turn the options off to see the raw comparison.
Lines in A
5
Lines in B
6
Unchanged
2
Added
4
Removed
3
Similarity
36.4%

This is a line diff, not a word or character diff. A single character change marks the whole line as removed and added. The similarity score is based on the longest common subsequence, not on the percentage of characters that changed.

This page compares two blocks of code and marks what changed between them. Paste the old version on the left and the new one on the right, and it produces a line table with additions, removals and unchanged context, plus counts for each and a similarity score. Three comparison options control whether trailing whitespace, all whitespace or letter case count as differences.

The comparison is a line diff. It is built for reviewing a function, a config file or a patch-sized edit in the browser, not for walking a repository history. It never sends the code anywhere, and the two text areas are the only inputs.

How the line comparison works

The tool splits both versions at line endings and compares the resulting lines with a longest common subsequence algorithm. Lines that appear in both versions, in the same relative order, are kept as context. The lines between them are marked as removed from version A or added in version B. That is why the output stays readable when a block moves: the algorithm keeps the shared lines and surrounds them with the changed ones.

It is not a character-level diff. Change one character in a line and the whole line is removed and re-added. A word-level view would show the single change, but this page deliberately keeps the unit at the line so the table stays close to what a patch looks like.

All removals are printed before the matching additions in each changed block. The table numbers both sides independently, so a removed line can have an A number and no B number, and the reverse for an addition.

The three comparison options

Ignore trailing whitespace is on by default. It strips spaces and tabs at the end of each line before comparing, so an editor that added a trailing space does not create a false change. Ignore all whitespace removes every space and tab inside the line as well, which is useful when one version was re-indented. Ignore case lowercases both sides before comparison.

The options change what counts as equal, not what is displayed. The table still shows the original text from each version. Two versions that differ only in case produce a similarity of 100% with the case option on, while the same pair produces additions and removals with it off. Turn every option off when you need the raw comparison.

A worked example

Version A was a five-line function with one console.log call. Version B added a parameter, changed both lines that used it and added a second log call. The page reported 4 lines added, 3 removed, 2 unchanged and a similarity of 36.4%.

Summary of the example comparison
MeasureValue
Lines in A5
Lines in B6
Unchanged2
Added4
Removed3
Similarity36.4%

The score is not the percentage of characters that survived. It is twice the number of unchanged lines divided by the total number of lines in both versions: 2 × 2 ÷ 11, rounded to one decimal place. A short file with one changed line therefore scores lower than a long file with the same one-line change, because the shared context is a smaller share of the whole.

The same text with the case option on scored 100%, and with all whitespace ignored it also scored 100% for a pair that differed only in spacing. Neither result means the files are identical on disk; it means they are identical under the selected rules.

Similarity is a rough signalUse the counts and the table for review. The percentage is useful for a quick comparison between runs, not as a measure of code quality or risk.

Reading the table

Each row carries the A line number, the B line number, a change marker and the line itself. Removed lines show their A number, added lines show their B number, and unchanged lines show both. The marker column uses a minus for a removal and a plus for an addition. The copy button produces a unified-style list with those same prefixes, which is convenient for a commit message or a review note.

Long lines are not wrapped in the copy output. If you are comparing minified code, expect a table of very wide rows; reformat both sides with the JavaScript beautifier or the CSS beautifier before comparing them. That gives the diff real line structure to work with.

Limits and empty states

Each side is limited to 600 lines. Above that the page stops and explains the limit instead of attempting a comparison that could freeze the tab. The warning names both line counts and the limit, so you can see how far over the input is. For a whole repository, use a dedicated diff tool or git diff.

With both sides empty the result area asks for two versions rather than reporting a 0% match. With one side empty, every line on the other side is treated as an addition or a removal. A file that ends with a newline has a final empty line, which can appear as a difference even when the visible text looks the same.

There is no three-way merge, no syntax highlighting by language and no ignore-blank-lines option. Blank lines are compared like any other line, so a version that only removed blank lines will show a series of removals. Use the whitespace options for indentation, not for blank-line noise.

Questions

Common questions

Short answers about this tool and its limits.

How is the similarity score calculated?

It is twice the number of unchanged lines divided by the total lines in both versions, rounded to one decimal place. It measures shared lines under the chosen options, not shared characters or semantic similarity.

Why does a one-character edit show a whole line changed?

Because the comparison works line by line. It marks the old line as removed and the new line as added. A word-level or character-level diff would show the smaller change, but this tool keeps the line as its unit.

Does it ignore whitespace by default?

Only trailing whitespace. The default option strips spaces and tabs at the end of a line. Use Ignore all whitespace to remove spaces and tabs inside lines as well, which is what re-indentation needs.

Can I compare case-insensitively?

Yes. The Ignore case option lowercases both versions before comparison. The table still shows the original casing. With the option on, two versions that differ only in case are reported as identical.

What happens above 600 lines?

The page stops and shows a line-limit warning rather than running the comparison. Split the file into smaller sections or use a dedicated diff tool or git diff for a whole repository.

Does it support three-way merges?

No. It compares two versions only. There is no base version, no merge output and no conflict resolution. Use a version control tool for a three-way merge.

Is my code uploaded?

No. The comparison runs in the browser and the two text areas are the only inputs. There is no account, no stored history and no server-side copy, so the result disappears when you close the page unless you copy it.

Why do I see a difference at the end of the file?

A trailing newline creates a final empty line. If one version ends with a newline and the other does not, that empty line appears as an addition or removal even when the visible text is the same.