Component Library

← Back to gallery

Reference code error panel in HTML, CSS and vanilla JS

A copy-paste Reference code error panel in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.

Category: Feedback · Tags: error, reference, support, disclosure

Live preview

Source (copy-ready)

<section class="dcl-error-reference-panel" data-dcl-scheme="light" aria-label="Reference code error panel example">
<div data-split>
  <div data-stack><span data-chip>Export stopped</span><h2>Approval report wasn't generated</h2><p>Give your workspace administrator this reference to check the failed job.</p></div>
  <div data-stack data-well><strong>Reference <code>EX-482</code></strong><details><summary>Read diagnostic context</summary><p>The template was unavailable before export began.</p></details></div>
</div>
<script>
(() => {
  const root = document.currentScript.closest(".dcl-error-reference-panel");
  const preference = matchMedia("(prefers-color-scheme: dark)");
  const setTheme = () => { root.dataset.dclScheme = preference.matches ? "dark" : "light"; };
  preference.addEventListener("change", setTheme);
  setTheme();
})();
</script>
</section>
<style>
.dcl-error-reference-panel, .dcl-error-reference-panel * { box-sizing: border-box; }
.dcl-error-reference-panel { 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-error-reference-panel :where(h2, h3, p, ol, ul, dl, dd) { margin: 0; }
.dcl-error-reference-panel h2 { font-size: 1.25rem; line-height: 1.25; }
.dcl-error-reference-panel h3 { font-size: 1rem; }
.dcl-error-reference-panel p + p { margin-block-start: 0.5rem; }
.dcl-error-reference-panel [data-stack], .dcl-error-reference-panel form { display: grid; gap: 0.75rem; }
.dcl-error-reference-panel [data-row] { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; }
.dcl-error-reference-panel [data-split] { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: 0.75rem 1.25rem; align-items: start; }
.dcl-error-reference-panel [data-spread] { justify-content: space-between; }
.dcl-error-reference-panel [hidden] { display: none !important; }
.dcl-error-reference-panel [data-well] { padding: 0.75rem; border-radius: 0.375rem; }
.dcl-error-reference-panel [data-chip] { display: inline-block; width: fit-content; padding: 0.125rem 0.55rem; border-radius: 99rem; font-size: 0.875rem; font-weight: 700; }
.dcl-error-reference-panel :where(button, summary, input, select) { font: inherit; }
.dcl-error-reference-panel :where(button, input, select) { min-block-size: 44px; min-inline-size: 0; max-inline-size: 100%; }
.dcl-error-reference-panel :where(button, input, select) { border: 1px solid; border-radius: 0.375rem; padding: 0.45rem 0.7rem; }
.dcl-error-reference-panel :where(button, summary) { cursor: pointer; font-weight: 650; }
.dcl-error-reference-panel :where(button, summary):active { box-shadow: inset 0 0 0 2px currentColor; }
.dcl-error-reference-panel summary:hover { text-decoration: underline; }
.dcl-error-reference-panel :where(button, input, select):disabled, .dcl-error-reference-panel [aria-disabled=true] { cursor: not-allowed; border-style: dashed; }
.dcl-error-reference-panel label { display: grid; gap: 0.25rem; }
.dcl-error-reference-panel :where(input, select) { inline-size: 100%; }
.dcl-error-reference-panel label[data-choice] { display: flex; gap: 0.5rem; align-items: center; min-block-size: 44px; }
.dcl-error-reference-panel label[data-choice] input { inline-size: 1.25rem; block-size: 1.25rem; min-block-size: 0; flex-shrink: 0; }
.dcl-error-reference-panel fieldset { min-inline-size: 0; margin: 0; border-radius: 0.375rem; padding: 0.5rem 0.75rem; }
.dcl-error-reference-panel :focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }
.dcl-error-reference-panel[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 2px; }
.dcl-error-reference-panel { color-scheme: light; border-color: #697f84; }
.dcl-error-reference-panel { color: #11292f; background-color: #ffffff; }
.dcl-error-reference-panel [data-well], .dcl-error-reference-panel [data-chip] { color: #11292f; background-color: #e4edef; }
.dcl-error-reference-panel button, .dcl-error-reference-panel input, .dcl-error-reference-panel select { color: #11292f; background-color: #e4edef; }
.dcl-error-reference-panel button[data-primary] { color: #ffffff; background-color: #00535a; }
.dcl-error-reference-panel button:hover { color: #ffffff; background-color: #003c42; }
.dcl-error-reference-panel button[disabled], .dcl-error-reference-panel button[aria-disabled=true] { color: #405a60; background-color: #e4edef; }
.dcl-error-reference-panel[data-dcl-scheme="dark"] { color-scheme: dark; border-color: #839fa5; }
.dcl-error-reference-panel[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; }
.dcl-error-reference-panel[data-dcl-scheme="dark"] [data-well], .dcl-error-reference-panel[data-dcl-scheme="dark"] [data-chip] { color: #eff8f9; background-color: #1c3c44; }
.dcl-error-reference-panel[data-dcl-scheme="dark"] button, .dcl-error-reference-panel[data-dcl-scheme="dark"] input, .dcl-error-reference-panel[data-dcl-scheme="dark"] select { color: #eff8f9; background-color: #1c3c44; }
.dcl-error-reference-panel[data-dcl-scheme="dark"] button[data-primary] { color: #11292f; background-color: #8fe1da; }
.dcl-error-reference-panel[data-dcl-scheme="dark"] button:hover { color: #11292f; background-color: #b2f2ec; }
.dcl-error-reference-panel[data-dcl-scheme="dark"] button[disabled], .dcl-error-reference-panel[data-dcl-scheme="dark"] button[aria-disabled=true] { color: #b0c9ce; background-color: #1c3c44; }
</style>

When to use

Put a support reference next to an error when recovery depends on a person diagnosing it.

Avoid

Do not expose stack traces, account data, or secrets in the diagnostic details.

Accessibility

The reference is rendered as text that can be selected without scripting. Native details keeps technical context optional. Text contrast is at least 6.1:1 in light and 6.7:1 in dark.

Was this useful? Send feedback.