CSS Browser Support Linter

6.0.6 · active · verified Wed Apr 22

Doiuse is a JavaScript library and CLI tool that lints CSS code for browser support issues by comparing features used in the CSS against the Can I use database. It helps developers identify CSS properties and values that are not supported by their target browser list, preventing unexpected rendering problems. The current stable version is 6.0.6, released in early 2024, with maintenance releases occurring as needed to fix bugs and update feature definitions. It integrates well into build pipelines, notably as a PostCSS plugin or a transform stream. A key differentiator is its direct reliance on the `caniuse` database for accurate, up-to-date compatibility data, allowing for highly customizable browser targets using `browserslist` syntax. While it focuses on identifying unsupported features, its "naive" detection approach means it primarily checks for direct property/value matches rather than complex runtime interpretation, offering a fast and focused linting experience.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `doiuse` as a PostCSS plugin to lint CSS for browser compatibility, targeting specific browser versions and logging unsupported feature usages to the console.

import postcss from 'postcss';
import DoIUse from 'doiuse/lib/DoIUse.js';

const cssInput = `
a { 
  background-size: cover; 
  display: flex; /* flexbox support */
  user-select: none;
  scroll-snap-align: start;
}

.gradient {
  background-image: conic-gradient(white, black);
}
`;

postcss(new DoIUse({
  browsers: ['last 2 chrome versions', 'ie 11'], // Target specific browsers
  ignore: ['flexbox', 'user-select-none'], // Optional: ignore specific features by 'caniuse' ID
  ignoreFiles: ['**/node_modules/**'], // Optional: ignore files matching these globs
  onFeatureUsage: (usageInfo) => {
    // Log detailed information about each unsupported feature found
    console.log(`[doiuse] ${usageInfo.message} in ${usageInfo.feature} for ${usageInfo.browsers.join(', ')} at ${usageInfo.source.start.line}:${usageInfo.source.start.column}`);
  }
})).process(cssInput, { from: 'example.css' })
  .then(result => {
    console.log('\nProcessed CSS (no changes made by doiuse):\n', result.css);
  })
  .catch(error => {
    console.error('PostCSS processing failed:', error);
  });

view raw JSON →