Component Library

← Back to gallery

Edit conflict alert in HTML, CSS and vanilla JS

A copy-paste Edit conflict alert in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.

Category: Feedback · Tags: alert, conflict, recovery, comparison

Live preview

Source (copy-ready)

<section class="dcl-alert-conflict-comparison" data-dcl-scheme="light" aria-label="Edit conflict alert example">
<div data-stack>
  <div data-row><span data-chip>Save blocked</span><h2>Two changes to the delivery date</h2></div>
  <div data-split>
    <div data-well><h3>Your draft</h3><p>Fri, 27 Nov</p></div>
    <div data-well><h3>Current version</h3><p>Mon, 30 Nov</p></div>
  </div>
  <div data-row><button type="button" data-value="Draft date selected." data-primary>Keep my date</button><button type="button" data-value="Current date selected.">Use current date</button></div>
  <p role="status">No date selected.</p>
</div>
<script>
(() => {
  const root = document.currentScript.closest(".dcl-alert-conflict-comparison");
  const preference = matchMedia("(prefers-color-scheme: dark)");
  const setTheme = () => { root.dataset.dclScheme = preference.matches ? "dark" : "light"; };
  preference.addEventListener("change", setTheme);
  setTheme();
  const find = (selector) => root.querySelector(selector);
  const all = (selector) => Array.from(root.querySelectorAll(selector));
  all("[data-value]").forEach((button) => button.addEventListener("click", () => {
    find('[role="status"]').textContent = button.dataset.value;
  }));
})();
</script>
</section>
<style>
.dcl-alert-conflict-comparison, .dcl-alert-conflict-comparison * { box-sizing: border-box; }
.dcl-alert-conflict-comparison { font: 1rem/1.5 system-ui, sans-serif; max-inline-size: 40rem; padding: clamp(0.75rem, 3vw, 1.25rem); border: 1px solid; border-radius: 0.75rem; overflow-wrap: anywhere; }
.dcl-alert-conflict-comparison :where(h2, h3, p, ol, ul, dl, dd) { margin: 0; }
.dcl-alert-conflict-comparison h2 { font-size: 1.25rem; line-height: 1.25; }
.dcl-alert-conflict-comparison h3 { font-size: 1rem; }
.dcl-alert-conflict-comparison p + p { margin-block-start: 0.5rem; }
.dcl-alert-conflict-comparison [data-stack], .dcl-alert-conflict-comparison form { display: grid; gap: 0.75rem; }
.dcl-alert-conflict-comparison [data-row] { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; }
.dcl-alert-conflict-comparison [data-split] { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: 0.75rem 1.25rem; align-items: start; }
.dcl-alert-conflict-comparison [data-spread] { justify-content: space-between; }
.dcl-alert-conflict-comparison [hidden] { display: none !important; }
.dcl-alert-conflict-comparison [data-well] { padding: 0.75rem; border-radius: 0.375rem; }
.dcl-alert-conflict-comparison [data-chip] { display: inline-block; width: fit-content; padding: 0.125rem 0.55rem; border-radius: 99rem; font-size: 0.875rem; font-weight: 700; }
.dcl-alert-conflict-comparison :where(button, summary, input, select) { font: inherit; }
.dcl-alert-conflict-comparison :where(button, input, select) { min-block-size: 44px; min-inline-size: 0; max-inline-size: 100%; }
.dcl-alert-conflict-comparison :where(button, input, select) { border: 1px solid; border-radius: 0.375rem; padding: 0.45rem 0.7rem; }
.dcl-alert-conflict-comparison :where(button, summary) { cursor: pointer; font-weight: 650; }
.dcl-alert-conflict-comparison :where(button, summary):active { box-shadow: inset 0 0 0 2px currentColor; }
.dcl-alert-conflict-comparison summary:hover { text-decoration: underline; }
.dcl-alert-conflict-comparison :where(button, input, select):disabled, .dcl-alert-conflict-comparison [aria-disabled=true] { cursor: not-allowed; border-style: dashed; }
.dcl-alert-conflict-comparison label { display: grid; gap: 0.25rem; }
.dcl-alert-conflict-comparison :where(input, select) { inline-size: 100%; }
.dcl-alert-conflict-comparison label[data-choice] { display: flex; gap: 0.5rem; align-items: center; min-block-size: 44px; }
.dcl-alert-conflict-comparison label[data-choice] input { inline-size: 1.25rem; block-size: 1.25rem; min-block-size: 0; flex-shrink: 0; }
.dcl-alert-conflict-comparison fieldset { min-inline-size: 0; margin: 0; border-radius: 0.375rem; padding: 0.5rem 0.75rem; }
.dcl-alert-conflict-comparison :focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }
.dcl-alert-conflict-comparison[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 2px; }
.dcl-alert-conflict-comparison { color-scheme: light; border-color: #697f84; }
.dcl-alert-conflict-comparison { color: #11292f; background-color: #ffffff; }
.dcl-alert-conflict-comparison [data-well], .dcl-alert-conflict-comparison [data-chip] { color: #11292f; background-color: #e4edef; }
.dcl-alert-conflict-comparison button, .dcl-alert-conflict-comparison input, .dcl-alert-conflict-comparison select { color: #11292f; background-color: #e4edef; }
.dcl-alert-conflict-comparison button[data-primary] { color: #ffffff; background-color: #00535a; }
.dcl-alert-conflict-comparison button:hover { color: #ffffff; background-color: #003c42; }
.dcl-alert-conflict-comparison button[disabled], .dcl-alert-conflict-comparison button[aria-disabled=true] { color: #405a60; background-color: #e4edef; }
.dcl-alert-conflict-comparison[data-dcl-scheme="dark"] { color-scheme: dark; border-color: #839fa5; }
.dcl-alert-conflict-comparison[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; }
.dcl-alert-conflict-comparison[data-dcl-scheme="dark"] [data-well], .dcl-alert-conflict-comparison[data-dcl-scheme="dark"] [data-chip] { color: #eff8f9; background-color: #1c3c44; }
.dcl-alert-conflict-comparison[data-dcl-scheme="dark"] button, .dcl-alert-conflict-comparison[data-dcl-scheme="dark"] input, .dcl-alert-conflict-comparison[data-dcl-scheme="dark"] select { color: #eff8f9; background-color: #1c3c44; }
.dcl-alert-conflict-comparison[data-dcl-scheme="dark"] button[data-primary] { color: #11292f; background-color: #8fe1da; }
.dcl-alert-conflict-comparison[data-dcl-scheme="dark"] button:hover { color: #11292f; background-color: #b2f2ec; }
.dcl-alert-conflict-comparison[data-dcl-scheme="dark"] button[disabled], .dcl-alert-conflict-comparison[data-dcl-scheme="dark"] button[aria-disabled=true] { color: #b0c9ce; background-color: #1c3c44; }
</style>

When to use

Place this before saving when a teammate edited the same field. List the conflicting values before the person chooses.

Avoid

Do not overwrite either version automatically on opening a conflict.

Accessibility

The compared values are headed and actions use native buttons. The result is announced without moving focus. Text contrast is at least 6.1:1 in light and 6.7:1 in dark.

Was this useful? Send feedback.