<div class="c-dialog" id="dialog">
  <div class="c-dialog__backdrop" tabindex="-1"></div>
  <div open role="dialog" class="c-dialog__content" aria-labelledby="dialog-title" aria-describedby="dialog-description">
    <div class="c-dialog__header">
      <button data-a11y-dialog-hide class="c-dialog__close-button" aria-label="Close">
        <svg class="c-dialog__close-icon" aria-hidden="true" focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M23.297.703a2.4 2.4 0 0 1 .128 3.256l-.128.138L15.395 12l7.902 7.903a2.4 2.4 0 0 1-3.256 3.522l-.138-.128L12 15.395l-7.903 7.902a2.4 2.4 0 0 1-3.522-3.256l.128-.138L8.605 12 .703 4.097A2.4 2.4 0 0 1 3.959.575l.138.128L12 8.605 19.903.703a2.4 2.4 0 0 1 3.394 0Z" fill-rule="nonzero"/></svg>
        <span class="hide-visually">Close</span>
      <h1 id="dialog-title" class="c-dialog__title">This is a simple modal dialog</h1>
    <div class="c-dialog__body">
      <p id="dialog-description">
        It has a title, a close button, and some body content, and that’s about it.

<main aria-hidden="true">
  <p>I'm just here to help show how the modal floats over other content, and how the dropshadow partially obscures content only in a normal display mode, and not Forced Colors mode. Forced Colors mode is really interesting, and I'm glad it exists because it helps people use computers, and also it's an open standard now, so everyone can enjoy and contribute to it.</p>
  <p>Designing for Forced Colors mode isn't too difficult once you know that it exists. It's mostly about making a good habit to check it in the first place, and then making small, surgical tweaks rather than complete overhauls.</p>
  <p>Still here? Cool. Don't forget to test your websites and web apps with the <kbd>Tab</kbd> key and make sure that each interactive element has a visible focus state. That'll help a whole lot to make things accessible!</p>
// How to read this:
// [1] Custom Properties are set up to mimic a design system.
// [2] A dialog modal component is defined.
// [3] Component-level Custom Properties are set up that 
//     draw from the `:root` Custom Properties.
// [4] Component-level Custom Properties are integrated into 
//     the dialog's subcomponents.
// [5] Custom Properties are updated in a controlled scope.

// [1] Global, component-agnostic settings
:root {
  --color-background: #FFFFFF;
  --color-blue-100: #D6E4FF;
  --color-blue-200: #ADC8FF;
  --color-blue-300: #84A9FF;
  --color-blue-400: #6690FF;
  --color-blue-500: #3366FF;
  --color-blue-600: #254EDB;
  --color-blue-700: #1939B7;
  --color-blue-800: #102693;
  --color-blue-900: #091A7A;
  --color-gray-100: #ECECED;
  --color-gray-200: #E0E0E0;
  --color-gray-300: #D3D3D4;
  --color-gray-400: #CECECE;
  --color-gray-500: #C3C3C3;
  --color-gray-600: #7E7E7E;
  --color-gray-700: #5B5B5C;
  --color-gray-800: #434344;
  --color-gray-900: #353535;

  --border-width-100: 1px;
  --border-width-200: 2px;
  --border-width-300: 3px;
  --border-width-400: 4px;
  --border-width-500: 5px;
  --border-width-600: 6px;
  --line-height-100: 1;
  --line-height-200: 1.2;
  --line-height-300: 1.3;
  --line-height-400: 1.4;
  --line-height-500: 1.5;
  --transition-fastest: 150ms;
  --transition-fast: 250ms;

  // Basic modular scales
  --font-size-100: 1rem;
  --font-size-200: 1.5rem;
  --font-size-300: 2.25rem;
  --font-size-400: 3.375rem;
  --font-size-500: 5.063rem;
  --size-100: 1rem;
  --size-200: 1.5rem;
  --size-300: 2.25rem;
  --size-400: 3.375rem;
  --size-500: 5.063rem;

// [2]
.c-dialog {
  // [3] Define component-level Custom Properties
  --dialog-border-width: var(--border-width-100);
  --dialog-border-color: var(--color-gray-300);
  --dialog-color-backdrop: #2b2e38e6;
  --dialog-color-background: var(--color-gray-900);
  --dialog-color-body: var(--color-gray-100);
  --dialog-color-icon-close: var(--color-blue-100);
  --dialog-color-title: var(--color-blue-100);
  --dialog-padding-outer: var(--size-300);
  --dialog-size-icon-close: var(--size-200);

  align-content: center;
  display: grid;
  justify-content: center;
  position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;

.c-dialog__backdrop {
  position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;

.c-dialog__content {
  background-color: var(--dialog-color-background); // [4] Integrate component-level Custom Properties
  box-shadow: 0 1rem 2rem 0 #00000099;
  outline: var(--dialog-border-width) solid var(--dialog-border-color);
  padding: var(--dialog-padding-outer);
  width: min(90vw, 38rem);
  z-index: 1;
  @media (forced-colors: active) {
    --dialog-border-width: var(--size-300); // [5]

.c-dialog__header {
  align-items: flex-start;
  display: flex;
  justify-content: space-between;

.c-dialog__title {
  color: var(--dialog-color-title);
  margin-top: 0;
  margin-right: var(--size-100);
  order: 1;

.c-dialog__close-button {
  align-self: flex-start;
  background-color: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  line-height: 1;
  margin: 0;
  order: 2;
  &:focus {
    // [5] Redefine component Custom Properties for user-facing state
    --dialog-focus-ring-inner: var(--dialog-color-background);
    --dialog-focus-ring-outer: var(--dialog-color-icon-close);

      0 0 0 var(--border-width-200) var(--dialog-focus-ring-inner), // Integrate redefined Custom Properties
      0 0 0 var(--border-width-600) var(--dialog-focus-ring-outer);
    outline: var(--border-width-300) solid transparent; // Transparent borders and outlines are rendered when Forced Color mode is active, so we don't have to write an extra media query

.c-dialog__close-icon {
  fill: var(--dialog-color-icon-close);
  forced-color-adjust: auto;
  height: var(--dialog-size-icon-close);
  width: var(--dialog-size-icon-close);
  transition: fill var(--transition-fastest) ease-in-out;
  &:hover {
    --dialog-color-icon-close: var(--color-blue-400);

    fill: var(--dialog-color-icon-close);
  &:active {
    --dialog-color-icon-close: var(--color-blue-800);

    fill: var(--dialog-color-icon-close);
    transition: none;

.c-dialog__body {
  color: var(--dialog-color-body);
  font-size: var(--font-size-200);

// Pen setup
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;

body {
  align-content: center;
  background-color: var(--color-background);
  color: var(--color-gray-800);
  display: grid;
  font-family: 'League Spartan', sans-serif;
  justify-content: center;
  min-height: 100vh;
  padding: 0.5rem;

main p {
  font-size: 1.25rem;
  line-height: var(--line-height-400);
  margin-top: 1rem;

.hide-visually {
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
View Compiled
// This is a demo for CSS stuff, sorry! 

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.