Skip to content

Integration Guide

Install postcss and postcss-logical-polyfill as development dependencies. Run this plugin after preprocessors, CSS generation and nesting expansion. Set <html dir="ltr"> or <html dir="rtl"> so the default direction selectors match.

Use this configuration with tools that load a PostCSS config, including Vite:

postcss.config.mjs
import logicalPolyfill from 'postcss-logical-polyfill';
export default {
plugins: [logicalPolyfill()]
};

For CommonJS, use postcss.config.cjs:

module.exports = {
plugins: [require('postcss-logical-polyfill')()]
};
Terminal window
npm install --save-dev postcss postcss-cli postcss-logical-polyfill
npx postcss input.css -o output.css

The CLI loads the configuration above. See the CLI example.

As an alternative to a separate PostCSS configuration file:

vite.config.mjs
import { defineConfig } from 'vite';
import logicalPolyfill from 'postcss-logical-polyfill';
export default defineConfig({
css: {
postcss: {
plugins: [logicalPolyfill()]
}
}
});

See the Vite source-map example.

Install postcss-loader, css-loader and style-loader in addition to the plugin and PostCSS, then configure your CSS rule:

webpack.config.cjs
module.exports = {
module: {
rules: [{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [require('postcss-logical-polyfill')()]
}
}
}
]
}]
}
};

See the Webpack example.

Use a PostCSS configuration rather than adding another CSS loader to Next.js:

postcss.config.mjs
export default {
plugins: {
'postcss-logical-polyfill': {}
}
};

A custom PostCSS configuration replaces Next.js defaults. Include the other plugins your application needs, with CSS generation and nesting expansion before this plugin. Set the HTML dir attribute in your root layout.

Compile Sass or Less to CSS before this plugin. The repository has Sass and Less examples.

For Tailwind, run this plugin after Tailwind generates CSS. Use the PostCSS plugin for your installed major version (tailwindcss for v3, @tailwindcss/postcss for v4). Prefer logical utilities: this plugin does not mirror physical ml-* and mr-* utilities.

The plugin options are ltr, rtl and outputOrder. Options such as preserve or dir from other plugins are not part of this API.