Product Color Swatches
Color swatches highlight on hover and update the selected product color when chosen.
Color swatches highlight on hover and update the selected product color when chosen.
Live Demo
Hover over the element or use Tab to focus.
Source Code
Copy the HTML, CSS or JavaScript you need for your project.
<fieldset class="tbx-1044"><legend>Available colors</legend><div class="tbx-1044__product" aria-hidden="true"><span class="tbx-1044__shape"></span></div><div class="tbx-1044__options"><label><input type="radio" name="tbx-1044-color" value="slate" checked><span class="tbx-1044__dot tbx-1044__dot--slate" title="Slate"></span></label><label><input type="radio" name="tbx-1044-color" value="clay"><span class="tbx-1044__dot tbx-1044__dot--clay" title="Terracotta"></span></label><label><input type="radio" name="tbx-1044-color" value="sage"><span class="tbx-1044__dot tbx-1044__dot--sage" title="Sage"></span></label></div></fieldset>
.tbx-1044{--item:#60768d;display:flex;flex-direction:column;align-items:center;gap:11px;border:0;margin:0;padding:0;font-family:system-ui}
.tbx-1044 legend{text-align:center;margin:0 0 4px;font-size:10px;color:#76869a;font-weight:700}
.tbx-1044:has(input[value=clay]:checked){--item:#cc7855}.tbx-1044:has(input[value=sage]:checked){--item:#7d9977}
.tbx-1044__product{display:grid;place-items:center;width:186px;height:105px;border-radius:10px;background:#e9eef1}
.tbx-1044__shape{position:relative;width:92px;height:69px;background:var(--item);border-radius:16px 16px 12px 12px;transform:rotate(-8deg);transition:background .3s,transform .3s;box-shadow:12px 8px 0 #a1b8c24a}
.tbx-1044__shape:before{content:"";position:absolute;inset:12px 19px 24px;border-radius:10px 10px 1px 1px;border:8px solid #e9eef1;border-bottom:0}
.tbx-1044__shape:after{content:"";position:absolute;left:-5px;right:-5px;bottom:0;height:12px;background:#e3e9ec;border-radius:4px 4px 10px 10px}
.tbx-1044__options{display:flex;gap:13px;justify-content:center}.tbx-1044__options label{position:relative;cursor:pointer;display:block}.tbx-1044 input{position:absolute;opacity:0;width:100%;height:100%;margin:0}
.tbx-1044__dot{display:block;width:22px;height:22px;border-radius:50%;outline:2px solid transparent;outline-offset:3px;transition:transform .2s,outline-color .2s}.tbx-1044__dot--slate{background:#60768d}.tbx-1044__dot--clay{background:#cc7855}.tbx-1044__dot--sage{background:#7d9977}
.tbx-1044 label:is(:hover,:focus-within) .tbx-1044__dot{transform:scale(1.16)}
.tbx-1044 input:checked+.tbx-1044__dot{outline-color:#354b61}.tbx-1044 input:focus-visible+.tbx-1044__dot{box-shadow:0 0 0 5px #dfa55e}
@media(prefers-reduced-motion:reduce){.tbx-1044__shape,.tbx-1044__dot{transition:none}}
How to Use
Insert the HTML and add the CSS to your stylesheet. Adjust colors and sizes and avoid class conflicts.
Use Case
Useful for ec sections and product showcases.
Technical Notes
Keep controls usable on touch devices. Test keyboard focus and reduced-motion preferences.
Mobile: Ensure the interactive content remains accessible without hover on touch devices.
Browser: Uses modern CSS. Check behavior in the browsers you support.
Reduced Motion: Check that prefers-reduced-motion is respected.