Side-by-Side Diff View for Comparing Two Files

Learn how side-by-side diff view works by displaying two text versions in parallel columns. Understand line-level comparison, addition and deletion highlighting, and synchronized scrolling.

Basic Diff

Detailed Explanation

Side-by-Side Diff View

A side-by-side diff view is one of the most intuitive ways to compare two text files. It displays the original (left) and modified (right) versions in parallel columns, with color-coded highlighting to make changes immediately visible.

How Side-by-Side Diff Works

The diff algorithm first identifies matching lines between the two inputs, then classifies each line as:

  • Unchanged — present in both versions, shown on the same row
  • Deleted — present only in the original (left), highlighted in red
  • Added — present only in the modified (right), highlighted in green
  • Modified — line exists in both but content differs, highlighted with inline character-level markers
Original (Left)           Modified (Right)
─────────────────         ─────────────────
function greet() {        function greet() {
  return "hello";    →      return "Hello, World!";
}                         }

Synchronized Scrolling

In a side-by-side view, both panels scroll together so that corresponding lines always align horizontally. When a block of lines is added on one side, blank placeholder lines (sometimes called "phantom lines") are inserted on the opposite side to maintain alignment.

Character-Level Highlighting

Within modified lines, the best diff viewers go further by highlighting the specific characters that changed. For example, if "hello" changed to "Hello, World!", only the differing characters are marked — not the entire line.

Line Numbers

Each panel maintains its own independent line numbering. This is essential because insertions and deletions cause the line counts to diverge. The line numbers help you quickly reference specific changes in code reviews or bug reports.

When to Use Side-by-Side

Side-by-side diff is ideal when:

  • You have a wide screen with sufficient horizontal space
  • Changes are scattered across the file
  • You need to see both versions simultaneously for context
  • You are doing code review and want to compare old vs. new logic

Use Case

Side-by-side diff is the standard view for code reviews on GitHub, GitLab, and Bitbucket. Developers use it when reviewing pull requests, comparing configuration file changes before deployment, or auditing changes to documentation. It works best on wide monitors where both columns can display full lines without horizontal scrolling.

Try It — Diff Viewer

Open full tool