1.0.0 • Published 10 months ago

stylelint-root-colors v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

stylelint-root-colors

npm version test status

Summary

color and background-color must be specified as a set in the root element.

The root element is :root { } or html { }.

/* 🆖 Do not specify only either `color` or `background-color` in the root element */
:root {
  color: #000;
}

html,
.foo {
  background-color: #fff;
}

/* 🆗 It is good to specify both `color` and `background-color` */
:root {
  background-color: #fff;
  color: #000;
}

/* 🆗 You may use the `background` short hand */
:root {
  background: #fff;
  color: #000;
}

/* 🆗 The `color` and `background-color` are not required */
:root {
}

/* 🆗 Except in the root element, only either `color` or `background-color` may be specified */
.foo {
  color: #000;
}

Why?

Browser text and background colors can be changed at the user's discretion.

In this case, if only either color or background-color is specified in the root element through producer stylesheets, the text will be unreadable in some cases.

In Firefox, you can set text and background colors arbitrarily in the Manage Colors. The screenshot below shows the text in white and the background in black (i.e., dark mode).

Dialog with color selection palettes for Text, Background, Unvisited Links, and Visited Links

See also F24 in Techniques for WCAG 2.2.

Usage

/** @type {import('stylelint').Config} */
export default {
  plugins: ['stylelint-root-colors'],
  rules: {
    'plugin/root-colors': [
      true,
      {
        root: ['.root'],
      },
    ],
  },
};

Rule options

nametypedescription
rootstring \| string[]Specifies the selector of the root element. If omitted, it will be [':root', 'html'].
1.0.0

10 months ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago