useLogicalProperties (CSS)
Summary
Section titled βSummaryβ- Rule available since:
v2.5.15 - Diagnostic Category:
lint/nursery/useLogicalProperties - This rule has an unsafe fix.
- The default severity of this rule is warning.
- Sources:
- Same as
csstools/use-logical - Same as
liberty/use-logical-spec
- Same as
How to configure
Section titled βHow to configureβ{ "linter": { "rules": { "nursery": { "useLogicalProperties": "error" } } }}Description
Section titled βDescriptionβPrefer logical CSS properties over physical properties.
Physical properties such as left, margin-left, and width describe fixed directions or
dimensions. Logical properties such as inset-inline-start, margin-inline-start, and
inline-size adapt when text runs right to left or uses a vertical writing mode.
Examples
Section titled βExamplesβInvalid
Section titled βInvalidβp { margin: 1px 2px;}code-block.css:2:3 lint/nursery/useLogicalProperties FIXABLE βββββββββββββββββββββββββββββββββββββ
β Use logical CSS longhands instead of a multi-value physical shorthand.
1 β p {
> 2 β margin: 1px 2px;
β ^^^^^^
3 β }
4 β
βΉ Logical properties adapt better to different writing modes and layout directions.
βΉ Multi-value shorthands always map to physical sides.
βΉ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
βΉ Unsafe fix: Replace with margin-block and margin-inline.
2 β Β·Β·margin-block:Β·1px;Β·margin-inline:Β·2px;
β ++++++ ++++++++++++++++
p { padding: var(--spacing) 2px;}code-block.css:2:3 lint/nursery/useLogicalProperties βββββββββββββββββββββββββββββββββββββββββββββββ
β Use logical CSS longhands instead of a multi-value physical shorthand.
1 β p {
> 2 β padding: var(--spacing) 2px;
β ^^^^^^^
3 β }
4 β
βΉ Logical properties adapt better to different writing modes and layout directions.
βΉ The variable or function may supply multiple values, so check its substitution and split the shorthand manually.
βΉ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
p { margin-block-start: 1px; margin-block-end: 2px;}code-block.css:2:3 lint/nursery/useLogicalProperties FIXABLE βββββββββββββββββββββββββββββββββββββ
β These logical longhands can be combined into a shorthand.
1 β p {
> 2 β margin-block-start: 1px;
β ^^^^^^^^^^^^^^^^^^
3 β margin-block-end: 2px;
4 β }
βΉ Logical properties adapt better to different writing modes and layout directions.
βΉ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
βΉ Unsafe fix: Combine these properties as margin-block.
1 1 β p {
2 β - Β·Β·margin-block-start:Β·1px;
3 β - Β·Β·margin-block-end:Β·2px;
2 β + Β·Β·margin-block:Β·1pxΒ·2px;
4 3 β }
5 4 β
p { width: 100%;}code-block.css:2:3 lint/nursery/useLogicalProperties FIXABLE βββββββββββββββββββββββββββββββββββββ
β Use logical CSS properties over physical ones.
1 β p {
> 2 β width: 100%;
β ^^^^^
3 β }
4 β
βΉ Logical properties adapt better to different writing modes and layout directions.
βΉ Replace width with inline-size.
βΉ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
βΉ Unsafe fix: Use the logical CSS replacement.
1 1 β p {
2 β - Β·Β·width:Β·100%;
2 β + Β·Β·inline-size:Β·100%;
3 3 β }
4 4 β
p { top: 0;}code-block.css:2:3 lint/nursery/useLogicalProperties FIXABLE βββββββββββββββββββββββββββββββββββββ
β Use logical CSS properties over physical ones.
1 β p {
> 2 β top: 0;
β ^^^
3 β }
4 β
βΉ Logical properties adapt better to different writing modes and layout directions.
βΉ Replace top with inset-block-start.
βΉ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
βΉ Unsafe fix: Use the logical CSS replacement.
1 1 β p {
2 β - Β·Β·top:Β·0;
2 β + Β·Β·inset-block-start:Β·0;
3 3 β }
4 4 β
p { margin-left: 1rem;}code-block.css:2:3 lint/nursery/useLogicalProperties FIXABLE βββββββββββββββββββββββββββββββββββββ
β Use logical CSS properties over physical ones.
1 β p {
> 2 β margin-left: 1rem;
β ^^^^^^^^^^^
3 β }
4 β
βΉ Logical properties adapt better to different writing modes and layout directions.
βΉ Replace margin-left with margin-inline-start.
βΉ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
βΉ Unsafe fix: Use the logical CSS replacement.
1 1 β p {
2 β - Β·Β·margin-left:Β·1rem;
2 β + Β·Β·margin-inline-start:Β·1rem;
3 3 β }
4 4 β
p { border-left: 1px solid;}code-block.css:2:3 lint/nursery/useLogicalProperties FIXABLE βββββββββββββββββββββββββββββββββββββ
β Use logical CSS properties over physical ones.
1 β p {
> 2 β border-left: 1px solid;
β ^^^^^^^^^^^
3 β }
4 β
βΉ Logical properties adapt better to different writing modes and layout directions.
βΉ Replace border-left with border-inline-start.
βΉ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
βΉ Unsafe fix: Use the logical CSS replacement.
1 1 β p {
2 β - Β·Β·border-left:Β·1pxΒ·solid;
2 β + Β·Β·border-inline-start:Β·1pxΒ·solid;
3 3 β }
4 4 β
p { float: left;}code-block.css:2:10 lint/nursery/useLogicalProperties FIXABLE ββββββββββββββββββββββββββββββββββββ
β Use logical CSS values over physical ones.
1 β p {
> 2 β float: left;
β ^^^^
3 β }
4 β
βΉ Logical properties adapt better to different writing modes and layout directions.
βΉ Replace left with inline-start.
βΉ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
βΉ Unsafe fix: Use the logical CSS replacement.
1 1 β p {
2 β - Β·Β·float:Β·left;
2 β + Β·Β·float:Β·inline-start;
3 3 β }
4 4 β
p { text-align: right;}code-block.css:2:15 lint/nursery/useLogicalProperties FIXABLE ββββββββββββββββββββββββββββββββββββ
β Use logical CSS values over physical ones.
1 β p {
> 2 β text-align: right;
β ^^^^^
3 β }
4 β
βΉ Logical properties adapt better to different writing modes and layout directions.
βΉ Replace right with end.
βΉ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
βΉ Unsafe fix: Use the logical CSS replacement.
1 1 β p {
2 β - Β·Β·text-align:Β·right;
2 β + Β·Β·text-align:Β·end;
3 3 β }
4 4 β
p { justify-content: left;}code-block.css:2:20 lint/nursery/useLogicalProperties ββββββββββββββββββββββββββββββββββββββββββββββ
β Use logical CSS values over physical ones.
1 β p {
> 2 β justify-content: left;
β ^^^^
3 β }
4 β
βΉ Logical properties adapt better to different writing modes and layout directions.
βΉ Choose a logical alignment value based on the layout axis.
βΉ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
p { inline-size: anchor-size(width);}code-block.css:2:28 lint/nursery/useLogicalProperties FIXABLE ββββββββββββββββββββββββββββββββββββ
β Use a logical size in anchor-size().
1 β p {
> 2 β inline-size: anchor-size(width);
β ^^^^^
3 β }
4 β
βΉ Logical properties adapt better to different writing modes and layout directions.
βΉ Replace width with self-inline.
βΉ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
βΉ Unsafe fix: Use the logical CSS replacement.
1 1 β p {
2 β - Β·Β·inline-size:Β·anchor-size(width);
2 β + Β·Β·inline-size:Β·anchor-size(self-inline);
3 3 β }
4 4 β
p { inset-block-start: anchor(bottom);}code-block.css:2:29 lint/nursery/useLogicalProperties FIXABLE ββββββββββββββββββββββββββββββββββββ
β Use a logical side in anchor().
1 β p {
> 2 β inset-block-start: anchor(bottom);
β ^^^^^^
3 β }
4 β
βΉ Logical properties adapt better to different writing modes and layout directions.
βΉ Replace bottom with end.
βΉ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
βΉ Unsafe fix: Use the logical CSS replacement.
1 1 β p {
2 β - Β·Β·inset-block-start:Β·anchor(bottom);
2 β + Β·Β·inset-block-start:Β·anchor(end);
3 3 β }
4 4 β
p { inline-size: 100%; inset-block-start: 0; margin-inline-start: 1rem; border-inline-start: 1px solid; float: inline-start; text-align: end; justify-content: start; inline-size: anchor-size(self-inline); block-size: anchor-size(self-block); inset-block-start: anchor(end);}A multi-value physical shorthand always applies values to physical sides. Use separate
logical properties when values differ by axis. A four-sided shorthand is only equivalent
when all four values are identical, so the rule does not combine differing axis values
into one. Shorthands containing var(), env(), attr(), if(), or a SCSS variable are
reported without an automatic fix because these values can expand to multiple values. Check the
substitution before splitting the shorthand manually.
p { margin: 1px; margin: var(--spacing); margin-block: 1px 2px; color: red;}$spacing: 1rem;
p { margin: $spacing 2px;}code-block.scss:4:3 lint/nursery/useLogicalProperties ββββββββββββββββββββββββββββββββββββββββββββββ
β Use logical CSS longhands instead of a multi-value physical shorthand.
3 β p {
> 4 β margin: $spacing 2px;
β ^^^^^^
5 β }
6 β
βΉ Logical properties adapt better to different writing modes and layout directions.
βΉ The variable or function may supply multiple values, so check its substitution and split the shorthand manually.
βΉ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
Options
Section titled βOptionsβdirection
Section titled βdirectionβSets the text direction used to replace left and right properties and to order the inline
values when splitting a four-value physical shorthand. Use "ltr" for left-to-right text
or "rtl" for right-to-left text. Defaults to "ltr".
{ "linter": { "rules": { "nursery": { "useLogicalProperties": { "level": "on", "options": { "direction": "rtl" } } } } }}Invalid
Section titled βInvalidβp { margin-left: 1rem;}code-block.css:2:3 lint/nursery/useLogicalProperties FIXABLE βββββββββββββββββββββββββββββββββββββ
β Use logical CSS properties over physical ones.
1 β p {
> 2 β margin-left: 1rem;
β ^^^^^^^^^^^
3 β }
4 β
βΉ Logical properties adapt better to different writing modes and layout directions.
βΉ Replace margin-left with margin-inline-end.
βΉ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
βΉ Unsafe fix: Use the logical CSS replacement.
1 1 β p {
2 β - Β·Β·margin-left:Β·1rem;
2 β + Β·Β·margin-inline-end:Β·1rem;
3 3 β }
4 4 β
p { margin: 1px 2px 3px 4px;}code-block.css:2:3 lint/nursery/useLogicalProperties FIXABLE βββββββββββββββββββββββββββββββββββββ
β Use logical CSS longhands instead of a multi-value physical shorthand.
1 β p {
> 2 β margin: 1px 2px 3px 4px;
β ^^^^^^
3 β }
4 β
βΉ Logical properties adapt better to different writing modes and layout directions.
βΉ Multi-value shorthands always map to physical sides.
βΉ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
βΉ Unsafe fix: Replace with margin-block and margin-inline.
1 1 β p {
2 β - Β·Β·margin:Β·1pxΒ·2pxΒ·3pxΒ·4px;
2 β + Β·Β·margin-block:Β·1pxΒ·3px;Β·margin-inline:Β·2pxΒ·4px;
3 3 β }
4 4 β
p { margin-inline-end: 1rem;}Related links
Section titled βRelated linksβCopyright (c) 2023-present Biome Developers and Contributors.