{"id":13563783,"url":"https://github.com/csstools/postcss-dir-pseudo-class","last_synced_at":"2025-04-03T20:31:46.808Z","repository":{"id":47009208,"uuid":"92875207","full_name":"csstools/postcss-dir-pseudo-class","owner":"csstools","description":"Use the :dir() pseudo-class to style by directionality in CSS","archived":true,"fork":false,"pushed_at":"2021-12-16T12:30:30.000Z","size":223,"stargazers_count":16,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-29T00:49:43.522Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-dir-pseudo-class","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/csstools.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-30T20:53:48.000Z","updated_at":"2023-01-28T04:36:58.000Z","dependencies_parsed_at":"2022-09-02T22:34:26.206Z","dependency_job_id":null,"html_url":"https://github.com/csstools/postcss-dir-pseudo-class","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fpostcss-dir-pseudo-class","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fpostcss-dir-pseudo-class/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fpostcss-dir-pseudo-class/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fpostcss-dir-pseudo-class/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/csstools","download_url":"https://codeload.github.com/csstools/postcss-dir-pseudo-class/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246436333,"owners_count":20776987,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T13:01:23.225Z","updated_at":"2025-04-03T20:31:46.566Z","avatar_url":"https://github.com/csstools.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e⚠️ PostCSS Dir Pseudo Class was moved to \u003ca href=\"https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-dir-pseudo-class\"\u003e@csstools/postcss-plugins\u003c/a\u003e. ⚠️ \u003cbr\u003e\n\u003ca href=\"https://github.com/csstools/postcss-plugins/discussions/75\"\u003eRead the announcement\u003c/a\u003e\u003c/div\u003e\n\n# PostCSS Dir Pseudo Class [\u003cimg src=\"https://postcss.github.io/postcss/logo.svg\" alt=\"PostCSS Logo\" width=\"90\" height=\"90\" align=\"right\"\u003e][postcss]\n\n[![NPM Version][npm-img]][npm-url]\n[![CSS Standard Status][css-img]][css-url]\n[![Build Status][cli-img]][cli-url]\n[![Support Chat][git-img]][git-url]\n\n[PostCSS Dir Pseudo Class] lets you style by directionality using the `:dir()`\npseudo-class in CSS, following the [Selectors] specification.\n\n[!['Can I use' table](https://caniuse.bitsofco.de/image/css-dir-pseudo.png)](https://caniuse.com/#feat=css-dir-pseudo)\n\n```pcss\narticle h3:dir(rtl) {\n  margin-right: 10px;\n}\n\narticle h3:dir(ltr) {\n  margin-left: 10px;\n}\n\n/* becomes */\n\n[dir=\"rtl\"] article h3 {\n  margin-right: 10px;\n}\n\n[dir=\"ltr\"] article h3 {\n  margin-left: 10px;\n}\n```\n\n### Maintaining Specificity\n\nUsing [PostCSS Dir Pseudo Class] will not impact selector weight, but it will\nrequire having at least one `[dir]` attribute in your HTML. If you don’t have\n_any_ `[dir]` attributes, consider using the following JavaScript:\n\n```js\n// force at least one dir attribute (this can run at any time)\ndocument.documentElement.dir=document.documentElement.dir||'ltr';\n```\n\nIf you absolutely cannot add a `[dir]` attribute in your HTML or even force one\nvia JavaScript, you can still work around this by presuming a direction in your\nCSS using the [`dir` option](#dir-option), but understand that this will\nsometimes increase selector weight by one element (`html`).\n\n## Usage\n\nAdd [PostCSS Dir Pseudo Class] to your project:\n\n```bash\nnpm install postcss-dir-pseudo-class --save-dev\n```\n\nUse [PostCSS Dir Pseudo Class] to process your CSS:\n\n```js\nconst postcssDirPseudoClass = require('postcss-dir-pseudo-class');\n\npostcssDirPseudoClass.process(YOUR_CSS /*, processOptions, pluginOptions */);\n```\n\nOr use it as a [PostCSS] plugin:\n\n```js\nconst postcss = require('postcss');\nconst postcssDirPseudoClass = require('postcss-dir-pseudo-class');\n\npostcss([\n  postcssDirPseudoClass(/* pluginOptions */)\n]).process(YOUR_CSS /*, processOptions */);\n```\n\n[PostCSS Dir Pseudo Class] runs in all Node environments, with special instructions for:\n\n| [Node](INSTALL.md#node) | [PostCSS CLI](INSTALL.md#postcss-cli) | [Webpack](INSTALL.md#webpack) | [Create React App](INSTALL.md#create-react-app) | [Gulp](INSTALL.md#gulp) | [Grunt](INSTALL.md#grunt) |\n| --- | --- | --- | --- | --- | --- |\n\n## Options\n\n### dir\n\nThe `dir` option allows you presume a direction in your CSS. By default, this\nis not specified and you are required to include a direction `[dir]` attribute\nsomewhere in your HTML, preferably on the `html` element.\n\nHere’s an example of using the `dir` option to presume a left-to-right\ndirection:\n\n```js\npostcssDirPseudoClass({ dir: 'ltr' });\n```\n\n```pcss\n.example:dir(ltr) {\n  margin-left: 10px;\n}\n\n.example:dir(rtl) {\n  margin-right: 10px;\n}\n\n/* becomes */\n\nhtml:not([dir=\"rtl\"]) .example {\n  margin-left: 10px;\n}\n\n[dir=\"rtl\"] .example {\n  margin-right: 10px;\n}\n```\n\n### preserve\n\nThe `preserve` option determines whether the original `:dir()` rule should\nremain in the CSS. By default, the original rule is not preserved.\n\n```js\npostcssDirPseudoClass({ preserve: true });\n```\n\n```pcss\narticle h3:dir(rtl) {\n  margin-right: 10px;\n}\n\narticle h3:dir(ltr) {\n  margin-left: 10px;\n}\n\n/* becomes */\n\n[dir=\"rtl\"] article h3 {\n  margin-right: 10px;\n}\n\narticle h3:dir(rtl) {\n  margin-right: 10px;\n}\n\n[dir=\"ltr\"] article h3 {\n  margin-left: 10px;\n}\n\narticle h3:dir(ltr) {\n  margin-left: 10px;\n}\n```\n\n[cli-img]: https://github.com/csstools/postcss-dir-pseudo-class/workflows/test/badge.svg\n[cli-url]: https://github.com/csstools/postcss-dir-pseudo-class/actions/workflows/test.yml?query=workflow/test\n[css-img]: https://cssdb.org/badge/dir-pseudo-class.svg\n[css-url]: https://cssdb.org/#dir-pseudo-class\n[git-img]: https://img.shields.io/badge/support-chat-blue.svg\n[git-url]: https://gitter.im/postcss/postcss\n[npm-img]: https://img.shields.io/npm/v/postcss-dir-pseudo-class.svg\n[npm-url]: https://www.npmjs.com/package/postcss-dir-pseudo-class\n[win-img]: https://img.shields.io/appveyor/ci/jonathantneal/postcss-dir-pseudo-class.svg\n[win-url]: https://ci.appveyor.com/project/jonathantneal/postcss-dir-pseudo-class\n\n[Gulp PostCSS]: https://github.com/postcss/gulp-postcss\n[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss\n[PostCSS]: https://github.com/postcss/postcss\n[PostCSS Loader]: https://github.com/postcss/postcss-loader\n[PostCSS Dir Pseudo Class]: https://github.com/jonathantneal/postcss-dir-pseudo-class\n[Selectors]: https://www.w3.org/TR/selectors-4/#the-dir-pseudo\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsstools%2Fpostcss-dir-pseudo-class","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcsstools%2Fpostcss-dir-pseudo-class","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsstools%2Fpostcss-dir-pseudo-class/lists"}