Inline Style Prefixer
inline-style-prefixer is a JavaScript library designed to automatically add vendor prefixes to CSS properties within JavaScript style objects at runtime. Currently stable at version 7.0.1, the library has seen sporadic major releases (e.g., a jump from v3 to v7) but maintains active development within its major versions. Its primary function is to ensure cross-browser compatibility for modern CSS properties by intelligently applying prefixes only where necessary for its supported browser matrix (e.g., Chrome 55+, Firefox 52+), rather than prefixing all properties indiscriminately. Key differentiators include its small footprint, speed, and simplicity, offering a functional API. It is widely adopted by popular styling-in-JS libraries such as Aphrodite, Fela, Material UI, and styled-components, providing a reliable solution for managing vendor prefixes in complex web applications.
Common errors
-
TypeError: inline_style_prefixer__WEBPACK_IMPORTED_MODULE_0__.prefix is not a function
cause Attempting to call 'prefix' on a CommonJS module import without destructuring, or importing an older default export that no longer exists.fixEnsure you are using named imports for ESM: `import { prefix } from 'inline-style-prefixer'` or destructuring for CJS: `const { prefix } = require('inline-style-prefixer')`. -
ReferenceError: Prefixer is not defined
cause Attempting to use the old class-based API (`new Prefixer()`) from versions 3.x or earlier with `inline-style-prefixer` v4 or newer.fixUpdate your code to use the modern functional API: `import { prefix } from 'inline-style-prefixer'; prefix(style)` or `import { createPrefixer } from 'inline-style-prefixer'`.
Warnings
- breaking Major refactor in v4 changed the API from a class-based `new Prefixer(config)` instantiation to a functional approach exporting `prefix` and `createPrefixer`.
- gotcha The library only applies prefixes for properties that *still require* them in its specified supported browser versions (e.g., Chrome 55+, Firefox 52+). Properties like `border-radius` which are fully standardized in modern browsers will not be prefixed.
- gotcha TypeScript users must install `@types/inline-style-prefixer` separately as the package does not bundle its own type definitions. Without it, you'll encounter TypeScript errors.
Install
-
npm install inline-style-prefixer -
yarn add inline-style-prefixer -
pnpm add inline-style-prefixer
Imports
- prefix
import Prefixer from 'inline-style-prefixer'; const prefix = new Prefixer().prefix
import { prefix } from 'inline-style-prefixer' - prefix (CommonJS)
const prefix = require('inline-style-prefixer')const { prefix } = require('inline-style-prefixer') - createPrefixer
import { Prefixer } from 'inline-style-prefixer'import { createPrefixer } from 'inline-style-prefixer'
Quickstart
import { prefix } from 'inline-style-prefixer';
const style = {
transition: '200ms all linear',
boxSizing: 'border-box',
display: 'flex',
color: 'blue',
// Example of a property that won't be prefixed in modern browsers
borderRadius: '5px'
};
const prefixedStyle = prefix(style);
console.log(prefixedStyle);
/* Example output (may vary based on userAgent and browserlist):
{
WebkitTransition: '200ms all linear',
transition: '200ms all linear',
MozBoxSizing: 'border-box',
boxSizing: 'border-box',
display: [ '-webkit-box', '-moz-box', '-ms-flexbox', '-webkit-flex', 'flex' ],
color: 'blue',
borderRadius: '5px'
}*/