# #150 — Feature Comparison Matrix

> Pricing & capability matrix with sticky plan headers, Monthly/Annual toggle, 'Differences Only' filter, and mobile 2-plan compare.

## Metadata

- **Index**: #150
- **Slug**: `feature-comparison-matrix`
- **Kind**: `ui`
- **Family**: Commerce & Pricing
- **Theme**: `light`
- **Mobile Strength**: `native-first`
- **Tags**: `comparison-matrix`, `pricing-table`, `sticky-headers`, `differences-only`, `saas-pricing`, `responsive`
- **Best For**: SaaS tier and enterprise pricing pages, Hardware model and spec comparisons, Insurance, banking, and plan selectors, Security and compliance capability matrices
- **Real-World Inspiration**: [1Password](https://1password.com/)
- **Detail Page**: https://templates.michaelpitts.net/t/feature-comparison-matrix
- **Live Demo**: https://templates.michaelpitts.net/demos/feature-comparison-matrix.html
- **JSON API**: https://templates.michaelpitts.net/api/templates/feature-comparison-matrix

## Why This Aesthetic Is Unique

Eliminates pricing-table eye strain with a 'Differences Only' switch that hides identical rows and a responsive 2-plan selector on 390px mobile that guarantees zero horizontal overflow.

## Color Palette

| Role | Name | Hex |
|------|------|-----|
| `canvas` | Soft Lilac Mist | `#F7F6FB` |
| `surface` | Matrix White | `#FFFFFF` |
| `ink` | Deep Plum Ink | `#1B1632` |
| `accent` | Proton Purple | `#6D4AFF` |
| `muted` | Muted Violet | `#655E7E` |

## Typography

- **Display**: `Inter`
- **Body**: `Inter`
- **Mono**: `JetBrains Mono`
- **Scale Notes**: 24px tabular-nums plan prices, 14px feature labels, 11px uppercase category section dividers.
- **Google Fonts**: https://fonts.googleapis.com/css2?family=Inter:wght@500;600;700&family=JetBrains+Mono:wght@600;700&display=swap
  ```html
  <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@500;600;700&family=JetBrains+Mono:wght@600;700&display=swap">
  ```

## Layout Architecture

Sticky plan header row + 4-tier matrix on desktop; clean 2-plan comparison mode with Plan A / Plan B dropdown pickers on <=768px mobile.

## Interaction & Micro-Motion Rules

Toggling 'Differences Only' hides rows where all visible plans share the exact same value; toggling Annual/Monthly recalculates prices and savings badges live.

## Mobile & Responsive Rules

Replaces cramped 4-column horizontal scrolling with two sticky Plan A / Plan B selectors so buyers can compare any two tiers side-by-side cleanly on a 390px screen.

## Agent Guardrails

### DO
- Include a 'Differences Only' toggle that evaluates differences across the currently visible plans.
- Switch 4-column comparison matrices to a 2-plan picker comparison below 768px.
- Keep plan headers and pricing sticky while scrolling through long feature categories.

### DON'T
- Never force users to horizontally scroll across 4+ pricing columns on a 390px phone.
- Avoid hiding billing-cycle savings; update prices smoothly with tabular numerals.

## Complete Standalone Starter Code

File: `demos/feature-comparison-matrix.html`

```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CipherSuite — Feature Comparison Matrix</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
  :root {
    --bg: #F7F6FC;
    --surface: #FFFFFF;
    --purple: #6D4AFF;
    --purple-dark: #4C2FD6;
    --purple-soft: #F0ECFF;
    --slate-900: #1B1340;
    --slate-600: #554E70;
    --slate-400: #8D87A6;
    --border: rgba(27, 19, 64, 0.1);
    --green: #0D9488;
    --sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  }

  * { box-sizing: border-box; margin: 0; padding: 0; }

  html, body {
    background: var(--bg);
    color: var(--slate-900);
    font-family: var(--sans);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    min-height: 100vh;
  }

  .hero {
    max-width: 1120px;
    margin: 0 auto;
    padding: 36px 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 18px;
  }

  .hero-top {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
  }

  .eyebrow {
    font-size: 0.74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--purple);
    margin-bottom: 6px;
  }

  .hero h1 {
    font-size: clamp(1.65rem, 3vw, 2.3rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.12;
  }

  .hero p {
    font-size: 0.94rem;
    color: var(--slate-600);
    margin-top: 6px;
    max-width: 540px;
  }

  .controls-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 10px 14px;
  }

  .billing-toggle {
    display: inline-flex;
    align-items: center;
    background: var(--bg);
    padding: 4px;
    border-radius: 10px;
    gap: 4px;
  }

  .bill-btn {
    min-height: 40px;
    padding: 0 14px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--slate-600);
    font-family: inherit;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
  }

  .bill-btn.active {
    background: var(--surface);
    color: var(--slate-900);
    box-shadow: 0 1px 4px rgba(27, 19, 64, 0.1);
  }

  .save-pill {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 999px;
    background: #CCFBF1;
    color: #0F766E;
  }

  .diff-toggle {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 0 6px;
    cursor: pointer;
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--slate-900);
    user-select: none;
  }

  .switch {
    position: relative;
    width: 44px;
    height: 24px;
    border-radius: 999px;
    background: #D6D3E5;
    transition: background 0.18s ease;
    flex-shrink: 0;
  }

  .switch::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: transform 0.18s ease;
  }

  .diff-toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
  }

  .diff-toggle input:checked + .switch { background: var(--purple); }
  .diff-toggle input:checked + .switch::after { transform: translateX(20px); }

  /* Mobile 2-Plan Picker */
  .mobile-picker {
    display: none;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px;
  }

  .picker-col {
    display: flex;
    flex-direction: column;
    gap: 5px;
  }

  .picker-col label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--slate-400);
  }

  .picker-col select {
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 0 10px;
    background: var(--bg);
    color: var(--slate-900);
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
  }

  /* Matrix Card */
  .matrix-wrap {
    max-width: 1120px;
    margin: 0 auto 64px;
    padding: 0 20px;
  }

  .matrix-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 12px 32px rgba(27, 19, 64, 0.05);
    overflow: clip;
  }

  table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
  }

  thead th {
    position: sticky;
    top: 0;
    z-index: 15;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 18px 14px 16px;
    vertical-align: top;
    text-align: center;
  }

  thead th:first-child {
    text-align: left;
    width: 30%;
    padding-left: 20px;
    z-index: 20;
    left: 0;
  }

  thead th.recommended {
    background: linear-gradient(180deg, #F5F2FF 0%, #FFFFFF 100%);
  }

  .plan-tag {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--purple);
    color: #fff;
    margin-bottom: 6px;
  }

  .plan-name {
    font-size: 1.04rem;
    font-weight: 700;
    margin-bottom: 4px;
  }

  .plan-price {
    font-size: 1.48rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--slate-900);
  }

  .plan-price small {
    font-size: 0.76rem;
    font-weight: 500;
    color: var(--slate-600);
  }

  .cta-btn {
    margin-top: 10px;
    width: 100%;
    min-height: 44px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--slate-900);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
  }

  .cta-btn:hover { border-color: var(--purple); color: var(--purple); }
  .cta-btn.primary {
    background: var(--purple);
    border-color: var(--purple);
    color: #fff;
  }
  .cta-btn.primary:hover { background: var(--purple-dark); }

  /* Body Rows */
  tr.cat-row td {
    background: #F4F2FA;
    font-size: 0.73rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--purple-dark);
    padding: 10px 20px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
  }

  tbody tr.feat-row td {
    padding: 13px 14px;
    border-bottom: 1px solid rgba(27, 19, 64, 0.06);
    text-align: center;
    font-size: 0.86rem;
    color: var(--slate-900);
    background: var(--surface);
  }

  tbody tr.feat-row td:first-child {
    text-align: left;
    padding-left: 20px;
    font-weight: 500;
    position: sticky;
    left: 0;
    z-index: 5;
  }

  tbody tr.feat-row td.rec-col {
    background: #FAF9FF;
  }

  .feat-sub {
    display: block;
    font-size: 0.74rem;
    font-weight: 400;
    color: var(--slate-400);
    margin-top: 2px;
  }

  .check {
    display: inline-grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--purple-soft);
    color: var(--purple);
    font-weight: 700;
    font-size: 0.82rem;
  }

  .dash {
    color: #C2BDD6;
    font-weight: 600;
  }

  .val-strong {
    font-weight: 600;
    color: var(--slate-900);
  }

  .hidden-row { display: none; }

  .summary-strip {
    padding: 12px 20px;
    background: #FAF9FE;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--slate-600);
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
  }

  @media (max-width: 780px) {
    .hero { padding: 20px 14px 14px; gap: 12px; }
    .controls-bar { padding: 10px 12px; }
    .billing-toggle { width: 100%; }
    .bill-btn { flex: 1; justify-content: center; min-height: 44px; }
    .mobile-picker { display: grid; }
    .matrix-wrap { padding: 0 12px; }

    thead th:first-child { width: 42%; padding-left: 12px; }
    thead th { padding: 12px 8px; }
    .plan-name { font-size: 0.9rem; }
    .plan-price { font-size: 1.15rem; }
    .cta-btn { font-size: 0.76rem; padding: 0 6px; }
    tbody tr.feat-row td { padding: 11px 8px; font-size: 0.8rem; }
    tbody tr.feat-row td:first-child { padding-left: 12px; }
    tr.cat-row td { padding: 9px 12px; }
    .feat-sub { display: none; }
  }
</style>
</head>
<body>

<section class="hero">
  <div class="hero-top">
    <div>
      <div class="eyebrow">CipherSuite Plans &amp; Security Matrix</div>
      <h1>Privacy-first productivity, side by side</h1>
      <p>Compare encrypted storage, custom domains, and compliance controls across every tier. Toggle differences to focus only on what changes.</p>
    </div>
  </div>

  <div class="controls-bar">
    <div class="billing-toggle" role="group" aria-label="Billing interval">
      <button class="bill-btn" data-cycle="monthly" type="button">Monthly</button>
      <button class="bill-btn active" data-cycle="annual" type="button">Annual <span class="save-pill">Save 25%</span></button>
    </div>

    <label class="diff-toggle">
      <input type="checkbox" id="diffCheckbox">
      <span class="switch" aria-hidden="true"></span>
      <span>Differences Only</span>
    </label>
  </div>

  <div class="mobile-picker" aria-label="Choose two plans to compare">
    <div class="picker-col">
      <label for="pickA">Compare Plan A</label>
      <select id="pickA"></select>
    </div>
    <div class="picker-col">
      <label for="pickB">Compare Plan B</label>
      <select id="pickB"></select>
    </div>
  </div>
</section>

<main class="matrix-wrap">
  <div class="matrix-card">
    <table aria-label="Plan feature comparison matrix">
      <thead id="matrixHead"></thead>
      <tbody id="matrixBody"></tbody>
    </table>
    <div class="summary-strip" id="summaryStrip"></div>
  </div>
</main>

<script>
const PLANS = [
  { id: 'free', name: 'Free', monthly: 0, annual: 0, cta: 'Start Free', recommended: false },
  { id: 'plus', name: 'Plus', monthly: 6, annual: 4.5, cta: 'Choose Plus', recommended: false },
  { id: 'unlimited', name: 'Unlimited', monthly: 13, annual: 9.99, cta: 'Get Unlimited', recommended: true },
  { id: 'business', name: 'Business', monthly: 18, annual: 13.5, cta: 'Start Trial', recommended: false }
];

const FEATURES = [
  {
    category: 'Core Encryption & Privacy',
    rows: [
      { label: 'Zero-access E2E encryption', sub: 'Open-source audited cryptography', vals: [true, true, true, true] },
      { label: 'Encrypted cloud storage', sub: 'Shared across Mail, Drive & Calendar', vals: ['5 GB', '25 GB', '500 GB', '1 TB / user'] },
      { label: 'Hardware security keys (FIDO2)', sub: 'YubiKey & passkey protection', vals: [true, true, true, true] },
      { label: 'Dark Web Sentinel alerts', sub: 'Real-time credential leak monitoring', vals: [false, false, true, true] }
    ]
  },
  {
    category: 'Mail, Aliases & Domains',
    rows: [
      { label: 'Custom email domains', sub: 'Use your own @company.com', vals: [false, '1 domain', '3 domains', '10 domains'] },
      { label: 'Hide-my-email aliases', sub: 'Unique forwarding addresses', vals: ['10', '25', 'Unlimited', 'Unlimited'] },
      { label: 'Encrypted desktop & mobile apps', sub: 'macOS, Windows, Linux, iOS, Android', vals: [true, true, true, true] },
      { label: 'Priority catch-all routing', sub: 'Route unmatched domain addresses', vals: [false, false, true, true] }
    ]
  },
  {
    category: 'Team & Compliance',
    rows: [
      { label: 'Dedicated VPN gateways', sub: '10 Gbps high-speed encrypted routes', vals: ['1 device', '2 devices', '10 devices', 'Unlimited'] },
      { label: 'SAML SSO & SCIM provisioning', sub: 'Okta, Entra ID & Google Workspace', vals: [false, false, false, true] },
      { label: 'Audit logs & retention policies', sub: 'Exportable SIEM activity stream', vals: [false, false, false, true] },
      { label: '24/7 Priority support SLA', sub: 'Under 2-hour response guarantee', vals: [false, false, 'Priority', '24/7 SLA'] }
    ]
  }
];

let billing = 'annual';
let diffOnly = false;
let mobilePair = [1, 2]; // Plus vs Unlimited on mobile
let selectedPlanToast = null;

const matrixHead = document.getElementById('matrixHead');
const matrixBody = document.getElementById('matrixBody');
const summaryStrip = document.getElementById('summaryStrip');
const pickA = document.getElementById('pickA');
const pickB = document.getElementById('pickB');

function isMobile() {
  return window.innerWidth <= 780;
}

function getVisibleIndices() {
  return isMobile() ? mobilePair : [0, 1, 2, 3];
}

function formatCell(v) {
  if (v === true) return '<span class="check" aria-label="Included">✓</span>';
  if (v === false) return '<span class="dash" aria-label="Not included">—</span>';
  return `<span class="val-strong">${v}</span>`;
}

function populatePickers() {
  [pickA, pickB].forEach((sel, idx) => {
    sel.innerHTML = PLANS.map((p, i) => `<option value="${i}" ${mobilePair[idx] === i ? 'selected' : ''}>${p.name}</option>`).join('');
  });
}

function renderMatrix() {
  const cols = getVisibleIndices();

  // Header
  let headHtml = '<tr><th><span style="font-size:0.8rem;color:var(--slate-400);font-weight:600;text-transform:uppercase;letter-spacing:0.08em">Features</span></th>';
  cols.forEach(ci => {
    const p = PLANS[ci];
    const price = billing === 'annual' ? p.annual : p.monthly;
    const priceStr = price === 0 ? '$0' : `$${price % 1 === 0 ? price : price.toFixed(2)}`;
    headHtml += `
      <th class="${p.recommended ? 'recommended' : ''}">
        ${p.recommended ? '<span class="plan-tag">Most Popular</span>' : ''}
        <div class="plan-name">${p.name}</div>
        <div class="plan-price">${priceStr}<small>/mo</small></div>
        <button class="cta-btn ${p.recommended ? 'primary' : ''}" data-plan="${p.name}" type="button">${p.cta}</button>
      </th>
    `;
  });
  headHtml += '</tr>';
  matrixHead.innerHTML = headHtml;

  // Body
  let bodyHtml = '';
  let totalRows = 0;
  let visibleRows = 0;

  FEATURES.forEach(group => {
    const groupRowsHtml = [];
    group.rows.forEach(row => {
      totalRows++;
      const shownVals = cols.map(ci => row.vals[ci]);
      const allSame = shownVals.every(v => v === shownVals[0]);
      if (diffOnly && allSame) return;

      visibleRows++;
      let rowHtml = `<tr class="feat-row"><td>${row.label}<span class="feat-sub">${row.sub}</span></td>`;
      cols.forEach(ci => {
        rowHtml += `<td class="${PLANS[ci].recommended ? 'rec-col' : ''}">${formatCell(row.vals[ci])}</td>`;
      });
      rowHtml += '</tr>';
      groupRowsHtml.push(rowHtml);
    });

    if (groupRowsHtml.length > 0) {
      bodyHtml += `<tr class="cat-row"><td colspan="${cols.length + 1}">${group.category}</td></tr>`;
      bodyHtml += groupRowsHtml.join('');
    }
  });

  if (visibleRows === 0) {
    bodyHtml = `<tr><td colspan="${cols.length + 1}" style="padding:36px 20px;text-align:center;color:var(--slate-600)">Selected plans have identical features across every row. Pick two different plans to compare.</td></tr>`;
  }

  matrixBody.innerHTML = bodyHtml;

  summaryStrip.innerHTML = `
    <span>Showing <strong>${visibleRows}</strong> of ${totalRows} capabilities${diffOnly ? ' (identical rows hidden)' : ''}</span>
    <span id="ctaFeedback">${selectedPlanToast || (billing === 'annual' ? 'Billed annually · 30-day money-back guarantee' : 'Billed monthly · Cancel anytime')}</span>
  `;

  matrixHead.querySelectorAll('.cta-btn').forEach(btn => {
    btn.addEventListener('click', () => {
      selectedPlanToast = `Selected ${btn.dataset.plan} (${billing}) — ready for checkout`;
      document.getElementById('ctaFeedback').textContent = selectedPlanToast;
    });
  });
}

document.querySelectorAll('.bill-btn').forEach(btn => {
  btn.addEventListener('click', () => {
    billing = btn.dataset.cycle;
    document.querySelectorAll('.bill-btn').forEach(b => b.classList.toggle('active', b === btn));
    renderMatrix();
  });
});

document.getElementById('diffCheckbox').addEventListener('change', (e) => {
  diffOnly = e.target.checked;
  renderMatrix();
});

pickA.addEventListener('change', () => {
  mobilePair[0] = parseInt(pickA.value, 10);
  renderMatrix();
});

pickB.addEventListener('change', () => {
  mobilePair[1] = parseInt(pickB.value, 10);
  renderMatrix();
});

let resizeTimer = null;
window.addEventListener('resize', () => {
  clearTimeout(resizeTimer);
  resizeTimer = setTimeout(renderMatrix, 120);
});

populatePickers();
renderMatrix();
</script>
</body>
</html>
```
