1 | # length-zero-no-unit
|
2 |
|
3 | Disallow units for zero lengths.
|
4 |
|
5 |
|
6 | ```css
|
7 | a { top: 0px; }
|
8 | /** ↑↑
|
9 | * This zero and this type of length unit */
|
10 | ```
|
11 |
|
12 | _Lengths_ refer to distance measurements. A length is a _dimension_, which is a _number_ immediately followed by a _unit identifier_. However, for zero lengths the unit identifier is optional. The length units are: `em`, `ex`, `ch`, `vw`, `vh`, `cm`, `mm`, `in`, `pt`, `pc`, `px`, `rem`, `vmin`, and `vmax`.
|
13 |
|
14 | This rule ignores lengths within math functions (e.g. `calc`) in favor of the [`function-calc-no-invalid`](../function-calc-no-invalid/README.md) rule.
|
15 |
|
16 | The [`fix` option](../../../docs/user-guide/usage/options.md#fix) can automatically fix all of the problems reported by this rule.
|
17 |
|
18 | ## Options
|
19 |
|
20 | ### `true`
|
21 |
|
22 | The following patterns are considered violations:
|
23 |
|
24 |
|
25 | ```css
|
26 | a { top: 0px }
|
27 | ```
|
28 |
|
29 |
|
30 | ```css
|
31 | a { top: 0.000em }
|
32 | ```
|
33 |
|
34 | The following patterns are _not_ considered violations:
|
35 |
|
36 |
|
37 | ```css
|
38 | a { top: 0 } /* no unit */
|
39 | ```
|
40 |
|
41 |
|
42 | ```css
|
43 | a { transition-delay: 0s; } /* dimension */
|
44 | ```
|
45 |
|
46 |
|
47 | ```css
|
48 | a { top: 2in; }
|
49 | ```
|
50 |
|
51 |
|
52 | ```css
|
53 | a { top: 1.001vh }
|
54 | ```
|
55 |
|
56 | ## Optional secondary options
|
57 |
|
58 | ### `ignore: ["custom-properties"]`
|
59 |
|
60 | #### `"custom-properties"`
|
61 |
|
62 | Ignore units for zero length in custom properties.
|
63 |
|
64 | The following pattern is _not_ considered a violation:
|
65 |
|
66 |
|
67 | ```css
|
68 | a { --x: 0px; }
|
69 | ```
|