A color in context

A native checkbox changes the backgrounds of two identical color samples. The squares keep the same color, size, and position throughout. No JavaScript or account is needed; reloading resets the experiment.

Compare, then remove the context

<figure class="color-context" data-pmx-prose="off">
  <div class="color-context-pair" role="img" aria-label="Two coral squares of equal size, one on each side. Compare their appearance, then use the checkbox to give them matching backgrounds.">
    <div class="color-context-ground color-context-ground-dark"><span class="color-context-swatch"></span></div>
    <div class="color-context-ground color-context-ground-light"><span class="color-context-swatch"></span></div>
  </div>
  <label class="color-context-control">
    <input type="checkbox" data-pmx-play-affordance />
    <span>Put both squares on the same background</span>
  </label>
  <figcaption>Only the backgrounds change. Look back at the squares as you toggle.</figcaption>
</figure>
.color-context {
  margin: 1.5rem 0;
  width: 100%;
  max-width: 46rem;
}
.color-context-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border-radius: var(--pmx-radius-md, 0.75rem);
}
.color-context-ground {
  display: grid;
  place-items: center;
  aspect-ratio: 1.2;
  padding: 0;
}
.color-context-ground-dark { background: #183c43; }
.color-context-ground-light { background: #f5dec1; }
.color-context-swatch {
  display: block;
  width: 32%;
  aspect-ratio: 1;
  background: #e78c70;
}
.color-context:has(input:checked) .color-context-ground {
  background: #bcb7ae;
}
.color-context-control {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 3rem;
  padding: 0.75rem 0;
  cursor: pointer;
  font-size: 0.9375rem;
  line-height: 1.5;
}
.color-context-control input {
  flex: none;
  width: 1.125rem;
  height: 1.125rem;
  margin: 0;
  accent-color: var(--pmx-color-accent);
}
.color-context-control:focus-within {
  outline: 2px solid var(--pmx-color-focus);
  outline-offset: 3px;
  border-radius: var(--pmx-radius-sm);
}
.color-context figcaption {
  margin: 0;
  color: var(--pmx-color-muted);
  font-size: 0.875rem;
  line-height: 1.5;
}

Use it in a lesson:

[@experiment]: ./color-context.components.md

<color-context-experiment />