opacity-checkerboard

Overview Changelog

Overview

Section titled Overview

The opacity-checkerboard class provides a CSS utility that displays a checkerboard pattern background, commonly used to highlight transparent or semi-transparent areas in UI components. This visual indicator helps users distinguish between transparent and opaque regions, making it an essential tool for color pickers, image editors, and other components that work with opacity.

Usage

Section titled Usage

See it on NPM! How big is this package in your project?

yarn add @spectrum-web-components/opacity-checkerboard

Import the opacity checkerboard styles from:

import opacityCheckerBoardStyles from '@spectrum-web-components/opacity-checkerboard/src/opacity-checkerboard.css.js';

Integration

Section titled Integration

To integrate the opacity checkerboard styles into your component, add them to your component's styles array. The order of inclusion is important, as selectors within opacity checkerboard may have the same specificity as those within your component:

public static override get styles(): CSSResultArray {
    return [opacityCheckerBoardStyles, styles];
}

Examples

Section titled Examples

Basic usage

Section titled Basic usage

Apply the opacity-checkerboard class to any element that needs to display the checkerboard pattern:

<div
    class="opacity-checkerboard"
    style="inline-size: 100px; block-size: 100px;"
    aria-hidden="true"
></div>

With overlaid content

Section titled With overlaid content

The opacity checkerboard works well as a background for elements with partial transparency:

<div
    class="opacity-checkerboard"
    style="inline-size: 200px; block-size: 200px; position: relative;"
    aria-hidden="true"
>
    <div
        style="
            position: absolute;
            inset: 0;
            background-color: rgba(255, 0, 0, 0.5);
        "
    ></div>
</div>

Accessibility

Section titled Accessibility

When implementing the opacity checkerboard pattern, ensure proper accessibility by:

  • Hiding from screen readers: Use aria-hidden="true" on the checkerboard element since it's purely visual
  • Providing semantic information: Use separate text nodes or live regions to convey opacity information
  • Using live regions: Implement aria-live regions to announce opacity changes dynamically
  • Descriptive context: Provide meaningful descriptions of the actual color and opacity values, not the visual pattern

Screen reader support

Section titled Screen reader support

The opacity checkerboard is a purely visual indicator and should remain hidden from screen readers. Instead, provide semantic information through separate text nodes or live regions that update as opacity changes:

<div class="color-container">
    <div
        class="opacity-checkerboard"
        style="inline-size: 100px; block-size: 100px;"
        aria-hidden="true"
    ></div>
    <div class="visually-hidden" aria-live="polite" id="opacity-status">
        Current opacity: 75%
    </div>
</div>

For components that change opacity dynamically, use a live region to announce changes:

<div class="dynamic-opacity-example">
    <div
        class="opacity-checkerboard"
        style="inline-size: 100px; block-size: 100px; position: relative;"
        aria-hidden="true"
    >
        <div
            style="
                position: absolute;
                inset: 0;
                background-color: rgba(255, 0, 0, 0.6);
            "
        ></div>
    </div>
    <div aria-live="assertive" class="visually-hidden">
        Opacity changed to 60%
    </div>
</div>

Keyboard navigation

Section titled Keyboard navigation

When the opacity checkerboard is part of an interactive component, ensure it doesn't interfere with keyboard navigation:

<button
    class="color-button"
    aria-label="Select red color with 50% opacity"
    aria-describedby="opacity-description"
>
    <span
        class="opacity-checkerboard"
        style="inline-size: 40px; block-size: 40px; display: block;"
        aria-hidden="true"
    ></span>
    <span id="opacity-description" class="visually-hidden">
        Red color with 50% transparency
    </span>
</button>

Changelog

Patch Changes

Section titled Patch Changes
  • Updated dependencies []:
    • @spectrum-web-components/base@1.8.0

1.7.0

Section titled 1.7.0

Patch Changes

Section titled Patch Changes
  • Updated dependencies []:
    • @spectrum-web-components/base@1.7.0

1.6.0

Section titled 1.6.0

Patch Changes

Section titled Patch Changes
  • Updated dependencies []:
    • @spectrum-web-components/base@1.6.0

1.5.0

Section titled 1.5.0

Patch Changes

Section titled Patch Changes
  • Updated dependencies []:
    • @spectrum-web-components/base@1.5.0

1.4.0

Section titled 1.4.0

Patch Changes

Section titled Patch Changes
  • Updated dependencies []:
    • @spectrum-web-components/base@1.4.0

1.3.0

Section titled 1.3.0

Patch Changes

Section titled Patch Changes
  • Updated dependencies []:
    • @spectrum-web-components/base@1.3.0

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

1.2.0 (2025-02-27)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

1.1.2 (2025-02-12)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

1.1.1 (2025-01-29)

Section titled

Features

Section titled Features
  • opacity-checkerboard: bump CSS version (#5040) (e3bf6d3)

1.1.0 (2025-01-29)

Section titled

Bug Fixes

Section titled Bug Fixes
  • lock prerelease versions for Spectrum CSS (#5014) (8aa7734)

Features

Section titled Features
  • opacity-checkerboard: bump CSS version (#5040) (e3bf6d3)

1.0.1 (2024-11-11)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

1.0.0 (2024-10-31)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.49.0 (2024-10-15)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.48.1 (2024-10-01)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.48.0 (2024-09-17)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.47.2 (2024-09-03)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.47.1 (2024-08-27)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.47.0 (2024-08-20)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.46.0 (2024-08-08)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.45.0 (2024-07-30)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.44.0 (2024-07-15)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.43.0 (2024-06-11)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.42.5 (2024-05-24)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.42.4 (2024-05-14)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.42.3 (2024-05-01)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.42.2 (2024-04-03)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.42.1 (2024-04-02)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.42.0 (2024-03-19)

Section titled

Features

Section titled Features
  • asset: use core tokens (99e76f4)

0.41.2 (2024-03-05)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.41.1 (2024-02-22)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.41.0 (2024-02-13)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.40.5 (2024-02-05)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.40.4 (2024-01-29)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.40.3 (2024-01-11)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.40.2 (2023-12-18)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.40.1 (2023-12-05)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.40.0 (2023-11-16)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.39.4 (2023-11-02)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.39.3 (2023-10-18)

Section titled

Bug Fixes

Section titled Bug Fixes
  • update deps graph, fix imports (f633005)

0.39.2 (2023-10-13)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.39.1 (2023-10-06)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.39.0 (2023-09-25)

Section titled

Bug Fixes

Section titled Bug Fixes
  • color-handle,color-loupe,swatch,thumbnail: use the Opacity Checkerboard package (47e1fc4)
  • opacity checkerboard inclusion order (#3651) (4f417dc)

0.38.0 (2023-09-05)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.37.0 (2023-08-18)

Section titled

Note: Version bump only for package @spectrum-web-components/opacity-checkerboard

0.36.0 (2023-08-18)

Section titled

Features

Section titled Features
  • opacity-checkerboard: add component (#3416) (90202f9)