-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext-diff.html
More file actions
700 lines (617 loc) · 46.7 KB
/
Copy pathtext-diff.html
File metadata and controls
700 lines (617 loc) · 46.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Diff Checker Online — Compare Two Texts | FreeDevTool</title>
<meta name="description" content="Free online diff checker. Compare two texts side-by-side with line-by-line highlighting. Works for code, JSON, configs. Runs in browser, no signup.">
<meta name="robots" content="index, follow">
<meta name="author" content="Anees Ur Rehman">
<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","datePublished":"2026-05-02","dateModified":"2026-05-19","inLanguage":"en-US","isPartOf":{"@type":"WebSite","name":"FreeDevTool","url":"https://freedevtool.org"}}</script>
<script type="application/ld+json">{"@context":"https://schema.org","@type":"Person","name":"Anees Ur Rehman","url":"https://freedevtool.org/about","jobTitle":"Full-stack developer","worksFor":{"@type":"Organization","name":"FreeDevTool","url":"https://freedevtool.org"}}</script>
<link rel="canonical" href="https://freedevtool.org/text-diff">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preload" href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&family=DM+Sans:wght@300;400;500;600&display=swap" as="style">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&family=DM+Sans:wght@300;400;500;600&display=swap">
<link rel="preload" href="style.css?v=20260502-cards" as="style">
<link rel="stylesheet" href="style.css?v=20260502-cards">
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/favicon.svg">
<meta property="og:image" content="https://freedevtool.org/og-image.svg">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="FreeDevTool — 50+ free, fast, privacy-first developer tools">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://freedevtool.org/og-image.svg">
<meta name="twitter:title" content="Text Diff Checker — Compare Two Texts | FreeDevTool">
<meta name="twitter:description" content="Side-by-side diff for code, JSON, configs. Line-by-line highlighting. Runs in browser, no signup.">
<script async src="https://www.googletagmanager.com/gtag/js?id=G-3L0CMH3X36"></script>
<script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments)}gtag('js',new Date());gtag('config','G-3L0CMH3X36');</script>
<meta property="og:title" content="Text Diff Checker — Compare Two Texts Online Free">
<meta property="og:description" content="Find differences between two texts instantly. Side-by-side comparison with highlighted changes.">
<meta property="og:type" content="website">
<meta property="og:url" content="https://freedevtool.org/text-diff">
<script type="application/ld+json">
{"@context":"https://schema.org","@type":"WebApplication","name":"Text Diff Checker","url":"https://freedevtool.org/text-diff","description":"Compare two texts and find differences with highlighted additions and deletions.","applicationCategory":"DeveloperApplication","operatingSystem":"Any","offers":{"@type":"Offer","price":"0","priceCurrency":"USD"}}
</script>
<script type="application/ld+json">
{"@context":"https://schema.org","@type":"FAQPage","mainEntity":[
{"@type":"Question","name":"How do I compare two text files online?","acceptedAnswer":{"@type":"Answer","text":"Paste the original text in the left panel and the modified text in the right panel. The diff checker highlights additions (green), deletions (red), and unchanged lines. You can compare code, JSON, XML, HTML, or any plain text. All processing happens in your browser — no files are uploaded."}},
{"@type":"Question","name":"What is a diff checker and how does it work?","acceptedAnswer":{"@type":"Answer","text":"A diff checker compares two texts line by line and identifies differences using algorithms like the longest common subsequence (LCS). Lines present only in the original are marked as deletions, lines only in the modified version are additions, and matching lines are unchanged. This is the same concept behind git diff and code review tools."}},
{"@type":"Question","name":"What is the difference between unified diff and side-by-side diff?","acceptedAnswer":{"@type":"Answer","text":"Unified diff shows changes in a single column with + and - prefixes (like git diff output). Side-by-side diff shows the original and modified text in parallel columns, making it easier to visually compare changes. Side-by-side is better for reviewing; unified is more compact and commonly used in terminals and patches."}},
{"@type":"Question","name":"Can I compare code files online?","acceptedAnswer":{"@type":"Answer","text":"Yes. This diff checker works with any text format — JavaScript, Python, JSON, XML, HTML, CSS, YAML, SQL, and more. Paste your code in both panels to see line-by-line differences highlighted. For comparing entire files, copy-paste the file contents or use git diff for version-controlled files."}},
{"@type":"Question","name":"How do I find differences between two JSON files?","acceptedAnswer":{"@type":"Answer","text":"Paste both JSON documents into the left and right panels. The diff checker compares them line by line. For best results, format (pretty-print) both JSON objects first so that structural changes are visible on separate lines. Use our JSON Formatter tool to format JSON before comparing."}},{"@type":"Question","name":"What is the difference between unified and side-by-side diff?","acceptedAnswer":{"@type":"Answer","text":"Unified diff shows changes inline with context lines — common in git output and code review tools. Side-by-side shows old and new in two columns with changes highlighted — easier to compare longer changes visually. Both convey the same information."}},{"@type":"Question","name":"How does git diff work internally?","acceptedAnswer":{"@type":"Answer","text":"git diff compares the working directory (or staging area, or a commit) against another revision. The default algorithm is Myers, which finds the shortest edit script. Optional algorithms: patience, histogram, minimal. Configure with diff.algorithm."}},{"@type":"Question","name":"What is a semantic diff?","acceptedAnswer":{"@type":"Answer","text":"A diff that understands the structure of the file format being compared — parsing JSON and comparing structurally rather than character-by-character. Semantic diffs ignore cosmetic changes (whitespace, key reordering) and highlight structural changes."}}
]}
</script>
<style>
.diff-panels { display:grid; grid-template-columns:1fr 1fr; gap:0; margin-bottom:14px; }
@media(max-width:700px) { .diff-panels { grid-template-columns:1fr; } }
.diff-panel { }
.diff-panel:first-child textarea { border-radius:var(--radius) 0 0 var(--radius); border-right:none; }
.diff-panel:last-child textarea { border-radius:0 var(--radius) var(--radius) 0; }
@media(max-width:700px) {
.diff-panel:first-child textarea { border-radius:var(--radius) var(--radius) 0 0; border-right:1px solid var(--border); border-bottom:none; }
.diff-panel:last-child textarea { border-radius:0 0 var(--radius) var(--radius); }
}
.diff-panel textarea { min-height:200px; resize:vertical; width:100%; }
.diff-panel-label {
font-family:var(--mono); font-size:11px; color:var(--text3);
text-transform:uppercase; letter-spacing:.5px; margin-bottom:6px;
display:flex; align-items:center; gap:6px;
}
.diff-panel-label .dot-sm { width:8px; height:8px; border-radius:50%; }
.dot-orig { background:var(--red); }
.dot-mod { background:var(--accent); }
.diff-output { font-family:var(--mono); font-size:13px; line-height:1.7; }
.diff-line { display:flex; padding:2px 0; border-bottom:1px solid rgba(42,47,54,.3); }
.diff-line-num { width:36px; text-align:right; padding-right:8px; color:var(--text3); font-size:11px; flex-shrink:0; user-select:none; }
.diff-line-content { flex:1; padding:1px 8px; white-space:pre-wrap; word-break:break-all; }
.diff-add { background:rgba(0,208,132,.1); }
.diff-add .diff-line-content { color:var(--accent); }
.diff-add .diff-line-num { color:rgba(0,208,132,.5); }
.diff-del { background:rgba(255,90,90,.08); }
.diff-del .diff-line-content { color:var(--red); }
.diff-del .diff-line-num { color:rgba(255,90,90,.4); }
.diff-prefix { font-weight:700; margin-right:4px; user-select:none; }
.diff-stats {
display:flex; gap:16px; margin-bottom:14px; font-family:var(--mono); font-size:12px;
}
.diff-stats span { display:flex; align-items:center; gap:4px; }
</style>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"name": "Home",
"item": "https://freedevtool.org/"
},
{
"@type": "ListItem",
"position": 2,
"name": "All Tools",
"item": "https://freedevtool.org/all-tools"
},
{
"@type": "ListItem",
"position": 3,
"name": "Text Diff Checker — Compare Two Texts",
"item": "https://freedevtool.org/text-diff"
}
]
}
</script>
<script src="/ga4-events.js" defer></script>
</head>
<body>
<nav>
<a class="nav-logo" href="/" aria-label="FreeDevTool home"><svg class="logo-mark" width="22" height="22" viewBox="0 0 24 24" aria-hidden="true" fill="none"><rect x="1" y="1" width="22" height="22" rx="6" fill="currentColor" opacity=".12"/><path d="M9.5 8.5L6 12l3.5 3.5M14.5 8.5L18 12l-3.5 3.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>FreeDevTool</a>
<div class="nav-links">
<div class="nav-dropdown" id="tools-dropdown">
<a href="all-tools" onclick="event.preventDefault();this.parentElement.classList.toggle('open')" aria-haspopup="true">Tools <svg class="chev" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg></a>
<div class="nav-dropdown-menu">
<a href="encoding-tools">
<div class="dd-icon">b64</div>
<div class="dd-info"><div class="dd-name">Encoding & Conversion</div><div class="dd-count">11 tools · Base64, YAML, px→rem</div></div>
</a>
<a href="generation-tools">
<div class="dd-icon">{ }</div>
<div class="dd-info"><div class="dd-name">Generation & Formatting</div><div class="dd-count">16 tools · JSON, SQL, gradients</div></div>
</a>
<a href="security-tools">
<div class="dd-icon">#</div>
<div class="dd-info"><div class="dd-name">Security & Hashing</div><div class="dd-count">3 tools · JWT, MD5, SHA</div></div>
</a>
<a href="text-tools">
<div class="dd-icon">.*</div>
<div class="dd-info"><div class="dd-name">Code & Text Tools</div><div class="dd-count">9 tools · Regex, diff, tokens</div></div>
</a>
<a href="devops-tools">
<div class="dd-icon">JS</div>
<div class="dd-info"><div class="dd-name">Optimization & DevOps</div><div class="dd-count">7 tools · Minifiers, cURL, git</div></div>
</a>
<a href="network-tools">
<div class="dd-icon">IP</div>
<div class="dd-info"><div class="dd-name">Network & Time</div><div class="dd-count">4 tools · IP, DNS, timestamps</div></div>
</a>
<a href="seo-tools">
<div class="dd-icon">SEO</div>
<div class="dd-info"><div class="dd-name">SEO & Meta Tools</div><div class="dd-count">3 tools · OG, meta, slug</div></div>
</a>
<div class="nav-dropdown-divider"></div>
<a class="dd-all" href="all-tools">
<div class="dd-icon">All</div>
<div class="dd-info"><div class="dd-name">Browse all 50 tools</div><div class="dd-count">Searchable catalog & categories</div></div>
</a>
</div>
</div>
<a href="/guides">Guides</a>
<a href="about">About</a>
<a href="privacy">Privacy</a>
</div>
</nav>
<div id="copy-toast">Copied!</div>
<div class="wrapper">
<a class="tool-back" href="/" aria-label="Back to home">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M15 18l-6-6 6-6"/></svg>
Back
</a>
<div class="tool-header">
<div class="tool-badge">Developer Tool</div>
<h1>Diff Checker — Compare Two Texts Online</h1>
<p class="tool-description">
Compare two texts side-by-side and find every difference instantly. Highlights additions, deletions, and unchanged lines (same algorithm as <code>git diff</code>). Works for code, JSON, XML, YAML, configs, and plain text. Runs in your browser — credentials and PII never leave your device.
</p>
<div class="last-updated">Last updated: May 2026 · Written by <a href="/about">Anees Ur Rehman</a>, full-stack developer</div>
</div>
<div class="tool-card">
<div class="tool-card-header">
<div class="dot dot-red"></div><div class="dot dot-yellow"></div><div class="dot dot-green"></div>
<span class="tool-card-title">text-diff.tool</span>
</div>
<div class="tool-body">
<div class="diff-panels">
<div class="diff-panel">
<div class="diff-panel-label"><span class="dot-sm dot-orig"></span> Original</div>
<textarea id="diff-a" placeholder="Paste original text here..." rows="8"></textarea>
</div>
<div class="diff-panel">
<div class="diff-panel-label"><span class="dot-sm dot-mod"></span> Modified</div>
<textarea id="diff-b" placeholder="Paste modified text here..." rows="8"></textarea>
</div>
</div>
<div class="btn-row">
<button class="btn btn-primary" onclick="runDiff()">Compare</button>
<button class="btn btn-secondary" onclick="swapPanels()">Swap</button>
<button class="btn btn-secondary" onclick="clearAll()">Clear</button>
</div>
<div class="divider"></div>
<div class="diff-stats" id="diff-stats" style="display:none">
<span style="color:var(--accent)">+ <span id="stat-add">0</span> additions</span>
<span style="color:var(--red)">− <span id="stat-del">0</span> deletions</span>
<span style="color:var(--text3)"><span id="stat-same">0</span> unchanged</span>
</div>
<div class="output-block diff-output" id="diff-output" style="color:var(--text2);font-style:italic;min-height:80px">
Click "Compare" to see differences...
</div>
</div>
</div>
<!-- =============================================================
LONG-FORM ARTICLE — comprehensive guide for E-E-A-T + ranking.
============================================================= -->
<article>
<p class="aeo-lead" style="font-size:16px;line-height:1.7;color:var(--text);max-width:760px;margin:24px auto 18px;padding:0 4px">
<strong>A text diff</strong> compares two pieces of text and shows what changed — insertions, deletions, modifications — using algorithms like Myers, patience, or histogram. Common granularities: line-by-line for code, word-by-word for prose, character-level for tiny differences. This <strong>free text diff tool</strong> runs entirely in your browser — your text never leaves the page, unlike some online diff tools.
</p>
<section id="examples" style="max-width:760px;margin:24px auto 32px">
<h2 style="font-size:18px;margin-bottom:14px">Examples</h2>
<div style="background:var(--bg3);border:1px solid var(--border);border-radius:var(--radius);padding:16px;margin-bottom:12px">
<strong style="display:block;color:var(--accent);font-family:var(--mono);font-size:11px;text-transform:uppercase;letter-spacing:1px;margin-bottom:6px">Line-by-line diff§§Old: function add(a, b) { return a + b; }§§New: function add(x, y) { return x + y; }§§Diff shows whole line replaced (renamed parameters).</strong>
</div>
<div style="background:var(--bg3);border:1px solid var(--border);border-radius:var(--radius);padding:16px;margin-bottom:12px">
<strong style="display:block;color:var(--accent);font-family:var(--mono);font-size:11px;text-transform:uppercase;letter-spacing:1px;margin-bottom:6px">Word-by-word diff§§Old: The quick brown fox jumps§§New: The slow brown dog jumps§§Two word substitutions: "quick" → "slow", "fox" → "dog". Useful for prose.</strong>
</div>
<div style="background:var(--bg3);border:1px solid var(--border);border-radius:var(--radius);padding:16px;margin-bottom:12px">
<strong style="display:block;color:var(--accent);font-family:var(--mono);font-size:11px;text-transform:uppercase;letter-spacing:1px;margin-bottom:6px">Whitespace-only changes§§Toggle "ignore whitespace" to filter out cosmetic differences — indentation changes, trailing spaces, line endings (CRLF vs LF). Useful for git diff cleanup.</strong>
</div>
</section>
<aside class="founder-note" style="max-width:760px;margin:24px auto 32px;padding:20px 24px;background:rgba(0,208,132,0.05);border-left:3px solid var(--accent);border-radius:6px;font-size:14px;line-height:1.7;color:var(--text2)"><div style="font-family:var(--mono);font-size:11px;color:var(--accent);letter-spacing:1.5px;text-transform:uppercase;margin-bottom:10px;font-weight:600">💡 Why I built this</div><p style="margin:0 0 12px">I built this because diffchecker.com pushes you to sign up after a few uses, and I was tired of pasting customer code into a tool that wanted to upgrade me. This diff tool does line-by-line, word-by-word, and character-by-character comparison entirely in browser. Your text never leaves the page. Use it for code review when GitHub’s diff is not right, comparing API responses, or finding the one space character breaking your YAML.</p><p style="margin:0;font-size:13px;color:var(--text3)">— <a href="/about" style="color:var(--accent);text-decoration:none">Anees Ur Rehman</a>, full-stack developer</p></aside>
<section class="article-section">
<h2>What is a text diff and how does it work?</h2>
<p>A <strong>text diff</strong> is the computed difference between two pieces of text, showing what was added, removed, or changed. It's the algorithm behind Git's <code>git diff</code>, every code review tool, every IDE merge conflict resolver, every "track changes" feature in Word and Google Docs, and most database synchronization tools. The most influential algorithm — <a href="https://www.cs.dartmouth.edu/~doug/diff.pdf" rel="noopener">"An O(ND) Difference Algorithm and its Variations"</a> by Eugene Myers (1986) — still powers Git, GNU diff, and most production diff tools 40 years later.</p>
<p>Conceptually, a diff finds the <strong>longest common subsequence (LCS)</strong> between two texts and reports everything that's NOT in that LCS as either an addition (in the new file) or deletion (only in the old file). The result is the smallest possible "patch" that turns the old text into the new.</p>
<p>Different tools display diffs differently:</p>
<ul>
<li><strong>Unified diff</strong> — Git's default. Shows old/new on alternating lines, prefixed with <code>-</code> and <code>+</code>.</li>
<li><strong>Side-by-side diff</strong> — old on left, new on right, aligned. Easier to read for prose; what most code review tools (GitHub, GitLab, Phabricator) use as default.</li>
<li><strong>Inline diff</strong> — single column with strikethrough for deletions and color for additions. Compact but harder for big changes.</li>
</ul>
</section>
<section class="article-section">
<h2>Diff granularity — line vs word vs character</h2>
<table class="ref-table">
<thead><tr><th>Granularity</th><th>Best for</th><th>Tool</th></tr></thead>
<tbody>
<tr><td><strong>Line-level</strong></td><td>Code, configs — most common diff type</td><td>git diff, GNU diff, this tool</td></tr>
<tr><td><strong>Word-level</strong></td><td>Prose, documentation, blog posts</td><td>git diff <code>--word-diff</code>, Google Docs</td></tr>
<tr><td><strong>Character-level</strong></td><td>Tiny strings, IDs, version numbers</td><td>JS libraries (diff-match-patch), Word</td></tr>
<tr><td><strong>Hunk / block</strong></td><td>Showing context around changes</td><td>git diff <code>-U3</code> (3-line context)</td></tr>
<tr><td><strong>Semantic / AST</strong></td><td>Understanding logic changes in code</td><td>difftastic, semantic-diff (research-grade)</td></tr>
</tbody>
</table>
<p><strong>This tool uses line-level diff</strong> with optional word-level highlighting within changed lines. That matches what you'd expect from <code>git diff</code> or a typical code-review interface.</p>
</section>
<section class="article-section">
<h2>Compare code online, find difference in code, string compare — same workflow, different phrasing</h2>
<p>Search variants for the same intent: "compare code online", "find difference in code", "string compare online", "online string compare", "js compare online", "online diff checker", "diff compare online". They all describe pasting two pieces of text into a tool and seeing what changed. The diff checker above handles all of them — code in any language, plain strings, JSON blobs, log lines, configuration files. Each H3 below addresses one specific phrasing.</p>
<h3>Compare code online — what makes a good code diff</h3>
<p>A good code diff is more than a line-by-line minus/plus. It also needs <strong>(1)</strong> whitespace-aware mode (toggle off "ignore whitespace" when indentation matters; toggle on for refactor reviews), <strong>(2)</strong> word-level highlighting within changed lines so a one-character rename doesn't paint the whole line red, <strong>(3)</strong> handling of long lines without forced wrap that distorts the diff. The tool above does all three. For comparing two files in different formats — e.g., one minified and one beautified version of the same JavaScript — run both sides through the <a href="/js-minifier">JS minifier</a>'s beautify mode first, then diff.</p>
<h3>Find difference in code — without copy-pasting into git</h3>
<p>Three scenarios where this is faster than <code>git diff</code>: <strong>(1)</strong> one of the two versions isn't in version control (a teammate's Slack paste, a production config you SSH'd into, an AI-generated patch); <strong>(2)</strong> the files are in different repos that don't share history; <strong>(3)</strong> you want to share the diff visually with someone who doesn't run a CLI. Paste both versions into the tool above, take a screenshot of the highlighted output, and share. For longer-term tracking, commit both versions to a scratch branch and use <code>git diff branch1..branch2</code>.</p>
<h3>String compare online — for non-code text comparison</h3>
<p>"String compare" usually means smaller payloads than full files: SQL query strings between two app versions, error messages between two log lines, two API responses to the same call. The diff above is identical for short strings — paste left and right, see character-level differences. For very short strings (under 100 chars) where you only care about exact equality, JavaScript's <code>===</code> in the browser console is faster; the diff tool's value is when you want to <em>see</em> what differs, not just whether they differ.</p>
<h3>JS compare online — for JavaScript snippets and JSON payloads</h3>
<p>"JS compare online" usually means one of two things: <strong>(1)</strong> compare two JavaScript source snippets (different versions of the same function, two implementations being benchmarked), or <strong>(2)</strong> compare two JSON payloads (API responses, config objects). The diff above handles both. For JSON specifically, beautify both sides through the <a href="/json-formatter">JSON formatter</a> first so structural differences don't get drowned out by formatting noise. For sorted-key comparison (where key order doesn't matter), pass each side through <code>jq -S '.'</code> at the CLI before pasting.</p>
<h2>Online diff compare — when to use a browser tool vs CLI</h2>
<p>Browser-based diff is fastest for one-off comparisons: paste two snippets, scan the highlighted output, copy the merged result. CLI <code>diff</code> wins when you're already in a terminal, scripting batch comparisons, or working with files too large to paste. The tool above handles the browser case; for the CLI, <code>diff -u old.txt new.txt</code> produces a unified diff that GitHub, Phabricator, and every code-review platform understand. Quick comparison alongside related tasks: format the inputs first with the <a href="/json-formatter">JSON formatter</a> or <a href="/sql-formatter">SQL formatter</a> so whitespace differences don't drown out the real changes.</p>
<h3>Git diff vs online diff compare — a practical workflow</h3>
<p>Use <code>git diff branch1..branch2 -- path/to/file</code> when both versions are committed. Use this online diff when one or both versions live outside Git: a teammate's Slack paste, a production config you SSH'd into, an AI-generated patch you haven't applied yet. The display semantics match — additions in green, deletions in red, unchanged lines neutral — so muscle memory from <code>git diff</code> transfers directly. For comparing minified JS or compressed JSON, run each side through the <a href="/js-minifier">JS minifier</a>'s <em>beautify</em> mode first.</p>
<h2>Common diff use cases</h2>
<ul>
<li><strong>Code review</strong> — comparing two versions of a file before merging a PR. The most common use, and what most diff tools optimize for.</li>
<li><strong>Configuration drift detection</strong> — comparing the running config of a server against the canonical version in your repo. Catches manual changes that didn't make it into version control.</li>
<li><strong>API response comparison</strong> — running the same API call before and after a deploy and diffing the responses. Catches subtle regressions in serialization or default values.</li>
<li><strong>Log file analysis</strong> — diffing yesterday's log output against today's. New error messages stand out instantly.</li>
<li><strong>Document version comparison</strong> — comparing two drafts of a contract, blog post, or specification. Lawyers and editors use this all day.</li>
<li><strong>Database schema migration verification</strong> — comparing <code>SHOW CREATE TABLE</code> output before and after a migration to verify changes.</li>
<li><strong>Detecting copy-paste content theft</strong> — paste suspect content alongside the original; diff highlights how much was copied verbatim.</li>
</ul>
</section>
<section class="article-section">
<h2>Diffing in 8 environments</h2>
<h3>Git (the most common diff in 2026)</h3>
<div class="lang-block">
<div class="lang-block-header">git</div>
<pre><code># Diff working tree vs last commit
git diff
# Diff between two commits
git diff abc123 def456
# Side-by-side via tool integration
git difftool -t vimdiff # or vscode, meld, kdiff3, beyond compare
# Word-level diff for prose
git diff --word-diff
# Show only filenames changed
git diff --name-only
# Statistics summary
git diff --stat
# Diff a specific file across all commits
git log -p -- path/to/file.txt</code></pre>
</div>
<h3>GNU diff (POSIX command line)</h3>
<div class="lang-block">
<div class="lang-block-header">bash</div>
<pre><code># Unified format (most readable)
diff -u old.txt new.txt
# Side-by-side
diff -y old.txt new.txt
# Recursive directory diff
diff -ur old_dir/ new_dir/
# Ignore whitespace changes
diff -u -w old.txt new.txt
# Generate a patch and apply it
diff -u old.txt new.txt > changes.patch
patch old.txt < changes.patch
</code></pre>
</div>
<h3>JavaScript (diff library)</h3>
<div class="lang-block">
<div class="lang-block-header">javascript</div>
<pre><code>import { diffLines, diffWords, diffChars } from 'diff';
const changes = diffLines(oldText, newText);
changes.forEach(part => {
const sign = part.added ? '+' : part.removed ? '-' : ' ';
console.log(sign + part.value);
});
// Word-level
const wordChanges = diffWords(oldText, newText);
// Generate unified-format patch
import { createPatch } from 'diff';
const patch = createPatch('file.txt', oldText, newText, 'old version', 'new version');
</code></pre>
</div>
<h3>Python (difflib — built-in)</h3>
<div class="lang-block">
<div class="lang-block-header">python</div>
<pre><code>import difflib
old = open('old.txt').readlines()
new = open('new.txt').readlines()
# Unified diff
for line in difflib.unified_diff(old, new, fromfile='old', tofile='new'):
print(line, end='')
# HTML side-by-side
html = difflib.HtmlDiff().make_file(old, new)
# Quick similarity ratio (0–1)
ratio = difflib.SequenceMatcher(None, old_str, new_str).ratio()
</code></pre>
</div>
<h3>Go (golang-diff)</h3>
<div class="lang-block">
<div class="lang-block-header">go</div>
<pre><code>import "github.com/sergi/go-diff/diffmatchpatch"
dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(oldText, newText, false)
fmt.Println(dmp.DiffPrettyText(diffs))
</code></pre>
</div>
<h3>Online tools beyond Git</h3>
<ul>
<li><strong>Beyond Compare</strong> — paid, best-in-class folder diff (Windows/Mac).</li>
<li><strong>Meld</strong> — open-source 3-way diff, great for merge conflicts.</li>
<li><strong>VS Code's built-in diff</strong> — open two files, right-click → "Compare Selected".</li>
<li><strong>JetBrains IDEs</strong> — built-in diff, supports code-aware highlighting.</li>
<li><strong>difftastic</strong> — modern AST-aware diff. Treats <code>{x: 1, y: 2}</code> and <code>{ "y": 2, "x": 1 }</code> as the same.</li>
</ul>
</section>
<section class="article-section">
<h2>Common diff problems & fixes</h2>
<ul>
<li><strong>"Every line shows as changed."</strong> Caused by line-ending mismatches (CRLF vs LF). Normalize with <code>dos2unix</code> first or use <code>git diff -w</code>.</li>
<li><strong>Trailing whitespace makes diff noisy.</strong> Use <code>diff -w</code> or <code>git diff --ignore-all-space</code> to focus on meaningful changes.</li>
<li><strong>Reordered keys in JSON show as huge changes.</strong> Sort keys before diffing, or use <code>jq --sort-keys</code> on both sides first.</li>
<li><strong>Auto-formatter ran across the file.</strong> Looks like a massive refactor. Rebase onto a "format-only" commit, mark it in <code>.git-blame-ignore-revs</code>, then diff the actual logic changes.</li>
<li><strong>Binary files diff as gibberish.</strong> Most diff tools don't handle binary. Use <code>git diff --binary</code> for transport or specialized tools (xxdiff for hex).</li>
<li><strong>Patches don't apply cleanly.</strong> The base file changed since the patch was created. Use <code>git apply --3way</code> or merge tools.</li>
</ul>
</section>
<section class="article-section">
<h2>Diff best practices for 2026</h2>
<ul>
<li><strong>Keep PRs small.</strong> A 50-line diff is reviewed in 10 minutes; a 500-line diff in days. Break big changes into stacked PRs.</li>
<li><strong>Format before commit.</strong> Save formatting changes for separate commits so logic diffs aren't drowned in whitespace noise.</li>
<li><strong>Use <code>.gitattributes</code> for binary & minified files.</strong> Mark them as <code>binary</code> so Git doesn't try to diff them.</li>
<li><strong>Diff JSON with <code>jq --sort-keys</code></strong> first to get clean output regardless of key order.</li>
<li><strong>Use <code>--word-diff</code> for prose.</strong> Far more useful than line-diff for documentation, blog posts, and contracts.</li>
<li><strong>Set up <code>git config diff.algorithm histogram</code></strong> for better diff results on refactored code.</li>
<li><strong>For visual diff in PRs, configure your platform's "render" mode.</strong> Markdown, JSON, and image diffs render specially in GitHub/GitLab.</li>
<li><strong>Don't reformat & logic-change in one commit.</strong> Reviewers can't tell formatting from substance. Two commits = two PRs of clean review.</li>
</ul>
</section>
</article>
<section class="faq-section">
<h2>Frequently Asked Questions</h2>
<div class="faq-item open">
<div class="faq-q" onclick="toggleFaq(this)">How do I compare two text files online?<svg class="chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg></div>
<div class="faq-a">Paste the <strong>original text</strong> in the left panel and the <strong>modified text</strong> in the right panel, then click "Compare." The diff checker highlights additions (green with +), deletions (red with −), and unchanged lines. You can compare code, JSON, XML, HTML, config files, or any plain text. All comparison happens in your browser — nothing is uploaded to any server.</div>
</div>
<div class="faq-item">
<div class="faq-q" onclick="toggleFaq(this)">What is a diff checker and how does it work?<svg class="chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg></div>
<div class="faq-a">A diff checker compares two texts <strong>line by line</strong> and identifies differences using algorithms like the longest common subsequence (LCS). Lines present only in the original are marked as <strong>deletions</strong> (−), lines only in the modified version are <strong>additions</strong> (+), and matching lines remain unchanged. This is the same concept behind <code>git diff</code>, GitHub pull request reviews, and code review tools.</div>
</div>
<div class="faq-item">
<div class="faq-q" onclick="toggleFaq(this)">What is the difference between unified diff and side-by-side diff?<svg class="chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg></div>
<div class="faq-a"><strong>Unified diff</strong> shows changes in a single column with <code>+</code> and <code>-</code> prefixes — this is what <code>git diff</code> produces. <strong>Side-by-side diff</strong> shows original and modified text in parallel columns. Unified is more compact and commonly used in terminals, patches, and email; side-by-side is better for visual code reviews. This tool shows unified-style output.</div>
</div>
<div class="faq-item">
<div class="faq-q" onclick="toggleFaq(this)">Can I compare JSON files with this tool?<svg class="chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg></div>
<div class="faq-a">Yes. Paste both JSON documents into the panels and click Compare. For best results, <strong>pretty-print both JSON objects first</strong> so structural changes appear on separate lines. Use our <a href="json-formatter" style="color:var(--accent)">JSON Formatter</a> to format JSON before comparing — this ensures keys and values are on individual lines, making the diff much more readable.</div>
</div>
<div class="faq-item">
<div class="faq-q" onclick="toggleFaq(this)">Is my data safe when comparing texts?<svg class="chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg></div>
<div class="faq-a"><strong>Yes.</strong> All comparison processing happens entirely in your browser using JavaScript. No text is ever sent to a server, stored, or logged. The tool works fully offline once loaded. You can safely compare sensitive code, configuration files, API responses, and credentials without privacy concerns.</div>
</div>
</section>
<section class="related-section">
<h2>Related Tools</h2>
<div class="related-grid">
<a class="related-card" href="json-formatter"><div class="related-icon">{ }</div><div class="related-card-info"><div class="related-card-name">JSON Formatter</div><div class="related-card-desc">Pretty print and validate JSON</div></div></a>
<a class="related-card" href="regex-tester"><div class="related-icon">.*</div><div class="related-card-info"><div class="related-card-name">Regex Tester</div><div class="related-card-desc">Test regex patterns live</div></div></a>
<a class="related-card" href="hash-generator"><div class="related-icon">#</div><div class="related-card-info"><div class="related-card-name">Hash Generator</div><div class="related-card-desc">Generate MD5, SHA-256 hashes</div></div></a>
</div>
</section>
<section class="all-tools-section" aria-label="Browse all FreeDevTool developer tools">
<h2>Browse all 50 free developer tools</h2>
<p class="atc-sub">All tools run in your browser, no signup required, nothing sent to a server.</p>
<div class="all-tools-grid">
<div class="atc-cat">
<div class="atc-cat-head">
<div class="atc-cat-icon">b64</div>
<div class="atc-cat-title"><h3>Encoding & Conversion</h3><span class="atc-cat-count">11 tools</span></div>
</div>
<ul class="atc-list">
<li><a href="/base64-encoder">Base64 Encoder / Decoder</a></li>
<li><a href="/base64-image">Image to Base64</a></li>
<li><a href="/byte-converter">Byte Converter (KB / MB / GB)</a></li>
<li><a href="/case-converter">Case Converter</a></li>
<li><a href="/hex-to-rgb">Hex to RGB / HSL</a></li>
<li><a href="/html-entity">HTML Entity Encoder</a></li>
<li><a href="/json-to-csv">JSON to CSV Converter</a></li>
<li><a href="/px-to-rem">PX to REM Converter</a></li>
<li><a href="/string-escape">String Escape / Unescape</a></li>
<li><a href="/url-encoder">URL Encoder / Decoder</a></li>
<li><a href="/yaml-to-json">YAML to JSON Converter</a></li>
</ul>
</div>
<div class="atc-cat">
<div class="atc-cat-head">
<div class="atc-cat-icon">{ }</div>
<div class="atc-cat-title"><h3>Formatting & Generators</h3><span class="atc-cat-count">13 tools</span></div>
</div>
<ul class="atc-list">
<li><a href="/color-name">Color Name from Hex</a></li>
<li><a href="/color-picker">Color Palette Picker</a></li>
<li><a href="/css-box-shadow">CSS Box Shadow</a></li>
<li><a href="/css-gradient">CSS Gradient Generator</a></li>
<li><a href="/json-formatter">JSON Formatter / Validator</a></li>
<li><a href="/lorem-ipsum">Lorem Ipsum Generator</a></li>
<li><a href="/markdown-preview">Markdown Preview</a></li>
<li><a href="/password-generator">Password Generator</a></li>
<li><a href="/qr-generator">QR Code Generator</a></li>
<li><a href="/sql-formatter">SQL Formatter</a></li>
<li><a href="/uuid-generator">UUID Generator</a></li>
<li><a href="/word-to-markdown">Word to Markdown</a></li>
<li><a href="/xml-formatter">XML Formatter</a></li>
</ul>
</div>
<div class="atc-cat">
<div class="atc-cat-head">
<div class="atc-cat-icon">JS</div>
<div class="atc-cat-title"><h3>Minifiers & DevOps</h3><span class="atc-cat-count">6 tools</span></div>
</div>
<ul class="atc-list">
<li><a href="/chmod-calculator">chmod Calculator</a></li>
<li><a href="/cron-parser">Cron Expression Parser</a></li>
<li><a href="/css-minifier">CSS Minifier</a></li>
<li><a href="/html-minifier">HTML Minifier</a></li>
<li><a href="/js-minifier">JavaScript Minifier</a></li>
<li><a href="/http-status">HTTP Status Codes</a></li>
</ul>
</div>
<div class="atc-cat">
<div class="atc-cat-head">
<div class="atc-cat-icon">#</div>
<div class="atc-cat-title"><h3>Security & Hashing</h3><span class="atc-cat-count">3 tools</span></div>
</div>
<ul class="atc-list">
<li><a href="/hash-generator">Hash Generator (MD5, SHA)</a></li>
<li><a href="/jwt-decoder">JWT Decoder</a></li>
<li><a href="/jwt-generator">JWT Generator</a></li>
</ul>
</div>
<div class="atc-cat">
<div class="atc-cat-head">
<div class="atc-cat-icon">.*</div>
<div class="atc-cat-title"><h3>Code & Text</h3><span class="atc-cat-count">8 tools</span></div>
</div>
<ul class="atc-list">
<li><a href="/ai-token-counter">AI Token Counter</a></li>
<li><a href="/char-counter">Character & Word Counter</a></li>
<li><a href="/git-cheatsheet">Git Commands Cheatsheet</a></li>
<li><a href="/number-base">Number Base Converter</a></li>
<li><a href="/regex-explainer">Regex Explainer</a></li>
<li><a href="/regex-tester">Regex Tester</a></li>
<li><a href="/text-diff">Text Diff Checker</a></li>
<li><a href="/wcag-contrast">WCAG Contrast Checker</a></li>
</ul>
</div>
<div class="atc-cat">
<div class="atc-cat-head">
<div class="atc-cat-icon">IP</div>
<div class="atc-cat-title"><h3>Network & APIs</h3><span class="atc-cat-count">3 tools</span></div>
</div>
<ul class="atc-list">
<li><a href="/dns-lookup">DNS Lookup</a></li>
<li><a href="/http-request-builder">HTTP Request Builder</a></li>
<li><a href="/ip-lookup">IP Address Lookup</a></li>
</ul>
</div>
<div class="atc-cat">
<div class="atc-cat-head">
<div class="atc-cat-icon">⏱</div>
<div class="atc-cat-title"><h3>Time & Dates</h3><span class="atc-cat-count">3 tools</span></div>
</div>
<ul class="atc-list">
<li><a href="/relative-time">Relative Time Calculator</a></li>
<li><a href="/timestamp-diff">Timestamp Diff</a></li>
<li><a href="/unix-timestamp-converter">Unix Timestamp Converter</a></li>
</ul>
</div>
<div class="atc-cat">
<div class="atc-cat-head">
<div class="atc-cat-icon">SEO</div>
<div class="atc-cat-title"><h3>SEO & Meta</h3><span class="atc-cat-count">3 tools</span></div>
</div>
<ul class="atc-list">
<li><a href="/meta-tag-generator">Meta Tag Generator</a></li>
<li><a href="/og-preview">Open Graph Preview</a></li>
<li><a href="/slug-generator">URL Slug Generator</a></li>
</ul>
</div>
</div>
</section>
</div>
<footer>
<div>© 2026 FreeDevTool — Text Diff Checker</div>
<div class="footer-links"><a href="/all-tools">All Tools</a><a href="/about">About</a><a href="/privacy">Privacy Policy</a><a href="/terms">Terms of Use</a></div>
</footer>
<script>
// Simple LCS-based diff
function diff(a, b) {
const linesA = a.split('\n');
const linesB = b.split('\n');
const m = linesA.length, n = linesB.length;
// Build LCS table
const dp = Array(m + 1).fill(null).map(() => Array(n + 1).fill(0));
for (let i = 1; i <= m; i++)
for (let j = 1; j <= n; j++)
dp[i][j] = linesA[i-1] === linesB[j-1] ? dp[i-1][j-1] + 1 : Math.max(dp[i-1][j], dp[i][j-1]);
// Backtrack
const result = [];
let i = m, j = n;
while (i > 0 || j > 0) {
if (i > 0 && j > 0 && linesA[i-1] === linesB[j-1]) {
result.unshift({ type: 'same', line: linesA[i-1], numA: i, numB: j });
i--; j--;
} else if (j > 0 && (i === 0 || dp[i][j-1] >= dp[i-1][j])) {
result.unshift({ type: 'add', line: linesB[j-1], numB: j });
j--;
} else {
result.unshift({ type: 'del', line: linesA[i-1], numA: i });
i--;
}
}
return result;
}
function esc(s) { return s.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'); }
function runDiff() {
const a = document.getElementById('diff-a').value;
const b = document.getElementById('diff-b').value;
const outEl = document.getElementById('diff-output');
if (!a && !b) {
outEl.innerHTML = '<span style="color:var(--text2);font-style:italic">Paste text in both panels and click Compare</span>';
document.getElementById('diff-stats').style.display = 'none';
return;
}
const result = diff(a, b);
let adds = 0, dels = 0, same = 0;
let html = '';
result.forEach(r => {
if (r.type === 'same') {
same++;
html += '<div class="diff-line"><span class="diff-line-num">' + (r.numA||'') + '</span><span class="diff-line-content"><span class="diff-prefix" style="color:var(--text3)"> </span>' + esc(r.line) + '</span></div>';
} else if (r.type === 'add') {
adds++;
html += '<div class="diff-line diff-add"><span class="diff-line-num">' + (r.numB||'') + '</span><span class="diff-line-content"><span class="diff-prefix">+</span>' + esc(r.line) + '</span></div>';
} else {
dels++;
html += '<div class="diff-line diff-del"><span class="diff-line-num">' + (r.numA||'') + '</span><span class="diff-line-content"><span class="diff-prefix">−</span>' + esc(r.line) + '</span></div>';
}
});
outEl.innerHTML = html || '<div style="color:var(--accent);padding:12px">✓ Both texts are identical</div>';
outEl.style.fontStyle = 'normal';
document.getElementById('stat-add').textContent = adds;
document.getElementById('stat-del').textContent = dels;
document.getElementById('stat-same').textContent = same;
document.getElementById('diff-stats').style.display = '';
}
function swapPanels() {
const a = document.getElementById('diff-a').value;
const b = document.getElementById('diff-b').value;
document.getElementById('diff-a').value = b;
document.getElementById('diff-b').value = a;
}
function clearAll() {
document.getElementById('diff-a').value = '';
document.getElementById('diff-b').value = '';
document.getElementById('diff-output').innerHTML = '<span style="color:var(--text2);font-style:italic">Click "Compare" to see differences...</span>';
document.getElementById('diff-stats').style.display = 'none';
}
function showToast() { const t=document.getElementById('copy-toast');t.classList.add('show');setTimeout(()=>t.classList.remove('show'),1800); }
function toggleFaq(el) { el.parentElement.classList.toggle('open'); }
</script>
<script>document.addEventListener('click',e=>{const dd=document.getElementById('tools-dropdown');if(dd&&!dd.contains(e.target))dd.classList.remove('open')});</script>
</body>
</html>