A text diff checker compares two pieces of text and highlights the differences line by line. It's one of the most-used tools in software engineering — baked into Git, VS Code, GitHub PRs, code review tools, document editors, and content management systems. This diff tool runs entirely in your browser, supports any text input (code, prose, JSON, logs, configs), and shows you exactly which lines were added, removed, or unchanged between the two versions.
How the Diff Algorithm Works
This tool implements a simple line-by-line comparison: each input is split on newlines, then corresponding lines are compared by string equality. Lines present only in the original are marked with - (deletion); lines present only in the modified version are marked with + (insertion); unchanged lines are prefixed with two spaces. For more sophisticated needs (longest common subsequence, character-level diffs, syntax-aware diffs), use dedicated tools like git diff, diff -u, delta, or difftastic.
When to Use a Text Diff
- Quick code comparison — pasting two snippets to see what changed.
- Config drift — comparing prod vs. staging config files.
- Log diffing — finding what's different between a working and a failing run.
- JSON / YAML comparison — format both with our JSON formatter first, then diff.
- Document revisions — spotting changes between two versions of a contract, blog post, or spec.
- Migration verification — before / after data dumps to confirm a migration did what you expected.
Diffing in Code
// Simple line-by-line diff in JavaScript
function diff(a, b) {
const linesA = a.split('\n'), linesB = b.split('\n');
const out = [];
const len = Math.max(linesA.length, linesB.length);
for (let i = 0; i < len; i++) {
if (linesA[i] === linesB[i]) out.push(' ' + linesA[i]);
else {
if (linesA[i] !== undefined) out.push('- ' + linesA[i]);
if (linesB[i] !== undefined) out.push('+ ' + linesB[i]);
}
}
return out.join('\n');
}
// CLI alternatives
diff -u old.txt new.txt // unified diff
git diff --no-index a.txt b.txt // git's diff on unversioned files
Line Diff vs. Character Diff vs. Semantic Diff
Line-based diffs (this tool, diff, git diff) are fast and work for any text but miss subtle changes inside a line. Character-based / word-based diffs (git diff --word-diff, wdiff) highlight specific words that changed within a line — better for prose. Semantic / syntax-aware diffs (difftastic, diffsitter) parse the input as code and diff the AST — a reformatting that changes whitespace but not behavior shows as zero diffs, which is a huge win for code review. For JSON specifically, format both sides identically first (use our JSON formatter), then a line diff becomes a useful structural diff.