Basic Controls and Selectors

Loft Control Deck Color Swatches

Complete color swatch selection in the loft control console scenario: includes real content, interactive controls, clear status feedback, and responsive layouts across sizes.

Basic Controls and SelectorsColor Sample SelectionHTMLCSSJavaScript
With JavaScript enabled, you can edit, run, and save this example. The fixed source is as follows:
<!doctype html>
<html lang="en" dir="ltr">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Loft Control Deck Color Swatches</title>
  <style>
    :root { --ink:#3a2419; --paper:#fbf3df; --accent:#c66a2d; --secondary:#b5c88d; --line:color-mix(in srgb, var(--ink) 18%, transparent); --shadow:0 24px 60px color-mix(in srgb, var(--ink) 16%, transparent); color-scheme:light; }
    * { box-sizing:border-box; }
    html { min-width:320px; background:var(--paper); }
    body { min-height:100vh; margin:0; overflow-x:hidden; color:var(--ink); font-family:"IBM Plex Sans","PingFang SC",sans-serif; background:linear-gradient(color-mix(in srgb,var(--ink) 5%,transparent) 1px,transparent 1px),var(--paper);background-size:100% 36px; }
    button,input,select,textarea { color:inherit; font:inherit; }
    button,[role="button"],input,select,textarea { accent-color:var(--accent); }
    button { cursor:pointer; }
    button:focus-visible,input:focus-visible,select:focus-visible,textarea:focus-visible,[tabindex]:focus-visible { outline:3px solid var(--accent); outline-offset:3px; }
    [hidden] { display:none !important; }
    @media (max-width:700px) { .mast h1 { line-height:1.08 !important; letter-spacing:-.035em !important; overflow-wrap:anywhere; } }
    @media (prefers-reduced-motion:reduce) { *,*::before,*::after { scroll-behavior:auto !important; animation-duration:.01ms !important; animation-iteration-count:1 !important; transition-duration:.01ms !important; } }
    .page{width:min(1280px,calc(100% - 24px));margin:auto;padding:28px 0 64px}.mast{display:flex;justify-content:space-between;padding:18px;border:1px solid var(--line);background:color-mix(in srgb,#fff 60%,transparent);gap:18px;margin-bottom:14px}.mast h1{font-family:"IBM Plex Sans","PingFang SC",sans-serif;font-weight:800;font-size:clamp(34px,6vw,66px);letter-spacing:-.045em;margin:0;line-height:1}.eyebrow{display:block;margin-bottom:6px;color:var(--accent);font:800 10px/1 ui-monospace,monospace;letter-spacing:.16em}.intro{max-width:720px;margin:10px 0 0;font-size:14px;line-height:1.6}.scenario{padding:7px 10px;border:1px solid var(--line);border-radius:8px;background:var(--paper);font-size:12px}.demo{border-radius:14px;box-shadow:0 14px 40px color-mix(in srgb,var(--ink) 11%,transparent);position:relative;min-height:390px;overflow:hidden;padding:24px;background:color-mix(in srgb,var(--paper) 90%,#fff)}@media(max-width:700px){.page{width:calc(100% - 12px);padding-top:12px}.mast{display:grid}.demo{padding:12px}}
    .panel{padding:16px;border:3px double var(--accent);background:var(--paper)}.stack{display:grid;gap:14px}.row{display:grid;grid-auto-flow:column;grid-auto-columns:max-content;gap:10px;overflow:auto}.action{padding:10px 15px;border:1px solid var(--accent);background:transparent;font-family:Didot,serif;letter-spacing:.06em}.action.primary,.action.is-active{color:var(--paper);background:var(--ink)}.metric{font-family:Didot,serif;font-size:clamp(36px,8vw,74px);letter-spacing:.04em}.status{min-height:24px;padding:9px;border-inline:1px solid var(--accent);text-align:center}.muted{line-height:1.8}.chip{padding:5px 14px;border-inline:1px solid var(--accent);letter-spacing:.1em}.meter{height:5px;background:var(--line)}.meter>i{display:block;height:100%;background:linear-gradient(90deg,var(--accent),var(--secondary))}
    .composition-split{display:grid;grid-template-columns:150px minmax(0,1fr);gap:18px;align-items:start}.split-note{position:sticky;top:20px;display:grid;gap:14px;padding:18px 12px;border-block:3px double var(--accent);font-size:13px;line-height:1.65}.split-note b{font:900 12px/1 ui-monospace,monospace;letter-spacing:.12em}.split-note span{writing-mode:vertical-rl;min-height:120px;color:color-mix(in srgb,var(--ink) 60%,transparent)}.composition-split .demo{min-width:0}@media(max-width:900px){.composition-split{grid-template-columns:1fr}.split-note{position:static;grid-template-columns:auto 1fr}.split-note span{writing-mode:horizontal-tb;min-height:0}}
    .swatch-studio{display:grid;gap:18px}.swatch-studio header{display:flex;justify-content:space-between;gap:18px;align-items:end}.swatch-studio h2{margin:.2em 0}.swatch-studio-grid{display:grid;grid-template-columns:minmax(0,1.05fr) minmax(250px,.95fr);gap:18px}.swatch-rail{display:grid;gap:10px;padding:18px;border:1px solid var(--line);border-radius:22px;background:var(--paper)}.swatch-rail legend{padding:0 8px;font-weight:900}.swatch-rail label{position:relative}.swatch-rail input{position:absolute;opacity:0}.swatch-rail span{display:grid;grid-template-columns:64px 1fr auto;gap:12px;align-items:center;padding:12px;border:1px solid var(--line);border-radius:16px}.swatch-rail i{height:54px;border-radius:12px;background:var(--swatch)}.swatch-rail input:checked+span{border:3px solid var(--ink);padding:10px}.swatch-rail input:focus-visible+span{outline:3px solid var(--accent);outline-offset:3px}.swatch-inspector{display:grid;align-content:start;gap:14px;min-height:340px;padding:28px;border-radius:28px;color:#fff;background:linear-gradient(150deg,var(--chosen),color-mix(in srgb,var(--chosen) 42%,#09121f))}.swatch-inspector strong{font-size:clamp(38px,7vw,76px)}.swatch-inspector ul{display:grid;gap:8px;padding:0;margin:0;list-style:none}.swatch-inspector li{padding:10px 12px;border:1px solid #ffffff33;border-radius:12px;background:#ffffff14}.swatch-inspector button{justify-self:start;padding:11px 17px;border:0;border-radius:999px;color:var(--chosen);background:#fff;font-weight:900}@media(max-width:720px){.swatch-studio header{align-items:stretch;flex-direction:column}.swatch-studio-grid{grid-template-columns:1fr}}.workflow-spatial{display:grid;gap:16px}.workflow-spatial>header{display:grid;grid-template-columns:1fr minmax(170px,.35fr) minmax(170px,.35fr);gap:18px;align-items:end;padding-bottom:16px;border-bottom:5px solid var(--ink)}.workflow-spatial h2{margin:.2em 0}.workflow-spatial header label{display:grid;grid-template-columns:1fr auto;gap:7px}.workflow-spatial header input{grid-column:1/-1;width:100%}.spatial-grid{display:grid;grid-template-columns:minmax(0,var(--spatial-width)) 20px minmax(180px,1fr);gap:0;align-items:stretch}.spatial-core{min-width:0;transform:scale(var(--spatial-zoom));transform-origin:top left;transition:transform .2s}.spatial-handle{display:grid;min-height:300px;place-items:center;border:0;border-inline:1px dashed var(--accent);background:color-mix(in srgb,var(--accent) 10%,transparent);cursor:col-resize}.spatial-grid>aside{display:grid;align-content:center;gap:14px;padding:22px;background:color-mix(in srgb,var(--secondary) 14%,var(--paper))}.spatial-grid>aside strong{font-size:clamp(24px,4vw,42px)}@media(max-width:900px){.workflow-spatial>header{grid-template-columns:1fr}.spatial-grid{order:-1;grid-template-columns:1fr}.spatial-handle{min-height:44px;cursor:row-resize}.spatial-core{transform:none}}
  </style>
</head>
<body data-aesthetic="dashboard" data-composition="split-note">
  <main class="page">
    <header class="mast"><div><span class="eyebrow">dashboard / color swatch selection / BEGINNER</span><h1>Loft Control Deck Color Swatches</h1><p class="intro">Complete color swatch selection in the loft control console scenario: includes real content, interactive controls, clear status feedback, and responsive layouts across sizes.</p></div><span class="scenario">Loft Control Console</span></header>
    <div class="composition-split"><aside class="split-note"><b>CASE 02</b><span>Master the semantic structure, responsive arrangement, keyboard operation, and state synchronization of color swatch selection.</span></aside><section class="demo" aria-label="Loft Console color swatch interaction area"><div id="workflowSpatial" class="workflow-spatial" style="--spatial-width:64%;--spatial-zoom:1"><header><div><span class="eyebrow">Loft control deck SPATIAL CANVAS</span><h2>Loft Control Deck</h2></div><label>Device Load Share<input id="workflowSpatialWidth" type="range" min="38" max="82" value="64"><output id="workflowSpatialWidthValue">64%</output></label><label>Content Scaling<input id="workflowSpatialZoom" type="range" min="80" max="120" value="100"><output id="workflowSpatialZoomValue">100%</output></label></header><div class="spatial-grid"><section id="workflowCore" class="workflow-core spatial-core"><!-- 11DZ_CORE_START:controls-selectors-color-swatches --><section class="swatch-studio"><header><div><span class="eyebrow">COLOR SWATCHES</span><h2>Loft Console Color Palette</h2><p>Put swatches, contrast cues, and recommended uses into one control panel.</p></div><output id="swatchContrast">Current contrast: High</output></header><div class="swatch-studio-grid"><fieldset class="swatch-rail"><legend>Choose theme color</legend><label style="--swatch:#1f9d8a"><input type="radio" name="themeColor" value="#1f9d8a" data-color-index="0" checked data-core-bridge="controls-selectors-color-swatches"><span><i aria-hidden="true"></i><b>Turquoise</b><small>#1f9d8a</small></span></label><label style="--swatch:#e5673f"><input type="radio" name="themeColor" value="#e5673f" data-color-index="1"><span><i aria-hidden="true"></i><b>Sunset</b><small>#e5673f</small></span></label><label style="--swatch:#4b5cc4"><input type="radio" name="themeColor" value="#4b5cc4" data-color-index="2"><span><i aria-hidden="true"></i><b>Indigo</b><small>#4b5cc4</small></span></label><label style="--swatch:#d39a27"><input type="radio" name="themeColor" value="#d39a27" data-color-index="3"><span><i aria-hidden="true"></i><b>Golden Sand</b><small>#d39a27</small></span></label><label style="--swatch:#a94268"><input type="radio" name="themeColor" value="#a94268" data-color-index="4"><span><i aria-hidden="true"></i><b>Berry</b><small>#a94268</small></span></label></fieldset><aside id="swatchPreview" class="swatch-inspector" style="--chosen:#1f9d8a"><span>THEME BOARD</span><strong id="swatchName">Turquoise</strong><p id="swatchHex">#1f9d8a</p><ul id="swatchChecklist"><li>title button</li><li>Hint tags</li><li>Data Focus</li></ul><button type="button">Apply Current Theme</button></aside></div></section><!-- 11DZ_CORE_END --></section><input id="workflowSpatialHandle" class="spatial-handle" type="button" value="↔" aria-label="Drag to adjust the main case preview width"><aside><strong>Loft control deck manual mode</strong><p>The smart mode and linked mode of the loft console will be reflowed according to the canvas size.</p><output id="workflowSpatialStatus">Width 64%, zoom 100%</output><input id="workflowSpatialApply" class="action primary" type="button" value="Application scenarios"></aside></div></div><p id="status" class="status" role="status" aria-live="polite"></p></section></div>
  </main>
  <script>
    'use strict';
    const statusOutput = document.querySelector('#status');
    const announce = message => { statusOutput.textContent = message; };
    /* 11DZ_CORE_SCRIPT_START:controls-selectors-color-swatches */
const swatchInputs=[...document.querySelectorAll('input[name="themeColor"]')];const swatchPreview=document.querySelector('#swatchPreview');const swatchName=document.querySelector('#swatchName');const swatchHex=document.querySelector('#swatchHex');const swatchContrast=document.querySelector('#swatchContrast');const swatchChecklist=document.querySelector('#swatchChecklist');const swatchLabel=input=>input.closest('label').querySelector('b').textContent;function renderSwatchInspector(input){const color=input.value;const name=swatchLabel(input);const contrast=['High','middle','High','middle','High'][swatchInputs.indexOf(input)]||'High';swatchPreview.style.setProperty('--chosen',color);swatchName.textContent=name;swatchHex.textContent=color.toUpperCase();swatchContrast.textContent='Current comparison:'+contrast;swatchChecklist.replaceChildren(...['title button','Hint tags','Data Focus'].map((label,index)=>{const item=document.createElement('li');item.textContent=name+' · '+label+' · '+['Primary','Auxiliary use','Accent'][index];return item;}));announce('Primary color switched to '+name);}swatchInputs.forEach(input=>input.addEventListener('change',()=>renderSwatchInspector(input)));renderSwatchInspector(swatchInputs.find(input=>input.checked)||swatchInputs[0]);
/* 11DZ_CORE_SCRIPT_END */
const workflowBridgeSpec={"name":"controls-selectors-color-swatches","selector":"[data-core-bridge=\"controls-selectors-color-swatches\"]","mode":"radio","key":"ArrowRight"};const workflowBridgeCore=document.querySelector('#workflowCore');const workflowBridgeControl=workflowBridgeCore.querySelector(workflowBridgeSpec.selector);if(!workflowBridgeControl)throw new Error('Missing core bridge: '+workflowBridgeSpec.name);const workflowBridgeControlledId=workflowBridgeControl.getAttribute('aria-controls');const workflowBridgeControlled=workflowBridgeControlledId?document.getElementById(workflowBridgeControlledId):null;workflowBridgeCore.dataset.workflowBridge=workflowBridgeSpec.name;workflowBridgeCore.dataset.workflowVersion='0';function workflowBridgeSerialize(){const visualNode=workflowBridgeCore.firstElementChild||workflowBridgeCore;const visual=getComputedStyle(visualNode);const outputs=[...workflowBridgeCore.querySelectorAll('output,[role="status"],[aria-live],meter,progress')].map(node=>node.textContent.trim()+'|'+node.getAttribute('aria-valuenow')+'|'+node.getAttribute('value'));const canvas=[...workflowBridgeCore.querySelectorAll('canvas')].map(node=>{try{return node.toDataURL().slice(-160);}catch{return 'canvas-unavailable';}});return JSON.stringify({html:workflowBridgeCore.innerHTML,status:statusOutput.textContent,outputs,canvas,visual:[visual.display,visual.visibility,visual.opacity,visual.transform,visual.filter,visual.backgroundColor,visual.width,visual.height],scroll:workflowBridgeSpec.mode==='scroll'?workflowBridgeControl.scrollTop:null});}let workflowBridgeLastEffect=workflowBridgeSerialize();function workflowBridgeSummary(){const label=(workflowBridgeControl.getAttribute('aria-label')||workflowBridgeControl.textContent||workflowBridgeControl.value||workflowBridgeSpec.name).trim().replace(/\s+/g,' ').slice(0,72);return label+' · Core Version '+workflowBridgeCore.dataset.workflowVersion;}function workflowBridgeCommit(){const effect=workflowBridgeSerialize();if(effect===workflowBridgeLastEffect)return {changed:false,summary:workflowBridgeSummary()};workflowBridgeLastEffect=effect;workflowBridgeCore.dataset.workflowVersion=String(Number(workflowBridgeCore.dataset.workflowVersion||0)+1);return {changed:true,summary:workflowBridgeSummary()};}function workflowBridgeScheduleCommit(){queueMicrotask(workflowBridgeCommit);setTimeout(workflowBridgeCommit,0);}workflowBridgeControl.addEventListener("keydown",workflowBridgeScheduleCommit);workflowBridgeControl.addEventListener('input',workflowBridgeScheduleCommit);workflowBridgeControl.addEventListener('change',workflowBridgeScheduleCommit);const workflowBridgeStateTargets=new Set(workflowBridgeCore.querySelectorAll('dialog'));if(workflowBridgeControlled&&workflowBridgeCore.contains(workflowBridgeControlled))workflowBridgeStateTargets.add(workflowBridgeControlled);workflowBridgeStateTargets.forEach(target=>['close','cancel','toggle'].forEach(eventName=>target.addEventListener(eventName,workflowBridgeScheduleCommit)));function workflowBridgeActivate(){workflowBridgeControl.focus();const radios=[...workflowBridgeCore.querySelectorAll('input[type="radio"]')].filter(input=>input.name===workflowBridgeControl.name&&!input.disabled);const current=Math.max(0,radios.findIndex(input=>input.checked));radios[(current+1)%radios.length].click();const result=workflowBridgeCommit();setTimeout(workflowBridgeCommit,0);return result;}function workflowBridgeReset(){workflowBridgeCore.dataset.workflowVersion='0';workflowBridgeLastEffect=workflowBridgeSerialize();}
const workflowSpatial=document.querySelector('#workflowSpatial');const workflowSpatialCore=document.querySelector('#workflowCore');const workflowSpatialWidth=document.querySelector('#workflowSpatialWidth');const workflowSpatialZoom=document.querySelector('#workflowSpatialZoom');const workflowSpatialHandle=document.querySelector('#workflowSpatialHandle');const workflowSpatialState={width:64,zoom:1,dragging:false};function workflowSpatialDrive(){workflowSpatial.style.setProperty('--spatial-width',workflowSpatialState.width+'%');workflowSpatial.style.setProperty('--spatial-zoom',String(workflowSpatialState.zoom));workflowSpatialWidth.value=String(workflowSpatialState.width);workflowSpatialZoom.value=String(Math.round(workflowSpatialState.zoom*100));document.querySelector('#workflowSpatialWidthValue').textContent=workflowSpatialState.width+'%';document.querySelector('#workflowSpatialZoomValue').textContent=Math.round(workflowSpatialState.zoom*100)+'%';document.querySelector('#workflowSpatialStatus').textContent='width '+workflowSpatialState.width+'%, zoom '+Math.round(workflowSpatialState.zoom*100)+'%';announce('Loft console canvas rearranged');}workflowSpatialWidth.addEventListener('input',()=>{workflowSpatialState.width=Number(workflowSpatialWidth.value);workflowSpatialDrive();});workflowSpatialZoom.addEventListener('input',()=>{workflowSpatialState.zoom=Number(workflowSpatialZoom.value)/100;workflowSpatialDrive();});workflowSpatialHandle.addEventListener('pointerdown',event=>{workflowSpatialState.dragging=true;workflowSpatialHandle.setPointerCapture(event.pointerId);});workflowSpatialHandle.addEventListener('pointermove',event=>{if(!workflowSpatialState.dragging)return;const rect=workflowSpatial.getBoundingClientRect();workflowSpatialState.width=Math.max(38,Math.min(82,Math.round((event.clientX-rect.left)/rect.width*100)));workflowSpatialDrive();});workflowSpatialHandle.addEventListener('pointerup',event=>{workflowSpatialState.dragging=false;workflowSpatialHandle.releasePointerCapture(event.pointerId);});workflowSpatialHandle.addEventListener('wheel',event=>{event.preventDefault();workflowSpatialState.zoom=Math.max(.8,Math.min(1.2,workflowSpatialState.zoom+(event.deltaY<0?.05:-.05)));workflowSpatialDrive();},{passive:false});workflowSpatialHandle.addEventListener('keydown',event=>{if(!['ArrowLeft','ArrowRight'].includes(event.key))return;event.preventDefault();workflowSpatialState.width=Math.max(38,Math.min(82,workflowSpatialState.width+(event.key==='ArrowRight'?2:-2)));workflowSpatialDrive();});document.querySelector('#workflowSpatialApply').addEventListener('click',()=>{const bridge=workflowBridgeActivate();document.querySelector('#workflowSpatialStatus').textContent='Applied scenario · width '+workflowSpatialState.width+'%, zoom '+Math.round(workflowSpatialState.zoom*100)+'% · '+bridge.summary;announce(document.querySelector('#workflowSpatialStatus').textContent);});workflowSpatialDrive();
workflowBridgeReset();
  </script>
</body>
</html>
Page feedbackFound an issue or have suggestions for improvement?
Feedback features need to be used in the online version

Please enable JavaScript in the online version before submitting; local features of the current tool or example are not affected.

Go to the online version for feedback