
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
@double-great/stylelint-a11y
Advanced tools
Stylelint plugin for CSS accessibility rules.
This plugin requires Stylelint 16.0.0 or higher.
npm i --save-dev stylelint @double-great/stylelint-a11y
Create the .stylelintrc.json
config file (or open the existing one), add stylelint-a11y
to the plugins array and the rules you need to the rules list. All rules from stylelint-a11y need to be namespaced with a11y
.
Please refer to stylelint docs for the detailed info on using this linter.
Here's a basic .stylelintrc.json
configuration:
{
"plugins": ["@double-great/stylelint-a11y"],
"rules": {
"a11y/no-outline-none": true,
"a11y/font-size-is-readable": true,
"a11y/media-prefers-reduced-motion": true,
"a11y/selector-pseudo-class-focus": true
}
}
Or extend one of the provided configs:
{
"extends": ["@double-great/stylelint-a11y/recommended"],
"rules": {
// Add any additional rules or overrides here
}
}
For stricter accessibility checks:
{
"extends": ["@double-great/stylelint-a11y/strict"],
"rules": {
// Override any rules if needed
}
}
Rule ID | Description | |
---|---|---|
content-property-no-static-value | Disallow unaccessible CSS generated content in pseudo-elements | |
font-size-is-readable | Disallow font sizes less than 15px | |
line-height-is-vertical-rhythmed | Disallow not vertical rhythmed line-height | |
media-prefers-reduced-motion | Require certain styles if the animation or transition in media features | Recommended, Fixable |
media-prefers-color-scheme | Require implementation of certain styles for selectors with colors. | |
no-display-none | Disallow content hiding with display: none property | |
no-obsolete-attribute | Disallow obsolete attribute using | |
no-obsolete-element | Disallow obsolete selectors using | |
no-spread-text | Require width of text in a comfortable range | |
no-outline-none | Disallow outline clearing | Recommended |
no-text-align-justify | Disallow content with text-align: justify | |
selector-pseudo-class-focus | Require or disallow a pseudo-element to the selectors with :hover | Recommended, Fixable |
Add recommended configuration by adding the following to extends
in your stylelint configuration:
@double-great/stylelint-a11y/recommended
This shareable config contains the following:
{
"plugins": ["@double-great/stylelint-a11y"],
"rules": {
"a11y/media-prefers-reduced-motion": true,
"a11y/no-outline-none": true,
"a11y/selector-pseudo-class-focus": true
}
}
For a more comprehensive accessibility check, use the strict configuration:
@double-great/stylelint-a11y/strict
This config enables ALL accessibility rules:
{
"plugins": ["@double-great/stylelint-a11y"],
"rules": {
"a11y/content-property-no-static-value": true,
"a11y/font-size-is-readable": true,
"a11y/line-height-is-vertical-rhythmed": true,
"a11y/media-prefers-color-scheme": true,
"a11y/media-prefers-reduced-motion": true,
"a11y/no-display-none": true,
"a11y/no-obsolete-attribute": true,
"a11y/no-obsolete-element": true,
"a11y/no-outline-none": true,
"a11y/no-spread-text": true,
"a11y/no-text-align-justify": true,
"a11y/selector-pseudo-class-focus": true
}
}
Since both configs add stylelint-a11y to plugins
, you don't have to do this yourself when extending these configs.
Stylelint supports configuring rules with different severity levels. You can set rules to either "error" or "warning":
{
"rules": {
"a11y/no-outline-none": "error",
"a11y/font-size-is-readable": "warning",
"a11y/media-prefers-reduced-motion": ["warning", { "ignore": ["animation"] }]
}
}
You can also use array syntax with severity as the first element:
{
"rules": {
"a11y/no-outline-none": ["error"],
"a11y/font-size-is-readable": ["warning", { "thresholdInPixels": 14 }],
"a11y/selector-pseudo-class-focus": ["error", "always"]
}
}
Many rules support additional configuration options for customization. For example:
{
"rules": {
"a11y/font-size-is-readable": [true, { "thresholdInPixels": 16 }],
"a11y/no-spread-text": [true, { "minWidth": 30, "maxWidth": 60 }],
"a11y/line-height-is-vertical-rhythmed": [true, { "baselineGrid": 20 }]
}
}
Refer to individual rule documentation for available options.
You can disable rules inline using stylelint's comment syntax:
/* stylelint-disable a11y/no-outline-none */
.button:focus {
outline: none;
}
/* stylelint-enable a11y/no-outline-none */
Or for a single line:
.button:focus {
outline: none; /* stylelint-disable-line a11y/no-outline-none */
}
We welcome contributions! Please see our Contributing Guide for detailed information on:
For quick links:
Run tests with the following commands:
npm run test
- Run unit tests for all rulesnpm run test:unit
- Run unit tests onlynpm run test:integration
- Run integration testsnpm run test:e2e
- Run end-to-end tests with real projectsnpm run test:performance
- Run performance benchmarksnpm run test:all
- Run complete test suiteThis project includes testing at a few levels:
npm run lint
- Run ESLintnpm run format:check
- Check code formattingnpm run format:fix
- Fix code formattingnpm run coverage
- Run tests with coverage reportThis project is licensed under the MIT License.
FAQs
Plugin for stylelint with a11y rules
We found that @double-great/stylelint-a11y demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.