Accessibility · Component reference

Appearance and contrast

Four appearance choices, 32 page shades and measured contrast at every step.

Published and reviewed · Starlit’s implementation notes

Try the live example

Research and our take

Our recorded research compared reader preferences and accessibility tools across several projects. For this component, these observations informed Starlit’s approach:

  • NB Accessibility: Text and spacing controls, contrast, link emphasis, motion and a local reset. Our decision: Keep the package local and make every preference reversible.

Starlit wrote the shared controller, scoped content adapters and component modules presented here. The referenced widgets are research sources, not browser dependencies. The component also draws on interface work in EvansWiki and PayCal.

Design reasoning

Offer a comfortable palette without using a page inversion filter that distorts images and meaning.

  1. Start with the person’s task and the barrier they may encounter.
  2. Connect the shared palette tokens to actual text, surfaces, links, borders and focus. This focused panel also demonstrates appearance presets.
  3. Keep the ordinary content and action usable before adding enhancement.
  4. Move through all 32 shades and contrast modes. Inspect links, form errors, focus and muted copy, not only the main paragraph.

Usage pattern

Connect the shared palette tokens to actual text, surfaces, links, borders and focus. This focused panel also demonstrates appearance presets.

Impact and tradeoffs

A shade slider provides finer choice. Every intermediate shade needs contrast checks, including secondary text and disabled controls.

Accessibility solutions

The library targets a 5:1 floor for its measured reading pairs. This project target is distinct from the individual WCAG requirements. Do not communicate state through colour alone.

Build accessible source content first. Personal preferences supplement semantic HTML, useful names, keyboard access and visible focus.

HTML

A concrete usage example. Host these assets on your own origin if you adapt the pattern. Read the source and credits before reuse.

<link rel="stylesheet" href="/open-ui/accessibility/shared/content.css">
<script type="module"
  src="/open-ui/accessibility/components/appearance-panel/index.js"></script>

<article id="reading" data-sdou-a11y-content data-default-theme="dark">
  <div data-sdou-a11y-prose>
    <h2 id="begin">Begin with a clear purpose</h2>
    <p>Readable text and useful controls belong together.</p>
    <h2 id="details">Consider the details</h2>
    <p>The page should remain usable before any enhancement loads.</p>
  </div>
</article>
<sdou-appearance-panel target="#reading"
  storage-key="example.appearance-panel.v1"></sdou-appearance-panel>

Open the HTML usage source

CSS

This is the component stylesheet used inside its Shadow DOM. The shared ui.css supplies its base controls and content.css adapts the reading region. An empty component stylesheet deliberately inherits the shared UI.

.contrast-meter {
  padding: 16px;
  border: 1px solid var(--sdou-ax-line);
  border-radius: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.contrast-meter .hint {
  margin: 0;
}
.contrast-meter strong {
  font:
    2rem Georgia,
    serif;
}

JavaScript

This is the actual component module used by the live example. Imports, the base class and shared preferences are dependencies. Keep the component folder and shared folder in their relative positions.

import { A11yComponent, appearance, preview } from "../../shared/base.js?v=sdou20261029";
class AppearancePanel extends A11yComponent {
  static styles = new URL("./component.css?v=sdou20261029", import.meta.url).href;
  render() {
    this.mount(
      "A more comfortable view.",
      "Choose a palette or explore the page shade. Text, links and borders keep at least 5:1 contrast.",
      appearance() +
        preview +
        '<div class="contrast-meter"><span class="hint">Lowest reading color pair</span><strong class="number" data-ratio></strong></div>',
    );
  }
  update() {
    const out = this.q("[data-ratio]");
    if (out)
      out.textContent = this.preferences.colors.minimum.toFixed(2) + ":1";
  }
}
customElements.define("sdou-appearance-panel", AppearancePanel);

PHP integration

In your own application, PHP can render this HTML on the server. Here, the example is escaped text only. The library has no PHP runner or execution endpoint. The browser owns the interaction.

<?php
// Server render trusted structure and escape authored text.
// PHP does not implement or save these browser preferences.
declare(strict_types=1);
$title = 'A readable article';
$paragraph = 'Your authored content goes here.';
$e = static fn (string $value): string =>
    htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
?>
<link rel="stylesheet" href="/open-ui/accessibility/shared/content.css">
<script type="module"
  src="/open-ui/accessibility/components/appearance-panel/index.js"></script>
<article id="reading" data-sdou-a11y-content data-default-theme="dark">
  <div data-sdou-a11y-prose>
    <h2 id="begin"><?= $e($title) ?></h2>
    <p><?= $e($paragraph) ?></p>
  </div>
</article>
<sdou-appearance-panel target="#reading"
  storage-key="example.appearance-panel.v1"></sdou-appearance-panel>

Open the PHP rendering source

API and dependencies

Element
sdou-appearance-panel
target
A selector for the content region. Use a unique ID. Components sharing a target share its controller.
storage-key
A stable key for this project. Use the same key for controls targeting the same region. Preferences stay in browser storage when available.
Content
data-sdou-a11y-content marks the target; data-sdou-a11y-prose identifies reading copy. Use data-default-theme="dark" for a dark initial and reset preference.
Event
sdou:a11y-change is dispatched on the target with preferences, palette and reducedMotion in its detail.
Dependencies
Modern JavaScript modules, custom elements, Shadow DOM and native form controls. Dialog, speech, clipboard and fullscreen support depend on the feature and browser.

Read shared/base.js · Read the preference controller · Read the content adapter · Read the shared control styles

Testing and limitations

Move through all 32 shades and contrast modes. Inspect links, form errors, focus and muted copy, not only the main paragraph.

The original library validation records automated rule checks, 320px reflow, enlarged text, text spacing, state persistence and relevant functional checks. Unresolved automated Shadow DOM reference checks are recorded separately from browser dialog checks. These historical results are not a new audit of every integration.

Production review still needs assistive technology, touch, zoom, custom styles and representative content. See our testing scope and known gaps. Report a barrier to Starlit.