We use cookies to understand how DevToolsHub is used and to improve your experience. You can choose which types of cookies to allow.
Compare two text blocks and highlight the differences line by line.
Loading...
Loading...
A text diff checkeris a tool that compares two pieces of text and highlights the differences between them. The word “diff” is short for “difference,” and diff tools have been a staple of software development since the early days of Unix in the 1970s. The originaldiff command, created by Douglas McIlroy in 1974, established the fundamental approach that modern diff tools still follow: identify which lines were added, removed, or changed between two versions of a file.
DevToolsHub’s Text Diff Checker brings this essential capability to your browser with a clean, intuitive interface. It uses the Longest Common Subsequence (LCS)algorithm — the same mathematical foundation used by Git, diff utilities, and merge tools — to determine the minimal set of changes between two texts. The result is presented in two view modes: an inline unified view (similar to diff -u output) and a side-by-side view that shows both versions simultaneously for easy visual comparison.
Unlike command-line diff tools that require a terminal and file access, this tool runs entirely in your browser. You can paste any two texts — code snippets, configuration files, blog drafts, legal documents, or any plain text — and instantly see what changed. The tool works offline once loaded, never sends your data to a server, and handles files of any size that your browser can manage. It also supports options to ignore whitespace differences and case, making it flexible enough for a wide range of comparison scenarios.
+, removals with -), or “Side-by-Side” for a two-column layout.The core of any diff tool is the algorithm used to find the differences between two texts. This tool uses the Longest Common Subsequence (LCS) algorithm, which is one of the most widely used approaches in diff tools. The LCS algorithm works by finding the longest sequence of lines that appear in both texts in the same order (though not necessarily consecutively). Once the LCS is identified, any lines not in the LCS are classified as additions or removals.
The algorithm operates in two phases. First, it builds a dynamic programming table where each cell table[i][j] stores the length of the LCS of the first i lines of text 1 and the first j lines of text 2. This table is built bottom-up in O(m × n) time and space, where m and n are the number of lines in each text. Second, it backtracks through the table from table[m][n] back to table[0][0], emitting diff lines as it goes: when the lines match, it emits an unchanged line; when it moves up, it emits a removal; when it moves left, it emits an addition.
The LCS-based approach produces a minimal edit script— the smallest set of changes needed to transform text 1 into text 2. This is the same approach used by Git’s git diff command, the diff utility, and many code review tools. More advanced algorithms like Myers’ difference algorithm or the patience diff algorithm offer performance improvements or better semantic grouping, but the LCS algorithm remains the clearest and most educational approach for understanding how diffs work.
The unified diff format (shown in inline mode) is a standard way to represent diffs compactly. It groups changes into hunks, each preceded by a header like @@ -1,3 +1,4 @@ that indicates the starting line and count in both the original and modified files. Lines prefixed with + are additions, lines prefixed with - are removals, and lines prefixed with a space are context (unchanged). This format is used by Git, patch files, and code review tools.
Loading...