CSS Minify Tests

Correctness tests for CSS minification tools. Each test provides a CSS input and a single canonical minified output. A tool passes if its output matches exactly.

Contribute tests on GitHub

Minifiers tested:

Summary

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
v5.3.3v0.0.40v0.0.60v9.9.0v5.0.5v0.28.2v1.33.0v1.108.2
anchor 2 / 5 1 / 5 5 / 5 2 / 5 2 / 5 1 / 5 0 / 5 1 / 5
calc 2 / 41 35 / 41 41 / 41 8 / 41 3 / 41 22 / 41 34 / 41 22 / 41
calc-advanced 0 / 10 2 / 10 10 / 10 0 / 10 0 / 10 1 / 10 0 / 10 4 / 10
charset 5 / 13 12 / 13 13 / 13 6 / 13 2 / 13 0 / 13 8 / 13 7 / 13
color-rounding 0 / 16 15 / 16 16 / 16 1 / 16 0 / 16 1 / 16 1 / 16 0 / 16
colors 27 / 72 63 / 72 72 / 72 42 / 72 29 / 72 38 / 72 48 / 72 25 / 72
combined 0 / 12 0 / 12 12 / 12 1 / 12 1 / 12 0 / 12 0 / 12 0 / 12
comments 5 / 7 3 / 7 7 / 7 4 / 7 4 / 7 4 / 7 3 / 7 4 / 7
container 2 / 7 3 / 7 7 / 7 1 / 7 1 / 7 1 / 7 5 / 7 0 / 7
counter-style 1 / 3 3 / 3 3 / 3 1 / 3 3 / 3 0 / 3 1 / 3 1 / 3
duplicates 20 / 27 6 / 27 27 / 27 15 / 27 20 / 27 12 / 27 14 / 27 6 / 27
empty-rules 7 / 7 7 / 7 7 / 7 7 / 7 7 / 7 6 / 7 6 / 7 6 / 7
escaping 3 / 15 13 / 15 15 / 15 3 / 15 4 / 15 12 / 15 14 / 15 11 / 15
font-face 3 / 13 2 / 13 13 / 13 12 / 13 3 / 13 4 / 13 5 / 13 2 / 13
gradients 2 / 14 2 / 14 14 / 14 4 / 14 2 / 14 3 / 14 6 / 14 0 / 14
idempotency 0 / 1 0 / 1 1 / 1 1 / 1 0 / 1 0 / 1 0 / 1 0 / 1
import 0 / 6 0 / 6 6 / 6 0 / 6 0 / 6 0 / 6 0 / 6 4 / 6
initial 0 / 9 0 / 9 9 / 9 7 / 9 0 / 9 0 / 9 0 / 9 0 / 9
keyframes 0 / 2 0 / 2 2 / 2 2 / 2 2 / 2 2 / 2 2 / 2 0 / 2
lang 0 / 8 0 / 8 8 / 8 1 / 8 1 / 8 0 / 8 3 / 8 0 / 8
layer 1 / 4 1 / 4 4 / 4 0 / 4 1 / 4 1 / 4 3 / 4 1 / 4
media 1 / 22 9 / 22 22 / 22 10 / 22 1 / 22 10 / 22 2 / 22 2 / 22
merging 24 / 38 11 / 38 38 / 38 30 / 38 22 / 38 12 / 38 20 / 38 7 / 38
nesting 0 / 53 12 / 53 53 / 53 12 / 53 0 / 53 16 / 53 6 / 53 8 / 53
page 3 / 4 4 / 4 4 / 4 3 / 4 3 / 4 3 / 4 3 / 4 2 / 4
property 4 / 9 4 / 9 9 / 9 5 / 9 4 / 9 0 / 9 4 / 9 2 / 9
scope 1 / 3 3 / 3 3 / 3 1 / 3 1 / 3 2 / 3 1 / 3 0 / 3
selectors 12 / 21 6 / 21 21 / 21 14 / 21 9 / 21 12 / 21 19 / 21 6 / 21
selectors-advanced 9 / 35 8 / 35 35 / 35 11 / 35 11 / 35 11 / 35 11 / 35 8 / 35
shorthand-values 15 / 26 19 / 26 26 / 26 19 / 26 13 / 26 13 / 26 23 / 26 2 / 26
shorthands 9 / 60 11 / 60 60 / 60 21 / 60 7 / 60 6 / 60 27 / 60 0 / 60
shorthands-unsafe 7 / 11 8 / 11 11 / 11 8 / 11 5 / 11 4 / 11 6 / 11 3 / 11
starting-style 0 / 2 2 / 2 2 / 2 2 / 2 2 / 2 2 / 2 1 / 2 2 / 2
supports 3 / 7 3 / 7 7 / 7 5 / 7 3 / 7 1 / 7 2 / 7 1 / 7
svg 2 / 9 4 / 9 9 / 9 4 / 9 4 / 9 4 / 9 2 / 9 4 / 9
transforms 0 / 11 0 / 11 11 / 11 6 / 11 0 / 11 8 / 11 11 / 11 0 / 11
values 17 / 67 30 / 67 67 / 67 46 / 67 21 / 67 22 / 67 38 / 67 17 / 67
vendors 1 / 9 0 / 9 9 / 9 3 / 9 1 / 9 0 / 9 6 / 9 0 / 9
whitespace 13 / 21 19 / 21 21 / 21 13 / 21 16 / 21 13 / 21 17 / 21 13 / 21
zero-units 10 / 13 12 / 13 13 / 13 10 / 13 10 / 13 9 / 13 13 / 13 8 / 13
Total 211 / 713 333 / 713 713 / 713 341 / 713 218 / 713 256 / 713 365 / 713 179 / 713
Total (%) 29.59% 46.7% 100% 47.82% 30.57% 35.9% 51.19% 25.1%
Total Duration 71ms 210ms 189ms 632ms 79ms 361ms 11ms 351ms

Historical Trends

Passing testsTests passed by each minifier across 95 recorded runs.
Date
Feb 18, 2026100.0% (371/371, v0.0.2)70.4% (261/371, v1.31.1)54.2% (201/371, v7.1.2)30.7% (114/371, v0.0.17)47.7% (177/371, v0.27.3)38.8% (144/371, v5.0.5)40.7% (151/371, v5.3.3)31.8% (118/371, v1.99.0)
Mar 8, 2026100.0% (371/371, v0.0.2)70.4% (261/371, v1.31.1)54.2% (201/371, v7.1.2)33.4% (124/371, v0.0.18)47.7% (177/371, v0.27.3)38.8% (144/371, v5.0.5)40.7% (151/371, v5.3.3)31.8% (118/371, v1.99.0)
Mar 8, 2026100.0% (384/384, v0.0.2)69.0% (265/384, v1.31.1)52.6% (202/384, v7.1.2)33.6% (129/384, v0.0.18)46.9% (180/384, v0.27.3)38.3% (147/384, v5.0.5)39.6% (152/384, v5.3.3)30.7% (118/384, v1.99.0)
Mar 9, 2026100.0% (384/384, v0.0.2)69.3% (266/384, v1.32.0)52.6% (202/384, v7.1.3)33.6% (129/384, v0.0.18)46.9% (180/384, v0.27.3)38.3% (147/384, v5.0.5)39.6% (152/384, v5.3.3)30.7% (118/384, v1.99.0)
Mar 9, 2026100.0% (387/387, v0.0.2)70.0% (271/387, v1.32.0)52.5% (203/387, v7.1.3)34.1% (132/387, v0.0.18)46.8% (181/387, v0.27.3)38.0% (147/387, v5.0.5)39.3% (152/387, v5.3.3)31.0% (120/387, v1.99.0)
Mar 9, 2026100.0% (389/389, v0.0.2)70.2% (273/389, v1.32.0)52.2% (203/389, v7.1.3)33.9% (132/389, v0.0.18)46.8% (182/389, v0.27.3)37.8% (147/389, v5.0.5)39.1% (152/389, v5.3.3)30.8% (120/389, v1.99.0)
Mar 16, 2026100.0% (389/389, v0.0.2)70.2% (273/389, v1.32.0)52.2% (203/389, v7.1.3)33.9% (132/389, v0.0.18)46.8% (182/389, v0.27.4)37.8% (147/389, v5.0.5)39.1% (152/389, v5.3.3)30.8% (120/389, v1.99.0)
Mar 24, 2026100.0% (396/396, v0.0.2)68.9% (273/396, v1.32.0)51.3% (203/396, v7.1.3)33.3% (132/396, v0.0.18)46.0% (182/396, v0.27.4)37.1% (147/396, v5.0.5)38.4% (152/396, v5.3.3)30.3% (120/396, v1.99.0)
Mar 30, 2026100.0% (396/396, v0.0.2)68.9% (273/396, v1.32.0)51.3% (203/396, v7.1.3)34.8% (138/396, v0.0.19)46.0% (182/396, v0.27.4)37.1% (147/396, v5.0.5)38.4% (152/396, v5.3.3)30.3% (120/396, v1.99.0)
Apr 6, 2026100.0% (396/396, v0.0.2)68.9% (273/396, v1.32.0)51.3% (203/396, v7.1.4)34.8% (138/396, v0.0.20)46.0% (182/396, v0.27.7)37.1% (147/396, v5.0.5)38.4% (152/396, v5.3.3)30.3% (120/396, v1.99.0)
Apr 14, 2026100.0% (396/396, v0.0.2)68.9% (273/396, v1.32.0)51.3% (203/396, v7.1.4)34.8% (138/396, v0.0.20)46.0% (182/396, v0.28.0)37.1% (147/396, v5.0.5)38.4% (152/396, v5.3.3)30.3% (120/396, v1.99.0)
Apr 20, 2026100.0% (396/396, v0.0.2)68.9% (273/396, v1.32.0)51.3% (203/396, v7.1.5)34.8% (138/396, v0.0.20)46.0% (182/396, v0.28.0)37.1% (147/396, v5.0.5)38.4% (152/396, v5.3.3)30.3% (120/396, v1.99.0)
Apr 27, 2026100.0% (396/396, v0.0.2)68.9% (273/396, v1.32.0)51.5% (204/396, v7.1.7)34.8% (138/396, v0.0.20)46.0% (182/396, v0.28.0)37.1% (147/396, v5.0.5)38.4% (152/396, v5.3.3)30.3% (120/396, v1.99.0)
May 4, 2026100.0% (396/396, v0.0.2)68.9% (273/396, v1.32.0)51.5% (204/396, v7.1.8)34.8% (138/396, v0.0.20)46.0% (182/396, v0.28.0)37.1% (147/396, v5.0.5)38.4% (152/396, v5.3.3)30.3% (120/396, v1.99.0)
May 6, 2026100.0% (396/396, v0.0.2)68.9% (273/396, v1.32.0)52.8% (209/396, v8.0.0)34.8% (138/396, v0.0.20)46.0% (182/396, v0.28.0)37.1% (147/396, v5.0.5)38.4% (152/396, v5.3.3)30.3% (120/396, v1.99.0)
May 9, 2026100.0% (398/398, v0.0.2)68.6% (273/398, v1.32.0)52.3% (208/398, v8.0.0)35.2% (140/398, v0.0.20)46.0% (183/398, v0.28.0)36.9% (147/398, v5.0.5)37.9% (151/398, v5.3.3)30.2% (120/398, v1.99.0)
May 11, 2026100.0% (398/398, v0.0.2)68.3% (272/398, v1.32.0)52.0% (207/398, v8.0.1)35.7% (142/398, v0.0.21)45.7% (182/398, v0.28.0)37.2% (148/398, v5.0.5)37.7% (150/398, v5.3.3)29.9% (119/398, v1.99.0)
May 13, 2026100.0% (398/398, v0.0.2)68.3% (272/398, v1.32.0)52.0% (207/398, v8.0.1)35.7% (142/398, v0.0.21)45.7% (182/398, v0.28.0)37.2% (148/398, v5.0.5)37.7% (150/398, v5.3.3)29.9% (119/398, v1.99.0)
May 15, 2026100.0% (398/398, v0.0.2)68.6% (273/398, v1.32.0)52.0% (207/398, v8.0.1)35.7% (142/398, v0.0.21)45.7% (182/398, v0.28.0)37.2% (148/398, v5.0.5)37.4% (149/398, v5.3.3)29.9% (119/398, v1.99.0)
May 16, 2026100.0% (398/398, v0.0.2)68.6% (273/398, v1.32.0)52.3% (208/398, v8.0.1)35.7% (142/398, v0.0.21)46.0% (183/398, v0.28.0)37.4% (149/398, v5.0.5)37.7% (150/398, v5.3.3)30.2% (120/398, v1.99.0)
May 18, 2026100.0% (399/399, v0.0.2)68.9% (275/399, v1.32.0)52.4% (209/399, v8.0.1)35.6% (142/399, v0.0.21)46.4% (185/399, v0.28.0)37.8% (151/399, v5.0.5)37.6% (150/399, v5.3.3)30.1% (120/399, v1.99.0)
May 18, 2026100.0% (398/398, v0.0.2)68.8% (274/398, v1.32.0)52.3% (208/398, v8.0.1)35.7% (142/398, v0.0.21)46.2% (184/398, v0.28.0)37.7% (150/398, v5.0.5)37.7% (150/398, v5.3.3)30.2% (120/398, v1.99.0)
May 18, 2026100.0% (402/402, v0.0.2)69.2% (278/402, v1.32.0)52.7% (212/402, v8.0.1)36.1% (145/402, v0.0.21)46.8% (188/402, v0.28.0)38.3% (154/402, v5.0.5)38.1% (153/402, v5.3.3)30.6% (123/402, v1.99.0)
May 24, 2026100.0% (402/402, v0.0.2)69.2% (278/402, v1.32.0)52.7% (212/402, v8.0.1)39.3% (158/402, v0.0.22)46.8% (188/402, v0.28.0)38.3% (154/402, v5.0.5)38.1% (153/402, v5.3.3)30.6% (123/402, v1.99.0)
May 24, 2026100.0% (403/403, v0.0.2)69.2% (279/403, v1.32.0)52.6% (212/403, v8.0.1)39.2% (158/403, v0.0.22)46.7% (188/403, v0.28.0)38.2% (154/403, v5.0.5)38.0% (153/403, v5.3.3)30.5% (123/403, v1.99.0)
May 25, 2026100.0% (403/403, v0.0.2)69.2% (279/403, v1.32.0)52.6% (212/403, v8.0.1)41.2% (166/403, v0.0.23)46.7% (188/403, v0.28.0)38.2% (154/403, v5.0.5)38.0% (153/403, v5.3.3)30.5% (123/403, v1.99.0)
May 29, 2026100.0% (407/407, v0.0.2)68.6% (279/407, v1.32.0)52.1% (212/407, v8.0.1)40.8% (166/407, v0.0.23)46.4% (189/407, v0.28.0)37.8% (154/407, v5.0.5)37.6% (153/407, v5.3.3)30.2% (123/407, v1.99.0)
Jun 1, 2026100.0% (407/407, v0.0.2)68.6% (279/407, v1.32.0)52.1% (212/407, v8.0.1)40.8% (166/407, v0.0.23)46.4% (189/407, v0.28.0)37.8% (154/407, v5.0.5)37.6% (153/407, v5.3.3)30.2% (123/407, v1.99.0)
Jun 1, 2026100.0% (410/410, v0.0.2)68.0% (279/410, v1.32.0)52.0% (213/410, v8.0.1)40.7% (167/410, v0.0.23)46.3% (190/410, v0.28.0)37.8% (155/410, v5.0.5)37.3% (153/410, v5.3.3)30.0% (123/410, v1.99.0)
Jun 2, 2026100.0% (410/410, v0.0.3)68.0% (279/410, v1.32.0)52.0% (213/410, v8.0.1)40.7% (167/410, v0.0.23)46.3% (190/410, v0.28.0)37.8% (155/410, v5.0.5)37.3% (153/410, v5.3.3)30.0% (123/410, v1.100.0)
Jun 8, 2026100.0% (410/410, v0.0.3)68.0% (279/410, v1.32.0)52.0% (213/410, v8.0.1)41.7% (171/410, v0.0.24)46.3% (190/410, v0.28.0)37.8% (155/410, v5.0.5)37.3% (153/410, v5.3.3)30.0% (123/410, v1.100.0)
Jun 9, 2026100.0% (410/410, v0.0.4)68.0% (279/410, v1.32.0)52.0% (213/410, v8.0.1)41.7% (171/410, v0.0.24)46.3% (190/410, v0.28.0)37.8% (155/410, v5.0.5)37.3% (153/410, v5.3.3)30.0% (123/410, v1.100.0)
Jun 17, 2026100.0% (412/412, v0.0.5)68.2% (281/412, v1.32.0)51.9% (214/412, v8.0.1)41.7% (172/412, v0.0.24)46.4% (191/412, v0.28.0)37.9% (156/412, v5.0.5)37.4% (154/412, v5.3.3)30.1% (124/412, v1.100.0)
Jun 19, 2026100.0% (412/412, v0.0.5)68.2% (281/412, v1.32.0)51.9% (214/412, v8.0.2)41.7% (172/412, v0.0.25)46.4% (191/412, v0.28.1)37.9% (156/412, v5.0.5)37.4% (154/412, v5.3.3)30.3% (125/412, v1.101.0)
Jun 21, 2026100.0% (412/412, v0.0.5)68.2% (281/412, v1.32.0)51.9% (214/412, v8.0.2)41.3% (170/412, v0.0.26)46.4% (191/412, v0.28.1)37.9% (156/412, v5.0.5)37.4% (154/412, v5.3.3)30.3% (125/412, v1.101.0)
Jun 21, 2026100.0% (413/413, v0.0.6)68.0% (281/413, v1.32.0)51.8% (214/413, v8.0.2)41.2% (170/413, v0.0.26)46.2% (191/413, v0.28.1)37.8% (156/413, v5.0.5)37.3% (154/413, v5.3.3)30.3% (125/413, v1.101.0)
Jun 21, 2026100.0% (415/415, v0.0.6)68.2% (283/415, v1.32.0)52.0% (216/415, v8.0.2)41.0% (170/415, v0.0.26)46.5% (193/415, v0.28.1)38.1% (158/415, v5.0.5)37.6% (156/415, v5.3.3)30.6% (127/415, v1.101.0)
Jun 22, 2026100.0% (422/422, v0.0.7)67.1% (283/422, v1.32.0)51.2% (216/422, v8.0.2)40.3% (170/422, v0.0.26)45.7% (193/422, v0.28.1)37.4% (158/422, v5.0.5)37.0% (156/422, v5.3.3)30.1% (127/422, v1.101.0)
Jun 25, 2026100.0% (427/427, v0.0.8)66.7% (285/427, v1.32.0)51.1% (218/427, v8.0.2)40.3% (172/427, v0.0.26)45.7% (195/427, v0.28.1)37.5% (160/427, v5.0.5)37.0% (158/427, v5.3.3)30.2% (129/427, v1.101.0)
Jul 2, 2026100.0% (440/440, v0.0.10)66.6% (293/440, v1.32.0)50.2% (221/440, v8.0.2)39.5% (174/440, v0.0.26)44.8% (197/440, v0.28.1)37.0% (163/440, v5.0.5)36.6% (161/440, v5.3.3)29.8% (131/440, v1.101.0)
Jul 3, 2026100.0% (438/438, v0.0.10)66.4% (291/438, v1.32.0)50.2% (220/438, v8.0.2)39.7% (174/438, v0.0.26)44.5% (195/438, v0.28.1)36.8% (161/438, v5.0.5)36.3% (159/438, v5.3.3)29.5% (129/438, v1.101.0)
Jul 4, 2026100.0% (448/448, v0.0.11)65.8% (295/448, v1.32.0)49.3% (221/448, v8.0.2)39.3% (176/448, v0.0.26)43.8% (196/448, v0.28.1)36.8% (165/448, v5.0.5)36.8% (165/448, v5.3.3)29.2% (131/448, v1.101.0)
Jul 6, 2026100.0% (455/455, v0.0.12)65.1% (296/455, v1.32.0)49.0% (223/455, v8.0.2)38.7% (176/455, v0.0.27)43.3% (197/455, v0.28.1)36.3% (165/455, v5.0.5)36.3% (165/455, v5.3.3)28.8% (131/455, v1.101.0)
Jul 16, 2026100.0% (455/455, v0.0.13)65.1% (296/455, v1.32.0)49.0% (223/455, v8.0.2)38.7% (176/455, v0.0.27)43.3% (197/455, v0.28.1)36.3% (165/455, v5.0.5)36.3% (165/455, v5.3.3)28.8% (131/455, v1.101.0)
Jul 17, 2026100.0% (457/457, v0.0.14)64.8% (296/457, v1.32.0)49.0% (224/457, v8.0.2)38.5% (176/457, v0.0.27)43.1% (197/457, v0.28.1)35.9% (164/457, v5.0.5)35.9% (164/457, v5.3.3)28.4% (130/457, v1.101.0)
Jul 18, 2026100.0% (461/461, v0.0.15)64.2% (296/461, v1.32.0)48.6% (224/461, v8.0.2)38.2% (176/461, v0.0.27)42.7% (197/461, v0.28.1)35.6% (164/461, v5.0.5)35.6% (164/461, v5.3.3)28.2% (130/461, v1.101.0)
Jul 18, 2026100.0% (464/464, v0.0.16)63.8% (296/464, v1.32.0)48.7% (226/464, v8.0.2)38.1% (177/464, v0.0.27)42.5% (197/464, v0.28.1)35.6% (165/464, v5.0.5)35.6% (165/464, v5.3.3)28.2% (131/464, v1.101.0)
Jul 24, 2026100.0% (464/464, v0.0.16)64.4% (299/464, v1.33.0)48.7% (226/464, v8.0.2)38.4% (178/464, v0.0.27)42.7% (198/464, v0.28.1)35.8% (166/464, v5.0.5)35.6% (165/464, v5.3.3)28.2% (131/464, v1.101.3)
Jul 25, 2026100.0% (464/464, v0.0.17)64.4% (299/464, v1.33.0)48.7% (226/464, v8.0.2)38.4% (178/464, v0.0.27)42.7% (198/464, v0.28.1)35.8% (166/464, v5.0.5)35.6% (165/464, v5.3.3)28.2% (131/464, v1.101.3)
Jul 25, 2026100.0% (464/464, v0.0.17)64.4% (299/464, v1.33.0)48.7% (226/464, v8.0.2)38.8% (180/464, v0.0.28)42.7% (198/464, v0.28.1)35.8% (166/464, v5.0.5)35.6% (165/464, v5.3.3)28.2% (131/464, v1.101.3)
Jul 26, 2026100.0% (482/482, v0.0.17)62.7% (302/482, v1.33.0)48.3% (233/482, v8.0.2)38.0% (183/482, v0.0.28)42.3% (204/482, v0.28.1)34.6% (167/482, v5.0.5)34.2% (165/482, v5.3.3)27.6% (133/482, v1.102.0)
Jul 29, 2026100.0% (496/496, v0.0.18)63.1% (313/496, v1.33.0)48.4% (240/496, v8.0.2)38.9% (193/496, v0.0.28)42.5% (211/496, v0.28.1)34.7% (172/496, v5.0.5)34.3% (170/496, v5.3.3)28.2% (140/496, v1.102.0)
Aug 4, 2026100.0% (496/496, v0.0.19)63.1% (313/496, v1.33.0)48.4% (240/496, v8.0.2)38.9% (193/496, v0.0.28)42.5% (211/496, v0.28.1)34.7% (172/496, v5.0.5)34.3% (170/496, v5.3.3)28.2% (140/496, v1.102.0)
Aug 9, 2026100.0% (504/504, v0.0.20)62.5% (315/504, v1.33.0)47.8% (241/504, v8.0.4)38.9% (196/504, v0.0.28)42.7% (215/504, v0.28.2)34.3% (173/504, v5.0.5)33.9% (171/504, v5.3.3)28.0% (141/504, v1.102.0)
Aug 12, 2026100.0% (504/504, v0.0.20)62.5% (315/504, v1.33.0)48.0% (242/504, v8.0.5)38.9% (196/504, v0.0.28)42.7% (215/504, v0.28.2)34.3% (173/504, v5.0.5)33.9% (171/504, v5.3.3)28.0% (141/504, v1.102.0)
Aug 13, 2026100.0% (511/511, v0.0.21)61.1% (312/511, v1.33.0)47.7% (244/511, v8.0.5)39.7% (203/511, v0.0.28)43.2% (221/511, v0.28.2)34.2% (175/511, v5.0.5)33.7% (172/511, v5.3.3)28.0% (143/511, v1.102.0)
Aug 20, 202699.8% (510/511, v0.0.21)61.1% (312/511, v1.33.0)47.7% (244/511, v8.0.5)39.9% (204/511, v0.0.29)43.2% (221/511, v0.28.2)34.2% (175/511, v5.0.5)33.5% (171/511, v5.3.3)28.0% (143/511, v1.102.0)
Aug 20, 202699.2% (511/515, v0.0.21)61.2% (315/515, v1.33.0)48.0% (247/515, v8.0.5)39.6% (204/515, v0.0.29)42.9% (221/515, v0.28.2)34.0% (175/515, v5.0.5)33.4% (172/515, v5.3.3)28.3% (146/515, v1.102.0)
Aug 21, 202698.8% (512/518, v0.0.21)61.4% (318/518, v1.33.0)48.1% (249/518, v8.0.5)39.4% (204/518, v0.0.29)42.7% (221/518, v0.28.2)33.8% (175/518, v5.0.5)33.4% (173/518, v5.3.3)28.6% (148/518, v1.102.0)
Aug 22, 202699.4% (517/520, v0.0.24)60.6% (315/520, v1.33.0)47.7% (248/520, v8.0.7)39.0% (203/520, v0.0.29)42.5% (221/520, v0.28.2)33.5% (174/520, v5.0.5)33.3% (173/520, v5.3.3)28.3% (147/520, v1.103.1)
Aug 23, 202699.4% (517/520, v0.0.24)60.6% (315/520, v1.33.0)47.7% (248/520, v8.0.7)43.8% (228/520, v0.0.30)42.5% (221/520, v0.28.2)33.5% (174/520, v5.0.5)33.3% (173/520, v5.3.3)28.3% (147/520, v1.103.1)
Aug 24, 202699.4% (517/520, v0.0.25)60.6% (315/520, v1.33.0)47.9% (249/520, v8.0.8)43.8% (228/520, v0.0.30)42.5% (221/520, v0.28.2)33.5% (174/520, v5.0.5)33.3% (173/520, v5.3.3)28.3% (147/520, v1.103.1)
Aug 24, 202698.7% (517/524, v0.0.25)60.1% (315/524, v1.33.0)47.7% (250/524, v8.0.8)43.5% (228/524, v0.0.30)42.2% (221/524, v0.28.2)33.2% (174/524, v5.0.5)33.0% (173/524, v5.3.3)28.1% (147/524, v1.103.1)
Aug 24, 2026100.0% (524/524, v0.0.26)59.9% (314/524, v1.33.0)47.7% (250/524, v8.0.8)43.5% (228/524, v0.0.30)42.2% (221/524, v0.28.2)33.2% (174/524, v5.0.5)33.0% (173/524, v5.3.3)28.1% (147/524, v1.103.1)
Aug 25, 2026100.0% (529/529, v0.0.27)59.4% (314/529, v1.33.0)47.6% (252/529, v8.0.8)43.3% (229/529, v0.0.30)42.2% (223/529, v0.28.2)33.5% (177/529, v5.0.5)33.1% (175/529, v5.3.3)28.2% (149/529, v1.103.1)
Aug 28, 202699.8% (532/533, v0.0.28)58.3% (311/533, v1.33.0)48.4% (258/533, v9.0.1)48.2% (257/533, v0.0.31)41.8% (223/533, v0.28.2)33.6% (179/533, v5.0.5)32.5% (173/533, v5.3.3)27.8% (148/533, v1.103.1)
Aug 30, 2026100.0% (537/537, v0.0.29)58.5% (314/537, v1.33.0)48.8% (262/537, v9.0.1)48.6% (261/537, v0.0.31)42.1% (226/537, v0.28.2)34.1% (183/537, v5.0.5)33.0% (177/537, v5.3.3)28.1% (151/537, v1.103.1)
Aug 31, 2026100.0% (541/541, v0.0.30)58.2% (315/541, v1.33.0)48.6% (263/541, v9.0.1)48.4% (262/541, v0.0.31)42.0% (227/541, v0.28.2)34.0% (184/541, v5.0.5)33.3% (180/541, v5.3.3)27.7% (150/541, v1.103.1)
Aug 31, 2026100.0% (541/541, v0.0.32)58.2% (315/541, v1.33.0)48.6% (263/541, v9.0.1)48.4% (262/541, v0.0.31)42.0% (227/541, v0.28.2)34.0% (184/541, v5.0.5)33.3% (180/541, v5.3.3)27.7% (150/541, v1.103.1)
Sep 3, 2026100.0% (541/541, v0.0.33)58.2% (315/541, v1.33.0)48.6% (263/541, v9.0.2)48.4% (262/541, v0.0.31)42.0% (227/541, v0.28.2)34.0% (184/541, v5.0.5)33.3% (180/541, v5.3.3)27.7% (150/541, v1.103.1)
Sep 4, 2026100.0% (541/541, v0.0.34)58.4% (316/541, v1.33.0)48.8% (264/541, v9.0.2)48.6% (263/541, v0.0.31)42.1% (228/541, v0.28.2)34.2% (185/541, v5.0.5)33.5% (181/541, v5.3.3)27.9% (151/541, v1.104.0)
Sep 5, 2026100.0% (548/548, v0.0.35)57.8% (317/548, v1.33.0)48.2% (264/548, v9.0.2)48.0% (263/548, v0.0.31)41.6% (228/548, v0.28.2)33.9% (186/548, v5.0.5)33.2% (182/548, v5.3.3)27.6% (151/548, v1.104.0)
Sep 6, 2026100.0% (553/553, v0.0.36)57.5% (318/553, v1.33.0)48.3% (267/553, v9.0.3)48.3% (267/553, v0.0.31)41.8% (231/553, v0.28.2)34.0% (188/553, v5.0.5)33.3% (184/553, v5.3.3)27.7% (153/553, v1.104.0)
Sep 10, 2026100.0% (556/556, v0.0.37)57.7% (321/556, v1.33.0)48.7% (271/556, v9.0.4)48.0% (267/556, v0.0.31)41.9% (233/556, v0.28.2)34.4% (191/556, v5.0.5)33.3% (185/556, v5.3.3)27.5% (153/556, v1.104.0)
Sep 14, 2026100.0% (574/574, v0.0.38)56.3% (323/574, v1.33.0)48.4% (278/574, v9.0.4)46.3% (266/574, v0.0.31)40.8% (234/574, v0.28.2)33.1% (190/574, v5.0.5)32.2% (185/574, v5.3.3)26.8% (154/574, v1.104.1)
Sep 17, 2026100.0% (582/582, v0.0.39)55.5% (323/582, v1.33.0)44.7% (260/582, v9.0.5)45.7% (266/582, v0.0.31)40.4% (235/582, v0.28.2)32.6% (190/582, v5.0.5)31.8% (185/582, v5.3.3)26.5% (154/582, v1.104.1)
Sep 21, 2026100.0% (582/582, v0.0.39)55.5% (323/582, v1.33.0)44.7% (260/582, v9.0.5)45.7% (266/582, v0.0.33)40.4% (235/582, v0.28.2)32.6% (190/582, v5.0.5)31.8% (185/582, v5.3.3)26.5% (154/582, v1.104.1)
Sep 25, 2026100.0% (590/590, v0.0.40)55.8% (329/590, v1.33.0)44.1% (260/590, v9.0.5)44.9% (265/590, v0.0.33)40.0% (236/590, v0.28.2)32.7% (193/590, v5.0.5)31.9% (188/590, v5.3.3)26.3% (155/590, v1.105.0)
Sep 28, 2026100.0% (594/594, v0.0.41)56.1% (333/594, v1.33.0)46.6% (277/594, v9.1.1)44.6% (265/594, v0.0.33)40.1% (238/594, v0.28.2)32.5% (193/594, v5.0.5)31.6% (188/594, v5.3.3)26.3% (156/594, v1.105.0)
Oct 5, 2026100.0% (594/594, v0.0.41)56.1% (333/594, v1.33.0)48.1% (286/594, v9.3.1)44.6% (265/594, v0.0.34)40.1% (238/594, v0.28.2)32.5% (193/594, v5.0.5)31.6% (188/594, v5.3.3)26.3% (156/594, v1.105.1)
Oct 16, 2026100.0% (594/594, v0.0.42)55.9% (332/594, v1.33.0)49.3% (293/594, v9.8.0)44.4% (264/594, v0.0.35)40.1% (238/594, v0.28.2)32.3% (192/594, v5.0.5)31.6% (188/594, v5.3.3)26.3% (156/594, v1.105.2)
Oct 17, 2026100.0% (595/595, v0.0.43)55.8% (332/595, v1.33.0)49.2% (293/595, v9.9.0)44.5% (265/595, v0.0.35)39.8% (237/595, v0.28.2)32.4% (193/595, v5.0.5)31.6% (188/595, v5.3.3)26.4% (157/595, v1.105.2)
Oct 18, 2026100.0% (606/606, v0.0.44)55.4% (336/606, v1.33.0)49.0% (297/606, v9.9.0)43.9% (266/606, v0.0.35)39.8% (241/606, v0.28.2)32.5% (197/606, v5.0.5)31.4% (190/606, v5.3.3)26.6% (161/606, v1.105.2)
Oct 20, 2026100.0% (622/622, v0.0.46)54.7% (340/622, v1.33.0)48.6% (302/622, v9.9.0)42.8% (266/622, v0.0.35)39.1% (243/622, v0.28.2)32.0% (199/622, v5.0.5)30.7% (191/622, v5.3.3)25.9% (161/622, v1.105.2)
Oct 25, 2026100.0% (645/645, v0.0.47)53.6% (346/645, v1.33.0)47.1% (304/645, v9.9.0)47.3% (305/645, v0.0.36)37.4% (241/645, v0.28.2)31.0% (200/645, v5.0.5)29.8% (192/645, v5.3.3)26.8% (173/645, v1.106.1)
Oct 29, 2026100.0% (657/657, v0.0.48)53.1% (349/657, v1.33.0)47.3% (311/657, v9.9.0)46.9% (308/657, v0.0.36)37.3% (245/657, v0.28.2)31.1% (204/657, v5.0.5)30.0% (197/657, v5.3.3)26.6% (175/657, v1.107.0)
Oct 30, 2026100.0% (660/660, v0.0.49)52.9% (349/660, v1.33.0)47.1% (311/660, v9.9.0)46.8% (309/660, v0.0.36)37.1% (245/660, v0.28.2)30.9% (204/660, v5.0.5)29.8% (197/660, v5.3.3)26.5% (175/660, v1.107.1)
Nov 1, 2026100.0% (663/663, v0.0.50)52.6% (349/663, v1.33.0)46.9% (311/663, v9.9.0)46.6% (309/663, v0.0.36)37.0% (245/663, v0.28.2)30.8% (204/663, v5.0.5)29.7% (197/663, v5.3.3)26.4% (175/663, v1.107.1)
Nov 2, 2026100.0% (669/669, v0.0.52)52.8% (353/669, v1.33.0)46.8% (313/669, v9.9.0)46.2% (309/669, v0.0.36)36.6% (245/669, v0.28.2)30.5% (204/669, v5.0.5)29.9% (200/669, v5.3.3)26.2% (175/669, v1.107.1)
Nov 7, 2026100.0% (676/676, v0.0.54)52.5% (355/676, v1.33.0)46.4% (314/676, v9.9.0)48.1% (325/676, v0.0.37)36.4% (246/676, v0.28.2)30.5% (206/676, v5.0.5)29.7% (201/676, v5.3.3)26.0% (176/676, v1.108.1)
Nov 9, 2026100.0% (688/688, v0.0.56)52.0% (358/688, v1.33.0)46.7% (321/688, v9.9.0)48.5% (334/688, v0.0.38)36.6% (252/688, v0.28.2)30.5% (210/688, v5.0.5)29.7% (204/688, v5.3.3)26.0% (179/688, v1.108.1)
Nov 10, 2026100.0% (690/690, v0.0.57)51.9% (358/690, v1.33.0)47.7% (329/690, v9.9.0)48.4% (334/690, v0.0.38)36.5% (252/690, v0.28.2)30.4% (210/690, v5.0.5)29.6% (204/690, v5.3.3)25.9% (179/690, v1.108.1)
Nov 11, 2026100.0% (698/698, v0.0.58)51.6% (360/698, v1.33.0)47.7% (333/698, v9.9.0)48.1% (336/698, v0.0.38)36.4% (254/698, v0.28.2)30.5% (213/698, v5.0.5)29.5% (206/698, v5.3.3)25.6% (179/698, v1.108.2)
Nov 15, 2026100.0% (703/703, v0.0.59)51.5% (362/703, v1.33.0)47.9% (337/703, v9.9.0)47.8% (336/703, v0.0.38)36.4% (256/703, v0.28.2)30.7% (216/703, v5.0.5)29.6% (208/703, v5.3.3)25.5% (179/703, v1.108.2)
Nov 17, 2026100.0% (713/713, v0.0.60)51.2% (365/713, v1.33.0)47.8% (341/713, v9.9.0)46.7% (333/713, v0.0.40)35.9% (256/713, v0.28.2)30.6% (218/713, v5.0.5)29.6% (211/713, v5.3.3)25.1% (179/713, v1.108.2)

anchor #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

position-area: center center shortens to center

position-area: center center is equivalent to position-area: center. When both axes are center, the second value can be omitted.

a {
  position-area: center center;
}

Expected

a{position-area:center}

Outputs

clean-css ✗

a{position-area:center center}

csskit ✗

a{position-area:center center}

csslop ✓

a{position-area:center}

cssnano ✗

a{position-area:center center}

csso ✗

a{position-area:center center}

esbuild ✗

a{position-area:center center}

lightningcss ✗

a{position-area:center center}

sass ✗

a{position-area:center center}
5ms
21ms
8ms
25ms
3ms
14ms
1ms
2ms
0002 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

position-area drops default center axis

position-area: top center shortens to position-area: top. When one axis is a directional keyword and the other is center, the center can be omitted as it is the default for the unspecified axis.

a {
  position-area: top center;
}

Expected

a{position-area:top}

Outputs

clean-css ✗

a{position-area:top center}

csskit ✗

a{position-area:center top}

csslop ✓

a{position-area:top}

cssnano ✗

a{position-area:top center}

csso ✗

a{position-area:top center}

esbuild ✗

a{position-area:top center}

lightningcss ✗

a{position-area:top center}

sass ✗

a{position-area:top center}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

@position-try equivalent to flip-block tactic

A @position-try that only flips the block axis (bottom -> top) is equivalent to the built-in flip-block try tactic. The at-rule can be removed and the reference replaced with the keyword, saving the entire block.

@position-try --flip {
  position-area: top;
}

a {
  position-area: bottom;
  position-try-fallbacks: --flip;
}

Expected

a{position-area:bottom;position-try-fallbacks:flip-block}

Outputs

clean-css ✗

@position-try --flip{position-area:top}a{position-area:bottom;position-try-fallbacks:--flip}

csskit ✗

@position-try --flip{position-area:top}a{position-area:bottom;position-try-fallbacks:--flip}

csslop ✓

a{position-area:bottom;position-try-fallbacks:flip-block}

cssnano ✗

@position-try --flip{position-area:top}a{position-area:bottom;position-try-fallbacks:--flip}

csso ✗

@position-try --flip{position-area:top}a{position-area:bottom;position-try-fallbacks:--flip}

esbuild ✗

@position-try --flip{position-area:top}a{position-area:bottom;position-try-fallbacks:--flip}

lightningcss ✗

@position-try --flip{position-area:top}a{position-area:bottom;position-try-fallbacks:--flip}

sass ✗

@position-try --flip{position-area:top}a{position-area:bottom;position-try-fallbacks:--flip}
1ms
1ms
2ms
2ms
1ms
1ms
1ms
3ms
0004 ✓ ✗ ✓ ✓ ✓ ✗ ✗ ✗
Details

Empty @position-try removal

An empty @position-try block with no declarations can be removed entirely.

@position-try --empty {
}

Expected

Outputs

clean-css ✓

csskit ✗

@position-try --empty{}

csslop ✓

cssnano ✓

csso ✓

esbuild ✗

@position-try --empty{}

lightningcss ✗

@position-try --empty{}

sass ✗

@position-try --empty{}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✓ ✓ ✓ ✓ ✓ ✓ ✗ ✓
Details

Unresolved position-try-fallbacks must be retained

position-try-fallbacks: --left, --undefined must keep --undefined even if no matching @position-try --undefined exists in the current stylesheet. Unresolved dashed-ident fallbacks are skipped at runtime and have no effect. However, it may be defined in other stylesheets ran on the same page, resulting in an incorrect outcome compared to the unminified code.

@position-try --left {
  position-area: left;
}
a {
  position-area: left;
  position-try-fallbacks: --left, --undefined;
}

Expected

@position-try --left{position-area:left}a{position-area:left;position-try-fallbacks:--left,--undefined}

Validate

Outputs

clean-css ✓

@position-try --left{position-area:left}a{position-area:left;position-try-fallbacks:--left,--undefined}

csskit ✓

@position-try --left{position-area:left}a{position-area:left;position-try-fallbacks:--left,--undefined}

csslop ✓

@position-try --left{position-area:left}a{position-area:left;position-try-fallbacks:--left,--undefined}

cssnano ✓

@position-try --left{position-area:left}a{position-area:left;position-try-fallbacks:--left,--undefined}

csso ✓

@position-try --left{position-area:left}a{position-area:left;position-try-fallbacks:--left,--undefined}

esbuild ✓

@position-try --left{position-area:left}a{position-area:left;position-try-fallbacks:--left,--undefined}

lightningcss ✗

@position-try --left{position-area:left}a{position-area:left;position-try-fallbacks:--left, --undefined}

sass ✓

@position-try --left{position-area:left}a{position-area:left;position-try-fallbacks:--left,--undefined}
1ms
1ms
1ms
2ms
1ms
1ms
1ms
2ms
Subtotal 2 / 5 1 / 5 5 / 5 2 / 5 2 / 5 1 / 5 0 / 5 1 / 5
Percent 40% 20% 100% 40% 40% 20% 0% 20%
Duration 5ms 22ms 12ms 31ms 4ms 17ms 1ms 9ms

calc #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✗ ✗ ✓ ✗ ✗ ✓ ✓ ✗
Details

Resolve calcs and merge them in margin

Resolve any static calculations, then apply merging of identical values for properties like margin, padding, or border.

a {
  margin: calc(1px + 2px) calc(4px - 1px);
}

Expected

a{margin:3px}

Outputs

clean-css ✗

a{margin:calc(1px + 2px) calc(4px - 1px)}

csskit ✗

a{margin:3px 3px}

csslop ✓

a{margin:3px}

cssnano ✗

a{margin:calc(3px)}

csso ✗

a{margin:calc(1px + 2px) calc(4px - 1px)}

esbuild ✓

a{margin:3px}

lightningcss ✓

a{margin:3px}

sass ✗

a{margin:3px 3px}
1ms
12ms
5ms
5ms
1ms
1ms
1ms
3ms
0002 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Smart separator preservation in calc()

Spaces around + and - operators inside calc() must be preserved. Removing them would cause 50vh+10px to be parsed as a single dimension token, or 100%-20px to change meaning. This tests that minifiers do not over-strip.

a {
  width: calc(100% - 20px);
  height: calc(50vh + 10px);
}

Expected

a{width:calc(100% - 20px);height:calc(50vh + 10px)}

Outputs

clean-css ✓

a{width:calc(100% - 20px);height:calc(50vh + 10px)}

csskit ✓

a{width:calc(100% - 20px);height:calc(50vh + 10px)}

csslop ✓

a{width:calc(100% - 20px);height:calc(50vh + 10px)}

cssnano ✓

a{width:calc(100% - 20px);height:calc(50vh + 10px)}

csso ✓

a{width:calc(100% - 20px);height:calc(50vh + 10px)}

esbuild ✓

a{width:calc(100% - 20px);height:calc(50vh + 10px)}

lightningcss ✓

a{width:calc(100% - 20px);height:calc(50vh + 10px)}

sass ✓

a{width:calc(100% - 20px);height:calc(50vh + 10px)}
1ms
1ms
3ms
2ms
1ms
1ms
1ms
2ms
0003 ✗ ✓ ✓ ✓ ✗ ✓ ✓ ✗
Details

Nested calc() flattening and reduction

calc(calc(100% - 20px) + 10px) should flatten the inner calc() and reduce compatible units: -20px + 10px = -10px, yielding calc(100% - 10px).

a {
  width: calc(calc(100% - 20px) + 10px);
}

Expected

a{width:calc(100% - 10px)}

Outputs

clean-css ✗

a{width:calc(calc(100% - 20px) + 10px)}

csskit ✓

a{width:calc(100% - 10px)}

csslop ✓

a{width:calc(100% - 10px)}

cssnano ✓

a{width:calc(100% - 10px)}

csso ✗

a{width:calc(calc(100% - 20px) + 10px)}

esbuild ✓

a{width:calc(100% - 10px)}

lightningcss ✓

a{width:calc(100% - 10px)}

sass ✗

a{width:calc(100% - 20px + 10px)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
4ms
0004 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Calc constant folding

calc(100px * 2) can be fully resolved to 200px at compile time since all values are known.

a {
  width: calc(100px * 2);
}

Expected

a{width:200px}

Outputs

clean-css ✗

a{width:calc(100px * 2)}

csskit ✓

a{width:200px}

csslop ✓

a{width:200px}

cssnano ✗

a{width:calc(200px)}

csso ✗

a{width:calc(100px*2)}

esbuild ✓

a{width:200px}

lightningcss ✓

a{width:200px}

sass ✓

a{width:200px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Calc addition folding

calc(50px + 50px) can be resolved to 100px since both operands share the same unit.

a {
  width: calc(50px + 50px);
}

Expected

a{width:100px}

Outputs

clean-css ✗

a{width:calc(50px + 50px)}

csskit ✓

a{width:100px}

csslop ✓

a{width:100px}

cssnano ✗

a{width:calc(100px)}

csso ✗

a{width:calc(50px + 50px)}

esbuild ✓

a{width:100px}

lightningcss ✓

a{width:100px}

sass ✓

a{width:100px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✗ ✓ ✓ ✓ ✗ ✓ ✓ ✗
Details

Calc partial reduction

Complex calc expressions with compatible units are partially reduced: px terms are combined while percentage terms are preserved.

a {
  width: calc(((75.37% - 63.5px) - 900px) + (2 * 100px));
}

Expected

a{width:calc(75.37% - 763.5px)}

Outputs

clean-css ✗

a{width:calc(((75.37% - 63.5px) - 900px) + (2 * 100px))}

csskit ✓

a{width:calc(75.37% - 763.5px)}

csslop ✓

a{width:calc(75.37% - 763.5px)}

cssnano ✓

a{width:calc(75.37% - 763.5px)}

csso ✗

a{width:calc(((75.37% - 63.5px) - 900px) + (2*100px))}

esbuild ✓

a{width:calc(75.37% - 763.5px)}

lightningcss ✓

a{width:calc(75.37% - 763.5px)}

sass ✗

a{width:calc(75.37% - 63.5px - 900px + 200px)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0007 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

Resolve calculations with long decimal points rounded

Replace the calculation with the result to reduce character count. To balanace accuracy and decimal point precision with character reduction, take the total number of characters in the resolved number (including .), and ensures it is 7 or less, and it correctly rounds the final digit if needed.

See the following post for decimal precision reasoning:

.a { width: calc(100% / 3); }
.b { width: calc(100% / 6); }
.c { width: calc(100% / 7); }
.d { width: calc(100% / 9); }
.e { width: calc(100% / 11); }
.f { width: calc(100% / 13); }
.g { width: calc(100% / 14); }

Expected

.a{width:33.3333%}.b{width:16.6667%}.c{width:14.2857%}.d{width:11.1111%}.e{width:9.09091%}.f{width:7.69231%}.g{width:7.14286%}

Outputs

clean-css ✗

.a{width:calc(100% / 3)}.b{width:calc(100% / 6)}.c{width:calc(100% / 7)}.d{width:calc(100% / 9)}.e{width:calc(100% / 11)}.f{width:calc(100% / 13)}.g{width:calc(100% / 14)}

csskit ✓

.a{width:33.3333%}.b{width:16.6667%}.c{width:14.2857%}.d{width:11.1111%}.e{width:9.09091%}.f{width:7.69231%}.g{width:7.14286%}

csslop ✓

.a{width:33.3333%}.b{width:16.6667%}.c{width:14.2857%}.d{width:11.1111%}.e{width:9.09091%}.f{width:7.69231%}.g{width:7.14286%}

cssnano ✗

.a{width:calc(100% / 3)}.b{width:calc(50% / 3)}.c{width:calc(100% / 7)}.d{width:calc(100% / 9)}.e{width:calc(100% / 11)}.f{width:calc(100% / 13)}.g{width:calc(50% / 7)}

csso ✗

.a{width:calc(100%/3)}.b{width:calc(100%/6)}.c{width:calc(100%/7)}.d{width:calc(100%/9)}.e{width:calc(100%/11)}.f{width:calc(100%/13)}.g{width:calc(100%/14)}

esbuild ✗

.a{width:calc(100% / 3)}.b{width:calc(100% / 6)}.c{width:calc(100% / 7)}.d{width:calc(100% / 9)}.e{width:calc(100% / 11)}.f{width:calc(100% / 13)}.g{width:calc(100% / 14)}

lightningcss ✓

.a{width:33.3333%}.b{width:16.6667%}.c{width:14.2857%}.d{width:11.1111%}.e{width:9.09091%}.f{width:7.69231%}.g{width:7.14286%}

sass ✗

.a{width:33.3333333333%}.b{width:16.6666666667%}.c{width:14.2857142857%}.d{width:11.1111111111%}.e{width:9.0909090909%}.f{width:7.6923076923%}.g{width:7.1428571429%}
1ms
1ms
6ms
2ms
1ms
1ms
1ms
2ms
0008 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Calc multiply by 1 (identity)

Multiplying a value by 1 has no effect. calc(100px * 1) simplifies to 100px, removing the calc() wrapper entirely.

a {
  width: calc(100px * 1);
}

Expected

a{width:100px}

Outputs

clean-css ✗

a{width:calc(100px * 1)}

csskit ✓

a{width:100px}

csslop ✓

a{width:100px}

cssnano ✗

a{width:calc(100px)}

csso ✗

a{width:calc(100px*1)}

esbuild ✓

a{width:100px}

lightningcss ✓

a{width:100px}

sass ✓

a{width:100px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0009 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Calc add zero same unit (identity)

Adding zero of the same unit has no effect. calc(100px + 0px) simplifies to 100px, removing the calc() wrapper.

Note: A zero term can only be combined with a term of the same unit, not removed outright.

a {
  width: calc(100px + 0px);
}

Expected

a{width:100px}

Outputs

clean-css ✗

a{width:calc(100px + 0px)}

csskit ✓

a{width:100px}

csslop ✓

a{width:100px}

cssnano ✗

a{width:calc(100px)}

csso ✗

a{width:calc(100px + 0px)}

esbuild ✓

a{width:100px}

lightningcss ✓

a{width:100px}

sass ✓

a{width:100px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0010 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Calc double negation elimination

calc(-1 * (-10px)) negates a negative value. The product -1 * -10px = 10px, fully resolving to a plain length value.

a {
  margin-left: calc(-1 * (-10px));
  margin-right: calc(-10 * (-10px));
}

Expected

a{margin-left:10px;margin-right:100px}

Outputs

clean-css ✗

a{margin-left:calc(-1 * (-10px));margin-right:calc(-10 * (-10px))}

csskit ✓

a{margin-left:10px;margin-right:100px}

csslop ✓

a{margin-left:10px;margin-right:100px}

cssnano ✗

a{margin-left:calc(10px);margin-right:calc(100px)}

csso ✗

a{margin-left:calc(-1*(-10px));margin-right:calc(-10*(-10px))}

esbuild ✓

a{margin-left:10px;margin-right:100px}

lightningcss ✓

a{margin-left:10px;margin-right:100px}

sass ✓

a{margin-left:10px;margin-right:100px}
1ms
1ms
1ms
2ms
1ms
1ms
1ms
1ms
0011 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✓
Details

Calc double inversion elimination

Dividing by a reciprocal cancels out. calc(1 / (1 / 50px)) simplifies back to 50px because the two inversions undo each other.

a {
  width: calc(1 / (1 / 50px));
}

Expected

a{width:50px}

Outputs

clean-css ✗

a{width:calc(1 / (1 / 50px))}

csskit ✓

a{width:50px}

csslop ✓

a{width:50px}

cssnano ✗

a{width:calc(50px)}

csso ✗

a{width:calc(1/(1/50px))}

esbuild ✗

a{width:calc(1/(1/50px))}

lightningcss ✗

a{width:calc(1 / (1 / 50px))}

sass ✓

a{width:50px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0012 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Calc sum flattening across nested calc()

Nested additions inside calc() are flattened into a single addition. Two nested calc() sums are merged and all px terms are combined: 10 + 20 + 30 + 40 = 100px.

a {
  width: calc(calc(10px + 20px) + calc(30px + 40px));
}

Expected

a{width:100px}

Validate

Outputs

clean-css ✗

a{width:calc(calc(10px + 20px) + calc(30px + 40px))}

csskit ✓

a{width:100px}

csslop ✓

a{width:100px}

cssnano ✗

a{width:calc(100px)}

csso ✗

a{width:calc(calc(10px + 20px) + calc(30px + 40px))}

esbuild ✓

a{width:100px}

lightningcss ✓

a{width:100px}

sass ✓

a{width:100px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0013 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Calc product flattening with multiple numbers

When a multiplication chain contains multiple plain numbers, they are multiplied together first. 2 * 3 becomes 6, then 6 * 10px = 60px.

a {
  width: calc(2 * 3 * 10px);
}

Expected

a{width:60px}

Outputs

clean-css ✗

a{width:calc(2 * 3 * 10px)}

csskit ✓

a{width:60px}

csslop ✓

a{width:60px}

cssnano ✗

a{width:calc(60px)}

csso ✗

a{width:calc(2*3*10px)}

esbuild ✓

a{width:60px}

lightningcss ✓

a{width:60px}

sass ✓

a{width:60px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0014 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Calc distribute multiplication over sum

Multiplication distributes over addition. 2 * (50px + 25px) expands to 100px + 50px, then the like terms combine to 150px.

a {
  width: calc(2 * (50px + 25px));
}

Expected

a{width:150px}

Validate

Outputs

clean-css ✗

a{width:calc(2 * (50px + 25px))}

csskit ✓

a{width:150px}

csslop ✓

a{width:150px}

cssnano ✗

a{width:calc(150px)}

csso ✗

a{width:calc(2*(50px + 25px))}

esbuild ✓

a{width:150px}

lightningcss ✓

a{width:150px}

sass ✓

a{width:150px}
1ms
1ms
4ms
1ms
1ms
1ms
1ms
1ms
0015 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Calc combine like percentage terms

Terms with the same unit are combined by adding their values. calc(50% + 25%) becomes 75%, removing the calc() wrapper.

a {
  width: calc(50% + 25%);
}

Expected

a{width:75%}

Outputs

clean-css ✗

a{width:calc(50% + 25%)}

csskit ✓

a{width:75%}

csslop ✓

a{width:75%}

cssnano ✗

a{width:calc(75%)}

csso ✗

a{width:calc(50% + 25%)}

esbuild ✓

a{width:75%}

lightningcss ✓

a{width:75%}

sass ✓

a{width:75%}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0016 ✗ ✗ ✓ ✗ ✗ ✓ ✓ ✓
Details

Calc division of pure numbers

calc(10 / 2) divides two unitless numbers, yielding 5. Since line-height accepts unitless numbers, the result is a plain 5 with the calc() wrapper removed.

a {
  line-height: calc(10 / 2);
}

Expected

a{line-height:5}

Outputs

clean-css ✗

a{line-height:calc(10 / 2)}

csskit ✗

a{line-height:calc(5)}

csslop ✓

a{line-height:5}

cssnano ✗

a{line-height:calc(5)}

csso ✗

a{line-height:calc(10/2)}

esbuild ✓

a{line-height:5}

lightningcss ✓

a{line-height:5}

sass ✓

a{line-height:5}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0017 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

Calc self-subtraction resolves to zero

calc(50px - 50px) subtracts identical values. The same-unit terms cancel out: 50 - 50 = 0. The result is 0 (unitless zero is valid for lengths).

a {
  width: calc(50px - 50px);
}

Expected

a{width:0}

Outputs

clean-css ✗

a{width:calc(50px - 50px)}

csskit ✓

a{width:0}

csslop ✓

a{width:0}

cssnano ✗

a{width:calc(0px)}

csso ✗

a{width:calc(50px - 50px)}

esbuild ✗

a{width:0px}

lightningcss ✓

a{width:0}

sass ✗

a{width:0px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0018 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

Calc multiply by zero

calc(100px * 0) multiplies a dimension by zero. The result is 0px, which serializes as 0.

a {
  width: calc(100px * 0);
}

Expected

a{width:0}

Outputs

clean-css ✗

a{width:calc(100px * 0)}

csskit ✓

a{width:0}

csslop ✓

a{width:0}

cssnano ✗

a{width:calc(0px)}

csso ✗

a{width:calc(100px*0)}

esbuild ✗

a{width:0px}

lightningcss ✓

a{width:0}

sass ✗

a{width:0px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0019 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

Calc constant pi resolution

pi is a numeric constant (~3.14159). calc(pi * 10px) resolves the constant then multiplies, yielding 31.4159px.

a {
  width: calc(pi * 100px);
}

Expected

a{width:314.159px}

Validate

Outputs

clean-css ✗

a{width:calc(pi * 100px)}

csskit ✓

a{width:314.159px}

csslop ✓

a{width:314.159px}

cssnano ✗

a{width:calc(314.15927px)}

csso ✗

a{width:calc(pi*100px)}

esbuild ✗

a{width:calc(pi*100px)}

lightningcss ✓

a{width:314.159px}

sass ✗

a{width:314.159265359px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0020 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

Calc constant e resolution

e is Euler's number (~2.71828). calc(e * 10px) resolves the constant then multiplies, yielding 27.1828px.

a {
  width: calc(e * 100px);
}

Expected

a{width:271.828px}

Validate

Outputs

clean-css ✗

a{width:calc(e * 100px)}

csskit ✓

a{width:271.828px}

csslop ✓

a{width:271.828px}

cssnano ✗

a{width:calc(271.82818px)}

csso ✗

a{width:calc(e*100px)}

esbuild ✗

a{width:calc(e*100px)}

lightningcss ✓

a{width:271.828px}

sass ✗

a{width:271.8281828459px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0021 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

Calc canonicalize compatible length units

Compatible units convert to canonical units: 1in = 96px. The sum combines 96px + 0px = 96px, resolving to a plain length value.

a {
  width: calc(1in + 0px);
}

Expected

a{width:96px}

Validate

Outputs

clean-css ✗

a{width:calc(1in + 0px)}

csskit ✓

a{width:96px}

csslop ✓

a{width:96px}

cssnano ✗

a{width:calc(1in)}

csso ✗

a{width:calc(1in + 0px)}

esbuild ✗

a{width:calc(1in + 0px)}

lightningcss ✓

a{width:96px}

sass ✗

a{width:1in}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0022 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Calc single term unwrap

calc(100px) contains a single numeric value with no operations. The calc() wrapper is unnecessary and should be removed, yielding 100px.

a {
  width: calc(100px);
}

Expected

a{width:100px}

Outputs

clean-css ✗

a{width:calc(100px)}

csskit ✓

a{width:100px}

csslop ✓

a{width:100px}

cssnano ✗

a{width:calc(100px)}

csso ✗

a{width:calc(100px)}

esbuild ✓

a{width:100px}

lightningcss ✓

a{width:100px}

sass ✓

a{width:100px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0023 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Calc division folding dimension by number

calc(100px / 4) creates a Product of 100px and Invert(4). The Invert resolves 4 to 0.25, then the Product yields 25px. Fully resolved, no calc() needed.

a {
  width: calc(100px / 4);
}

Expected

a{width:25px}

Validate

Outputs

clean-css ✗

a{width:calc(100px / 4)}

csskit ✓

a{width:25px}

csslop ✓

a{width:25px}

cssnano ✗

a{width:calc(25px)}

csso ✗

a{width:calc(100px/4)}

esbuild ✓

a{width:25px}

lightningcss ✓

a{width:25px}

sass ✓

a{width:25px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0024 ✗ ✓ ✓ ✓ ✗ ✓ ✓ ✗
Details

Calc combine like terms preserving incompatible units

calc(100% - 50px + 0%) has both percentage and px terms. Like units are combined: 100% + 0% = 100%, while -50px remains unchanged. The result is calc(100% - 50px) -- calc() is preserved because % and px cannot be resolved together at specified-value time.

a {
  width: calc(100% - 50px + 0%);
}

Expected

a{width:calc(100% - 50px)}

Validate

Outputs

clean-css ✗

a{width:calc(100% - 50px + 0%)}

csskit ✓

a{width:calc(100% - 50px)}

csslop ✓

a{width:calc(100% - 50px)}

cssnano ✓

a{width:calc(100% - 50px)}

csso ✗

a{width:calc(100% - 50px + 0%)}

esbuild ✓

a{width:calc(100% - 50px)}

lightningcss ✓

a{width:calc(100% - 50px)}

sass ✗

a{width:calc(100% - 50px + 0%)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0025 ✓ ✓ ✓ ✓ ✓ ✓ ✗ ✓
Details

calc() zero with different unit must not be dropped

calc(100px + 0%) must not simplify to 100px. Although 0% is numerically zero, it has a different unit type. The browser resolves % against the containing block at computed value time, and future animations or transitions could interpolate through non-zero percentage values.

a {
  width: calc(100px + 0%);
}

Expected

a{width:calc(100px + 0%)}

Outputs

clean-css ✓

a{width:calc(100px + 0%)}

csskit ✓

a{width:calc(100px + 0%)}

csslop ✓

a{width:calc(100px + 0%)}

cssnano ✓

a{width:calc(100px + 0%)}

csso ✓

a{width:calc(100px + 0%)}

esbuild ✓

a{width:calc(100px + 0%)}

lightningcss ✗

a{width:100px}

sass ✓

a{width:calc(100px + 0%)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0026 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Convert reciprocal multiplication to division

Convert multiplication by decimal to divide by whole number in calc.

When a decimal is used for multiplication and it is between 0 and 1, take it and put it in a fraction over 1.

0.25 = 0.25 1

Then multiply the top and bottom by 10 to the power of however many decimal places there are. For .25 you'd use 102 (100), for .0625 you'd use 104 (10000).

0.25 1 × 100 100 = 25 100

Find the Greatest Common Factor (GCF) of the top and bottom, if it exists, and reduce the fraction by dividing both numerator and denominator by the GCF.

25 ÷ 25 100 ÷ 25 = 1 4

After division, if the top value is 1, then you can use the bottom (denominator) as a replacement in your CSS calc, and convert from multiplication to division.

Examples:

  • calc(var(--x)*.5) => calc(var(--x)/2)
  • calc(var(--x)*.25) => calc(var(--x)/4)
  • calc(var(--x)*.05) => calc(var(--x)/20)
  • calc(var(--x)*.03125) => calc(var(--x)/32)

Note: This optimization can only be applied when the right-side of the calculation is unitless (See: calc/0035 for more information).

a {
  font-size: calc(var(--x) * 0.25);
}

Expected

a{font-size:calc(var(--x)/4)}

Outputs

clean-css ✗

a{font-size:calc(var(--x) * .25)}

csskit ✗

a{font-size:calc(var(--x)*.25)}

csslop ✓

a{font-size:calc(var(--x)/4)}

cssnano ✗

a{font-size:calc(var(--x) * .25)}

csso ✗

a{font-size:calc(var(--x)*.25)}

esbuild ✗

a{font-size:calc(var(--x) * .25)}

lightningcss ✗

a{font-size:calc(var(--x) * .25)}

sass ✗

a{font-size:calc(var(--x)*.25)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0027 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

Resolve on subtraction on exponents

In this example the two values being subtracted have exponents and the result can also be represented with an exponent. Since both values are the same unit a minifier should perform the calculation and resolve to the shortest representation, in this case 9e5px.

a {
  width: calc(1e6px - 1e5px);
}

Expected

a{width:9e5px}

Outputs

clean-css ✗

a{width:calc(1e6px - 1e5px)}

csskit ✓

a{width:9e5px}

csslop ✓

a{width:9e5px}

cssnano ✗

a{width:calc(9e5px)}

csso ✗

a{width:calc(1e6px - 1e5px)}

esbuild ✗

a{width:900000px}

lightningcss ✗

a{width:900000px}

sass ✗

a{width:900000px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0030 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Resolve simple percent division in calc

Replace a calculation with the result when it is a percentage divided by a number that results in a non-repeating positive interger that is shorter than the minified version of the calculation.

Example:

  • calc(100%/16) is 13 characters
  • 6.25% is 5 characters

.a { width: calc(100% / 1); }
.b { width: calc(100% / 2); }
.c { width: calc(100% / 4); }
.d { width: calc(100% / 5); }
.e { width: calc(100% / 8); }
.f { width: calc(100% / 10); }
.g { width: calc(100% / 16); }

Expected

.a{width:100%}.b{width:50%}.c{width:25%}.d{width:20%}.e{width:12.5%}.f{width:10%}.g{width:6.25%}

Outputs

clean-css ✗

.a{width:calc(100% / 1)}.b{width:calc(100% / 2)}.c{width:calc(100% / 4)}.d{width:calc(100% / 5)}.e{width:calc(100% / 8)}.f{width:calc(100% / 10)}.g{width:calc(100% / 16)}

csskit ✓

.a{width:100%}.b{width:50%}.c{width:25%}.d{width:20%}.e{width:12.5%}.f{width:10%}.g{width:6.25%}

csslop ✓

.a{width:100%}.b{width:50%}.c{width:25%}.d{width:20%}.e{width:12.5%}.f{width:10%}.g{width:6.25%}

cssnano ✗

.a{width:calc(100%)}.b{width:calc(50%)}.c{width:calc(25%)}.d{width:calc(20%)}.e{width:calc(12.5%)}.f{width:calc(10%)}.g{width:calc(6.25%)}

csso ✗

.a{width:calc(100%/1)}.b{width:calc(100%/2)}.c{width:calc(100%/4)}.d{width:calc(100%/5)}.e{width:calc(100%/8)}.f{width:calc(100%/10)}.g{width:calc(100%/16)}

esbuild ✓

.a{width:100%}.b{width:50%}.c{width:25%}.d{width:20%}.e{width:12.5%}.f{width:10%}.g{width:6.25%}

lightningcss ✓

.a{width:100%}.b{width:50%}.c{width:25%}.d{width:20%}.e{width:12.5%}.f{width:10%}.g{width:6.25%}

sass ✓

.a{width:100%}.b{width:50%}.c{width:25%}.d{width:20%}.e{width:12.5%}.f{width:10%}.g{width:6.25%}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0031 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Resolve mixed time units in calc

Convert both inner values in the calculation to the same units, then resolve the calculation. In this case .8s is shorter than 800ms.

a {
  transition-duration: calc(1s - 200ms);
}

Expected

a{transition-duration:.8s}

Outputs

clean-css ✗

a{transition-duration:calc(1s - 200ms)}

csskit ✓

a{transition-duration:.8s}

csslop ✓

a{transition-duration:.8s}

cssnano ✗

a{transition-duration:calc(.8s)}

csso ✗

a{transition-duration:calc(1s - 200ms)}

esbuild ✓

a{transition-duration:.8s}

lightningcss ✓

a{transition-duration:.8s}

sass ✓

a{transition-duration:.8s}
1ms
5ms
1ms
1ms
1ms
1ms
1ms
1ms
0032 ✗ ✓ ✓ ✓ ✗ ✓ ✓ ✗
Details

Resolve with correct order of operations in subtraction with parentheses

You must first resolve the inner parentheses (25px - 4px) => 21px. Resulting in 100% - 21px - 2px or 100% + -21px + -2px which can be resolved to 100% + -23px or 100% - 23px.

a {
  margin: calc(100% - (25px - 4px) - 2px);
}

Expected

a{margin:calc(100% - 23px)}

Outputs

clean-css ✗

a{margin:calc(100% - (25px - 4px) - 2px)}

csskit ✓

a{margin:calc(100% - 23px)}

csslop ✓

a{margin:calc(100% - 23px)}

cssnano ✓

a{margin:calc(100% - 23px)}

csso ✗

a{margin:calc(100% - (25px - 4px) - 2px)}

esbuild ✓

a{margin:calc(100% - 23px)}

lightningcss ✓

a{margin:calc(100% - 23px)}

sass ✗

a{margin:calc(100% - 21px - 2px)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0033 ✗ ✓ ✓ ✓ ✗ ✗ ✓ ✗
Details

Resolve with correct order of operations in division with parentheses

In this example (100% - 5em) / 2 can be represented as this fraction:

100% − 5em 2

Which allows dividing each part of the numerator by the denominator, like so: (100% / 2) - (5em / 2). Which can be resolved to 50% - 2.5em.

a {
  margin: calc((100% - 5em) / 2);
}

Expected

a{margin:calc(50% - 2.5em)}

Outputs

clean-css ✗

a{margin:calc((100% - 5em)/ 2)}

csskit ✓

a{margin:calc(50% - 2.5em)}

csslop ✓

a{margin:calc(50% - 2.5em)}

cssnano ✓

a{margin:calc(50% - 2.5em)}

csso ✗

a{margin:calc((100% - 5em)/2)}

esbuild ✗

a{margin:calc((100% - 5em)/2)}

lightningcss ✓

a{margin:calc(50% - 2.5em)}

sass ✗

a{margin:calc((100% - 5em)/2)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0034 ✗ ✓ ✓ ✓ ✗ ✗ ✓ ✗
Details

Resolve with correct PEMDAS order of operations

In this example -1 * (1rem + 16px) / 2, the parentheses go first, but cannot be resolved any further because of differing relative vs absolute units. Then the multiplication is applied, creating (-1rem + -16px) / 2. This can be represented as a fraction:

-1rem − 16px 2

Which allows dividing each part of the numerator by the denominator, like so: (-1rem / 2) - (16px / 2). Which can be resolved to -.5rem - 8px.

a {
  margin: calc(-1 * (1rem + 16px) / 2);
}

Expected

a{margin:calc(-.5rem - 8px)}

Outputs

clean-css ✗

a{margin:calc(-1 * (1rem + 16px)/ 2)}

csskit ✓

a{margin:calc(-.5rem - 8px)}

csslop ✓

a{margin:calc(-.5rem - 8px)}

cssnano ✓

a{margin:calc(-.5rem - 8px)}

csso ✗

a{margin:calc(-1*(1rem + 16px)/2)}

esbuild ✗

a{margin:calc(-.5*(1rem + 16px))}

lightningcss ✓

a{margin:calc(-.5rem - 8px)}

sass ✗

a{margin:calc(-1*(1rem + 16px)/2)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0035 ✗ ✓ ✓ ✗ ✓ ✗ ✗ ✓
Details

Do not convert reciprocal multiplication to division when right value has unit

In calc/0026 we convert reciprocal multiplication to division (x * .25 => x / 4), however this should only be done when the right-side value is unitless. The CSS spec requires the right-side value to have its unit inverted to a negative during division.

For example, assuming --x: 1;:

  • var(--x) * 0.25s becomes
  • (1,{}) * (0.25, {s: 1}) becomes
  • (0.25, {s: 1}) becomes
  • 0.25s

However,

  • var(--x) / 4s becomes
  • (1,{}) * (0.25, {s: -1}) becomes
  • (0.25, {s: -1}) becomes
  • -0.25s

Which is not equivalent to the original authored intent, making it incorrect, and in many cases also invalid according to the browser.

References:

a {
  transition-delay: calc(var(--x) * 0.25s);
}

Expected

a{transition-delay:calc(var(--x)*.25s)}

Outputs

clean-css ✗

a{transition-delay:calc(var(--x) * 0.25s)}

csskit ✓

a{transition-delay:calc(var(--x)*.25s)}

csslop ✓

a{transition-delay:calc(var(--x)*.25s)}

cssnano ✗

a{transition-delay:calc(var(--x) * .25s)}

csso ✓

a{transition-delay:calc(var(--x)*.25s)}

esbuild ✗

a{transition-delay:calc(var(--x) * .25s)}

lightningcss ✗

a{transition-delay:calc(var(--x) * .25s)}

sass ✓

a{transition-delay:calc(var(--x)*.25s)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0036 ✗ ✗ ✓ ✗ ✗ ✗ ✓ ✗
Details

Calc combines compatible angle units

.25turn is 90deg, so the sum is exactly 100deg. Writing the result in turn needs a rounded .2778turn (100.008deg), which is longer and lossy.

a {
  rotate: calc(0.25turn + 10deg);
}

Expected

a{rotate:100deg}

Outputs

clean-css ✗

a{rotate:calc(0.25turn + 10deg)}

csskit ✗

a{rotate:calc(100deg)}

csslop ✓

a{rotate:100deg}

cssnano ✗

a{rotate:calc(100deg)}

csso ✗

a{rotate:calc(.25turn + 10deg)}

esbuild ✗

a{rotate:calc(.25turn + 10deg)}

lightningcss ✓

a{rotate:100deg}

sass ✗

a{rotate:.2777777778turn}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0037 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✓
Details

Resolve clamp() when the value exceeds the maximum

All three arguments share a unit, so clamp(10px, 50px, 20px) resolves to its maximum, 20px.

a {
  width: clamp(10px, 50px, 20px);
}

Expected

a{width:20px}

Outputs

clean-css ✗

a{width:clamp(10px,50px,20px)}

csskit ✓

a{width:20px}

csslop ✓

a{width:20px}

cssnano ✗

a{width:calc(20px)}

csso ✗

a{width:clamp(10px,50px,20px)}

esbuild ✗

a{width:clamp(10px,50px,20px)}

lightningcss ✓

a{width:20px}

sass ✓

a{width:20px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0038 ✗ ✗ ✓ ✗ ✗ ✗ ✓ ✓
Details

Resolve max() across compatible length units

1in is 96px, so it is the larger argument. The winning argument is kept in its original unit, as 1in is shorter than 96px.

a {
  width: max(1in, 20px);
}

Expected

a{width:1in}

Outputs

clean-css ✗

a{width:max(1in,20px)}

csskit ✗

a{width:96px}

csslop ✓

a{width:1in}

cssnano ✗

a{width:calc(1in)}

csso ✗

a{width:max(1in,20px)}

esbuild ✗

a{width:max(1in,20px)}

lightningcss ✓

a{width:1in}

sass ✓

a{width:1in}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0039 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✓
Details

Resolve abs() inside calc()

abs(-5px) is 5px, so the whole expression folds to 10px.

a {
  margin: calc(abs(-5px) + 5px);
}

Expected

a{margin:10px}

Outputs

clean-css ✗

a{margin:calc(abs(-5px) + 5px)}

csskit ✓

a{margin:10px}

csslop ✓

a{margin:10px}

cssnano ✗

a{margin:calc(10px)}

csso ✗

a{margin:calc(abs(-5px) + 5px)}

esbuild ✗

a{margin:calc(abs(-5px) + 5px)}

lightningcss ✓

a{margin:10px}

sass ✓

a{margin:10px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0040 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✓
Details

Resolve min() nested inside calc()

min(10px, 20px) is 10px, so the outer sum folds to 20px.

a {
  width: calc(min(10px, 20px) + 10px);
}

Expected

a{width:20px}

Outputs

clean-css ✗

a{width:calc(min(10px,20px) + 10px)}

csskit ✓

a{width:20px}

csslop ✓

a{width:20px}

cssnano ✗

a{width:calc(20px)}

csso ✗

a{width:calc(min(10px,20px) + 10px)}

esbuild ✗

a{width:calc(min(10px,20px) + 10px)}

lightningcss ✓

a{width:20px}

sass ✓

a{width:20px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0041 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

Fold calc() inside a var() fallback

The fallback is only used as the whole width value, so calc(5px + 5px) can be folded to 10px without changing the result.

a {
  width: var(--x, calc(5px + 5px));
}

Expected

a{width:var(--x,10px)}

Outputs

clean-css ✗

a{width:var(--x,calc(5px + 5px))}

csskit ✓

a{width:var(--x,10px)}

csslop ✓

a{width:var(--x,10px)}

cssnano ✗

a{width:var(--x,calc(10px))}

csso ✗

a{width:var(--x, calc(5px + 5px))}

esbuild ✗

a{width:var(--x, 10px )}

lightningcss ✗

a{width:var(--x,calc(5px + 5px))}

sass ✗

a{width:var(--x, 10px)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0042 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Clamp calc() inside a var() fallback

calc(5px - 10px) is clamped to the allowed range of width, so it resolves to 0. Folding it to -5px would be wrong: a literal negative width is invalid at computed-value time, so the declaration would compute to unset instead of 0.

The fallback is only used as the whole width value, so it can be folded to 0.

a {
  width: var(--x, calc(5px - 10px));
}

Expected

a{width:var(--x,0)}

Outputs

clean-css ✗

a{width:var(--x,calc(5px - 10px))}

csskit ✗

a{width:var(--x,calc(-5px))}

csslop ✓

a{width:var(--x,0)}

cssnano ✗

a{width:var(--x,calc(-5px))}

csso ✗

a{width:var(--x, calc(5px - 10px))}

esbuild ✗

a{width:var(--x, -5px )}

lightningcss ✗

a{width:var(--x,calc(5px - 10px))}

sass ✗

a{width:var(--x, -5px)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0047 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✗
Details

Resolve calc() in colour channels

calc(255 / 2) is 127.5, which rounds to 128 in sRGB. rgb(128 0 0) is maroon, which is shorter than #800000.

a {
  color: rgb(calc(255 / 2) 0 0);
}

Expected

a{color:maroon}

Outputs

clean-css ✗

a{color:rgb(calc(255 / 2) 0 0)}

csskit ✓

a{color:maroon}

csslop ✓

a{color:maroon}

cssnano ✗

a{color:rgb(calc(127.5) 0 0)}

csso ✗

a{color:rgb(calc(255/2)0 0)}

esbuild ✓

a{color:maroon}

lightningcss ✓

a{color:maroon}

sass ✗

a{color:rgb(50%,0%,0%)}
2ms
7ms
1ms
1ms
1ms
1ms
1ms
3ms
Subtotal 2 / 41 35 / 41 41 / 41 8 / 41 3 / 41 22 / 41 34 / 41 22 / 41
Percent 4.87% 85.36% 100% 19.51% 7.31% 53.65% 82.92% 53.65%
Duration 8ms 30ms 34ms 45ms 6ms 22ms 1ms 40ms

calc-advanced #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Flatten negative width pixel calculations to 0

In the CSS spec, widths cannot have negative values, so any calculation that would return a negative value is interpreted as 0.

a {
  width: calc(5px - 10px);
  margin: calc(5px - 10px);
}

Expected

a{width:0;margin:-5px}

Outputs

clean-css ✗

a{width:calc(5px - 10px);margin:calc(5px - 10px)}

csskit ✗

a{width:calc(-5px);margin:calc(-5px)}

csslop ✓

a{width:0;margin:-5px}

cssnano ✗

a{width:calc(-5px);margin:calc(-5px)}

csso ✗

a{width:calc(5px - 10px);margin:calc(5px - 10px)}

esbuild ✗

a{width:-5px;margin:-5px}

lightningcss ✗

a{width:-5px;margin:-5px}

sass ✗

a{width:-5px;margin:-5px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Flatten negative width rem calculations to 0

In the CSS spec, widths cannot have negative values, so any calculation that would return a negative value is interpreted as 0.

a {
  width: calc(-0.5rem);
  margin: calc(-0.5rem);
}

Expected

a{width:0;margin:-.5rem}

Outputs

clean-css ✗

a{width:calc(-.5rem);margin:calc(-.5rem)}

csskit ✗

a{width:calc(-.5rem);margin:calc(-.5rem)}

csslop ✓

a{width:0;margin:-.5rem}

cssnano ✗

a{width:calc(-.5rem);margin:calc(-.5rem)}

csso ✗

a{width:calc(-.5rem);margin:calc(-.5rem)}

esbuild ✗

a{width:-.5rem;margin:-.5rem}

lightningcss ✗

a{width:-.5rem;margin:-.5rem}

sass ✗

a{width:-0.5rem;margin:-0.5rem}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Merge rules after flattening negative width calculations to 0

In the CSS spec, widths cannot have negative values, so any calculation that would return a negative value is interpretted as 0.

a {
  width: calc(5px - 10px);
}
b {
  width: calc(-0.5rem);
}

Expected

a,b{width:0}

Outputs

clean-css ✗

a{width:calc(5px - 10px)}b{width:calc(-.5rem)}

csskit ✗

a{width:calc(-5px)}b{width:calc(-.5rem)}

csslop ✓

a,b{width:0}

cssnano ✗

a{width:calc(-5px)}b{width:calc(-.5rem)}

csso ✗

a{width:calc(5px - 10px)}b{width:calc(-.5rem)}

esbuild ✗

a{width:-5px}b{width:-.5rem}

lightningcss ✗

a{width:-5px}b{width:-.5rem}

sass ✗

a{width:-5px}b{width:-0.5rem}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✓
Details

Cancel units with typed arithmetic

CSS Values 4 allows dividing by a dimension. 10px * (2 / 20px) is the plain number 1, leaving 3em. Every current engine supports typed arithmetic.

a {
  width: calc(10px * (2 / 20px) * 3em);
}

Expected

a{width:3em}

Outputs

clean-css ✗

a{width:calc(10px * (2 / 20px) * 3em)}

csskit ✓

a{width:3em}

csslop ✓

a{width:3em}

cssnano ✗

a{width:calc(10px * (2 / 20px) * 3em)}

csso ✗

a{width:calc(10px*(2/20px)*3em)}

esbuild ✗

a{width:calc(10px*2/20px*3em)}

lightningcss ✗

a{width:calc(10px * (2 / 20px) * 3em)}

sass ✓

a{width:3em}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✓
Details

Typed division resolving to a number

1in / 48px is 96px / 48px, the unitless number 2. Writing 2px or 32px would be wrong: unitless line-height scales with each element's font size.

a {
  line-height: calc(1in / 48px);
}

Expected

a{line-height:2}

Outputs

clean-css ✗

a{line-height:calc(1in / 48px)}

csskit ✗

a{line-height:calc(2)}

csslop ✓

a{line-height:2}

cssnano ✗

a{line-height:calc(2)}

csso ✗

a{line-height:calc(1in/48px)}

esbuild ✗

a{line-height:calc(1in/48px)}

lightningcss ✗

a{line-height:calc(1in / 48px)}

sass ✓

a{line-height:2}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Round calc() results for <integer> properties

z-index accepts only integers. calc(7 / 3) is rounded to 2, but the unrounded 2.33333 is invalid and drops the declaration.

a {
  z-index: calc(7 / 3);
}

Expected

a{z-index:2}

Outputs

clean-css ✗

a{z-index:calc(7 / 3)}

csskit ✗

a{z-index:calc(7/3)}

csslop ✓

a{z-index:2}

cssnano ✗

a{z-index:calc(7 / 3)}

csso ✗

a{z-index:calc(7/3)}

esbuild ✗

a{z-index:calc(7 / 3)}

lightningcss ✗

a{z-index:calc(7 / 3)}

sass ✗

a{z-index:2.3333333333}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0007 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Clamp calc() results to the allowed range

column-count must be at least 1. A top-level calc() outside the allowed range is not a parse error; it is clamped when the value is computed. So calc(2 - 2) is valid and computes to 1. Folding it to a literal 0 is invalid and drops the declaration.

a {
  column-count: calc(2 - 2);
}

Expected

a{column-count:1}

Outputs

clean-css ✗

a{column-count:calc(2 - 2)}

csskit ✗

a{column-count:calc(0)}

csslop ✓

a{column-count:1}

cssnano ✗

a{column-count:calc(0)}

csso ✗

a{column-count:calc(2 - 2)}

esbuild ✗

a{column-count:0}

lightningcss ✗

a{column-count:calc(2 - 2)}

sass ✗

a{column-count:0}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0008 ✗ ✗ ✓ ✗ ✗ ✓ ✗ ✓
Details

Fold in-range calc() results without clamping

column-count must be at least 1. calc(5 - 2) is already in range, so it folds to 3. Clamping only applies to results outside the allowed range.

a {
  column-count: calc(5 - 2);
}

Expected

a{column-count:3}

Outputs

clean-css ✗

a{column-count:calc(5 - 2)}

csskit ✗

a{column-count:calc(3)}

csslop ✓

a{column-count:3}

cssnano ✗

a{column-count:calc(3)}

csso ✗

a{column-count:calc(5 - 2)}

esbuild ✓

a{column-count:3}

lightningcss ✗

a{column-count:calc(5 - 2)}

sass ✓

a{column-count:3}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0009 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Clamp calc() opacity to 1

opacity is clamped to the range 0 to 1, so calc(3 / 2) behaves as 1.

a {
  opacity: calc(3 / 2);
}

Expected

a{opacity:1}

Outputs

clean-css ✗

a{opacity:calc(3 / 2)}

csskit ✗

a{opacity:calc(1.5)}

csslop ✓

a{opacity:1}

cssnano ✗

a{opacity:calc(1.5)}

csso ✗

a{opacity:calc(3/2)}

esbuild ✗

a{opacity:1.5}

lightningcss ✗

a{opacity:1.5}

sass ✗

a{opacity:1.5}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0010 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✓
Details

Typed division recovering a unit

8px / 2px is the unitless number 4, and multiplying by 1px restores the length 4px. Writing 4 would be wrong: unitless line-height scales with each element's font size.

a {
  line-height: calc((8px / 2px) * 1px);
}

Expected

a{line-height:4px}

Outputs

clean-css ✗

a{line-height:calc((8px / 2px) * 1px)}

csskit ✓

a{line-height:4px}

csslop ✓

a{line-height:4px}

cssnano ✗

a{line-height:calc((8px / 2px) * 1px)}

csso ✗

a{line-height:calc((8px/2px)*1px)}

esbuild ✗

a{line-height:calc(8px/2px*1px)}

lightningcss ✗

a{line-height:calc((8px / 2px) * 1px)}

sass ✓

a{line-height:4px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 0 / 10 2 / 10 10 / 10 0 / 10 0 / 10 1 / 10 0 / 10 4 / 10
Percent 0% 20% 100% 0% 0% 10% 0% 40%
Duration 1ms 4ms 3ms 8ms 1ms 5ms 1ms 6ms

charset #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✗ ✓ ✓ ✓ ✗ ✗ ✓ ✓
Details

@charset removal

@charset "UTF-8" is redundant in modern workflows since UTF-8 is the default encoding. It should be stripped.

@charset "UTF-8";
a {
  color: red;
}

Expected

a{color:red}

Outputs

clean-css ✗

@charset "UTF-8";a{color:red}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✓

a{color:red}

csso ✗

@charset "UTF-8";a{color:red}

esbuild ✗

@charset "UTF-8";a{color:red}

lightningcss ✓

a{color:red}

sass ✓

a{color:red}
1ms
1ms
1ms
2ms
2ms
1ms
1ms
1ms
0002 ✓ ✓ ✓ ✗ ✓ ✗ ✗ ✗
Details

Duplicate @charset removal

Only the first @charset declaration is meaningful; subsequent @charset rules are dropped. Uses two non-UTF-8 charsets to avoid special-casing UTF-8 removal.

@charset "gbk";
@charset "big5";
a {
  color: red;
}

Expected

@charset "gbk";a{color:red}

Outputs

clean-css ✓

@charset "gbk";a{color:red}

csskit ✓

@charset "gbk";a{color:red}

csslop ✓

@charset "gbk";a{color:red}

cssnano ✗

a{color:red}

csso ✓

@charset "gbk";a{color:red}

esbuild ✗

@charset "UTF-8";a{color:red}

lightningcss ✗

a{color:red}

sass ✗

a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✓ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

Move @charset to the top of documents

If a @charset is used and set to anything besides the default UTF-8, it must be retained and placed at the start of the minified CSS file. If the @charset is not moved to the top of the document, the CSS file will be considered invalid.

"It is a specific byte sequence that can only be placed at the very beginning of a stylesheet." - https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@charset

a {
  color: red;
}
@charset "gbk";

Expected

@charset "gbk";a{color:red}

Outputs

clean-css ✓

@charset "gbk";a{color:red}

csskit ✓

@charset "gbk";a{color:red}

csslop ✓

@charset "gbk";a{color:red}

cssnano ✗

a{color:red}

csso ✗

a{color:red}

esbuild ✗

a{color:red}@charset "gbk";

lightningcss ✗

a{color:red}

sass ✗

a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✗ ✓ ✓ ✗ ✓ ✗ ✓ ✓
Details

Replace unicode escapes with actual character

If the @charset is set to UTF-16 or UTF-8 (the default if @charset is not present), you can safely replace the escape codes for UTF values with their actual character value.

.foo:before {
  content: "\e61d";
}

Expected

.foo:before{content:""}

Outputs

clean-css ✗

.foo:before{content:"\e61d"}

csskit ✓

.foo:before{content:""}

csslop ✓

.foo:before{content:""}

cssnano ✗

.foo:before{content:"\e61d"}

csso ✓

.foo:before{content:""}

esbuild ✗

.foo:before{content:"\e61d"}

lightningcss ✓

.foo:before{content:""}

sass ✓

.foo:before{content:""}
1ms
1ms
4ms
4ms
1ms
1ms
1ms
1ms
0005 ✓ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Do not replace unicode escapes in non-unicode charsets

If the @charset is not set to UTF-16 or UTF-8 (the default if @charset is not present), then it may not be safe to convert escaped unicode values with real unicode characters.

@charset "gbk";
.foo:before {
  content: "\e61d";
}

Expected

@charset "gbk";.foo:before{content:"\e61d"}

Outputs

clean-css ✓

@charset "gbk";.foo:before{content:"\e61d"}

csskit ✗

@charset "gbk";.foo:before{content:""}

csslop ✓

@charset "gbk";.foo:before{content:"\e61d"}

cssnano ✗

.foo:before{content:"\e61d"}

csso ✗

@charset "gbk";.foo:before{content:""}

esbuild ✗

@charset "UTF-8";.foo:before{content:"\e61d"}

lightningcss ✗

.foo:before{content:""}

sass ✗

.foo:before{content:""}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✓ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

Handle multiple charsets

A @charset must be the first part of a CSS or it is ignored. Assume any declarations of a @charset are intentional, and if not at the top of a CSS file, it is likely a result of concatenating files but it is meant to be used. Move the first seen @charset to the top of the document. Remove all subsequent @charset's as they are ignored by the browser. If the first seen @charset uses UTF-8, it can be removed too, as it is the default encoding and does not need to be explicitly defined.

.foo {
  color: red;
}

@charset "gbk";

.bar {
  color: tan;
}

@charset "big5";

.baz {
  background: red;
}

Expected

@charset "gbk";.foo{color:red}.bar{color:tan}.baz{background:red}

Outputs

clean-css ✓

@charset "gbk";.foo{color:red}.bar{color:tan}.baz{background:red}

csskit ✓

@charset "gbk";.foo{color:red}.bar{color:tan}.baz{background:red}

csslop ✓

@charset "gbk";.foo{color:red}.bar{color:tan}.baz{background:red}

cssnano ✗

.foo{color:red}.bar{color:tan}.baz{background:red}

csso ✗

.foo{color:red}.bar{color:tan}.baz{background:red}

esbuild ✗

.foo{color:red}@charset "gbk";.bar{color:tan}@charset "big5";.baz{background:red}

lightningcss ✗

.foo{color:red}.bar{color:tan}.baz{background:red}

sass ✗

.foo{color:red}.bar{color:tan}.baz{background:red}
1ms
1ms
2ms
1ms
1ms
1ms
1ms
1ms
0007 ✗ ✓ ✓ ✓ ✗ ✗ ✓ ✓
Details

A UTF-16 @charset label means UTF-8

Determining the fallback encoding says that if the @charset label resolves to utf-16be or utf-16le, the encoding used is utf-8. The declaration bytes are ASCII, so the file cannot really be UTF-16. @charset "utf-16be"; therefore means @charset "utf-8";, which is the default and can be dropped (see charset/0001).

@charset "utf-16be";
a {
  color: red;
}

Expected

a{color:red}

Outputs

clean-css ✗

@charset "utf-16be";a{color:red}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✓

a{color:red}

csso ✗

@charset "utf-16be";a{color:red}

esbuild ✗

@charset "UTF-8";a{color:red}

lightningcss ✓

a{color:red}

sass ✓

a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0008 ✗ ✓ ✓ ✓ ✗ ✗ ✓ ✓
Details

utf-16 is a UTF-16LE label, so it also means UTF-8

The Encoding Standard maps utf-16, utf-16le, ucs-2, unicode, unicodefeff and iso-10646-ucs-2 to UTF-16LE, and utf-16be / unicodefffe to UTF-16BE. Every one of them becomes utf-8 when determining the fallback encoding, so the rule is redundant and removable.

A minifier that string-matches only utf-16be/utf-16le keeps this rule and misses the optimisation.

@charset "utf-16";
a {
  color: red;
}

Expected

a{color:red}

Outputs

clean-css ✗

@charset "utf-16";a{color:red}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✓

a{color:red}

csso ✗

@charset "utf-16";a{color:red}

esbuild ✗

@charset "UTF-8";a{color:red}

lightningcss ✓

a{color:red}

sass ✓

a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0009 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

Shorten the @charset label to its shortest alias

Labels are looked up in the Encoding Standard, which gives every encoding several aliases. iso-8859-1, latin1, us-ascii, ascii, cp819, and l1 all resolve to the same windows-1252 encoding, so @charset "ISO-8859-1"; can be written @charset "l1";, saving 8 bytes.

@charset "ISO-8859-1";
a {
  color: red;
}

Expected

@charset "l1";a{color:red}

Validate

Outputs

clean-css ✗

@charset "ISO-8859-1";a{color:red}

csskit ✓

@charset "l1";a{color:red}

csslop ✓

@charset "l1";a{color:red}

cssnano ✗

a{color:red}

csso ✗

@charset "ISO-8859-1";a{color:red}

esbuild ✗

@charset "UTF-8";a{color:red}

lightningcss ✗

a{color:red}

sass ✗

a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0010 ✗ ✓ ✓ ✓ ✗ ✗ ✓ ✓
Details

An unrecognised @charset label has no effect

If the label does not match an Encoding Standard label the lookup fails and the stylesheet keeps the encoding it would have had anyway, so the rule is inert and removable. Gecko DetermineNonBOMEncoding only uses the label when Encoding::ForLabel returns non-null; WebKit/Blink SetEncoding returns early when !encoding.IsValid().

@charset "not-a-charset";
a {
  color: red;
}

Expected

a{color:red}

Outputs

clean-css ✗

@charset "not-a-charset";a{color:red}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✓

a{color:red}

csso ✗

@charset "not-a-charset";a{color:red}

esbuild ✗

@charset "UTF-8";a{color:red}

lightningcss ✓

a{color:red}

sass ✓

a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0011 ✓ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

An uppercased @charset is not an encoding declaration

CSS at-keywords are ASCII case-insensitive, but the @charset rule, and its value are not. Engines compare raw bytes against @charset ". So @CHARSET "gbk"; declares nothing and the parser drops the at-rule; it can be removed.

@CHARSET "gbk";
a {
  color: red;
}

Expected

a{color:red}

Outputs

clean-css ✓

a{color:red}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✗

@CHARSET "gbk";a{color:red}

csso ✗

@CHARSET "gbk";a{color:red}

esbuild ✗

@charset "UTF-8";a{color:red}

lightningcss ✓

a{color:red}

sass ✗

@CHARSET "gbk";a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0012 ✗ ✓ ✓ ✓ ✗ ✗ ✓ ✓
Details

Never resolve escapes inside a @charset label

Engines read @charset rules as raw bytes, not CSS strings, therefore escaping isn't taken into account. Everything between @charset " and "; is the label. The literal bytes of \67 bk might resolve in CSS syntax as "gbk" - a valid encoding label, but the pre-escaped label not an Encoding Standard label, so the rule is inert and removable.

A minifier that unescapes strings would emit @charset "gbk"; and change how the browser decodes the whole file. This is incorrect.

@charset "\67 bk";
a {
  color: red;
}

Expected

a{color:red}

Outputs

clean-css ✗

@charset "\67 bk";a{color:red}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✓

a{color:red}

csso ✗

@charset "gbk";a{color:red}

esbuild ✗

@charset "UTF-8";a{color:red}

lightningcss ✓

a{color:red}

sass ✓

a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0013 ✗ ✓ ✓ ✓ ✗ ✗ ✓ ✓
Details

A single-quoted @charset is not an encoding declaration

@charset must use single quotes, as the byte sequence - not "tokenized" syntax is detected. @charset 'gbk'; is therefore inert, and will be discarded in engines. Minifiers can therefore safely remove this.

Normalising the quotes instead - which minifiers do to ordinary strings - turns a rule the browser ignored into a live encoding declaration. This is incorrect and may cause bugs.

@charset 'gbk';
a {
  color: red;
}

Expected

a{color:red}

Outputs

clean-css ✗

@charset 'gbk';a{color:red}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✓

a{color:red}

csso ✗

@charset "gbk";a{color:red}

esbuild ✗

@charset "UTF-8";a{color:red}

lightningcss ✓

a{color:red}

sass ✓

a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 5 / 13 12 / 13 13 / 13 6 / 13 2 / 13 0 / 13 8 / 13 7 / 13
Percent 38.46% 92.3% 100% 46.15% 15.38% 0% 61.53% 53.84%
Duration 2ms 3ms 9ms 15ms 5ms 7ms 1ms 8ms

color-rounding #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

oklab() rounding: out-of-gamut colours stay in native space

oklab() values with excess precision are rounded to 3 decimal places. Out-of-gamut oklab colours (chroma too high to fit in sRGB) stay in oklab space; they cannot be safely represented as a hex value.

In-gamut oklab colours may be minified to hex if the hex form is shorter.

a {
  color: oklab(0.50000 0.28456 -0.14876);
}

Expected

a{color:oklab(.5 .285-.149)}

Outputs

clean-css ✗

a{color:oklab(.5 .28456 -.14876)}

csskit ✓

a{color:oklab(.5 .285-.149)}

csslop ✓

a{color:oklab(.5 .285-.149)}

cssnano ✗

a{color:oklab(.5 .28456 -.14876)}

csso ✗

a{color:oklab(.5 .28456-.14876)}

esbuild ✗

a{color:oklab(.5 .28456 -.14876)}

lightningcss ✗

a{color:oklab(50% .28456 -.14876)}

sass ✗

a{color:oklab(.5 .28456 -0.14876)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

color-mix in oklch resolved to oklch value

color-mix(in oklch, red 50%, blue 50%) can be resolved at build time to oklch(.54 .285 326.6). A minifier that resolves the mix must do so in oklch space -- mixing in srgb produces a different color. Keeping the result in oklch avoids lossy gamut mapping to sRGB hex. Precision is rounded to 3dp (L/C) and 1dp (hue) -- well below JND. Lightness uses the number form (.54) rather than percent (54%) -- same length but consistent with always preferring numbers over percentages since percentages are longer for other components.

For a lot more detail on rounding, read Too Much Color.

a {
  color: color-mix(in oklch, red 50%, blue 50%);
}

Expected

a{color:oklch(.54 .285 326.6)}

Validate

Outputs

clean-css ✗

a{color:color-mix(in oklch,red 50%,#00f 50%)}

csskit ✓

a{color:oklch(.54 .285 326.6)}

csslop ✓

a{color:oklch(.54 .285 326.6)}

cssnano ✗

a{color:color-mix(in oklch,red 50%,blue 50%)}

csso ✗

a{color:color-mix(in oklch,red 50%,blue 50%)}

esbuild ✗

a{color:color-mix(in oklch,red 50%,blue 50%)}

lightningcss ✗

a{color:oklch(53.9985% .285449 326.643)}

sass ✗

a{color:color-mix(in oklch, red 50%, blue 50%)}
1ms
2ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

color-mix() in oklch resolved to oklch() when out of sRGB gamut

color-mix(in oklch, lime, blue) produces a high-chroma teal in oklch space that is outside the sRGB gamut. A minifier must not convert this to a hex color (which would clamp and change the color). Instead, the mix should be resolved to oklch functional notation: oklch(.659 .304 203.3), which is both shorter than the color-mix and preserves the intended color. L/C at 3dp and hue at 1dp - well below dEOk JND of 0.02.

a {
  color: color-mix(in oklch, lime, blue);
}

Expected

a{color:oklch(.659 .304 203.3)}

Outputs

clean-css ✗

a{color:color-mix(in oklch,#0f0,#00f)}

csskit ✓

a{color:oklch(.659 .304 203.3)}

csslop ✓

a{color:oklch(.659 .304 203.3)}

cssnano ✗

a{color:color-mix(in oklch,lime,blue)}

csso ✗

a{color:color-mix(in oklch,lime,blue)}

esbuild ✗

a{color:color-mix(in oklch,lime,blue)}

lightningcss ✗

a{color:oklch(65.9227% .304021 203.274)}

sass ✗

a{color:color-mix(in oklch, lime, blue)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✗ ✓ ✓ ✓ ✗ ✓ ✓ ✗
Details

Fractional sRGB channels round to integers

rgb(127.6 64.4 191.5) has fractional channel values that are meaningless in 8-bit sRGB. Browsers round to the nearest integer (128, 64, 192) before display. A minifier should round-then-convert to hex #8040c0, not truncate (which would give #7f40bf).

a {
  color: rgb(127.6 64.4 191.5);
}

Expected

a{color:#8040c0}

Outputs

clean-css ✗

a{color:rgb(127.6 64.4 191.5)}

csskit ✓

a{color:#8040c0}

csslop ✓

a{color:#8040c0}

cssnano ✓

a{color:#8040c0}

csso ✗

a{color:rgb(127.6 64.4 191.5)}

esbuild ✓

a{color:#8040c0}

lightningcss ✓

a{color:#8040c0}

sass ✗

a{color:rgb(50.0392156863%,25.2549019608%,75.0980392157%)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

oklch/oklab excess precision rounds to 3 decimal places

oklch and oklab use a 0-1 lightness scale and small chroma/a/b ranges. dEOk JND is 0.02, so 3dp (0.001) on L/C/a/b gives two orders of magnitude headroom. Hue at 1dp (0.1 deg) contributes ~0.0003 dEOk - effectively zero. A minifier can round e.g. oklch(0.55432 0.12276 180.4567 / 0.74567) to oklch(.554 .123 180.5/.746) with no perceptible change. Alpha is 0-1, so 3dp applies there too.

Both colours here are out-of-gamut for sRGB, so they stay in their native colour space. In-gamut colours may be minified to hex.

For a lot more detail on this, read Too Much Color.

a {
  color: oklch(0.55432 0.12276 180.4567 / 0.74567);
  background-color: oklab(0.65432 -0.23456 0.18901);
}

Expected

a{color:oklch(.554 .123 180.5/.746);background-color:oklab(.654-.235 .189)}

Outputs

clean-css ✗

a{color:oklch(.55432 .12276 180.4567 / .74567);background-color:oklab(.65432 -.23456 .18901)}

csskit ✓

a{color:oklch(.554 .123 180.5/.746);background-color:oklab(.654-.235 .189)}

csslop ✓

a{color:oklch(.554 .123 180.5/.746);background-color:oklab(.654-.235 .189)}

cssnano ✗

a{color:oklch(.55432 .12276 180.4567/.74567);background-color:oklab(.65432 -.23456 .18901)}

csso ✗

a{color:oklch(.55432 .12276 180.4567/.74567);background-color:oklab(.65432-.23456 .18901)}

esbuild ✗

a{color:oklch(.55432 .12276 180.4567 / .74567);background-color:oklab(.65432 -.23456 .18901)}

lightningcss ✗

a{color:oklch(55.432% .12276 180.457/.74567);background-color:oklab(65.432% -.23456 .18901)}

sass ✗

a{color:oklch(.55432 .12276 180.4567/.74567);background-color:oklab(.65432 -0.23456 .18901)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

lch/lab excess precision rounds to 1 decimal place

CIE LCH and Lab use a 0-100 lightness scale, chroma up to ~150, and a/b axes of roughly -128 to 128. dE00 JND is 2.0. At 0dp (integers) the worst-case error is already sub-JND for L/C/a/b, but lch chroma at 0dp can hit ~0.5 dE00. 1dp gives two orders of magnitude headroom (worst-case ~0.05 dE00 for all channels). A minifier can round e.g. lch(54.321 43.765 274.456 / 0.74567) to lch(54.3 43.8 274.5/.746). Alpha is 0-1, so 3dp applies there.

Both colours here are out-of-gamut for sRGB, so they stay in their native colour space. In-gamut colours may be minified to hex.

For a lot more detail on this, read Too Much Color.

a {
  color: lch(54.321 100.456 274.456 / 0.74567);
  background-color: lab(54.321 -60.456 70.789);
}

Expected

a{color:lch(54.3 100.5 274.5/.746);background-color:lab(54.3-60.5 70.8)}

Outputs

clean-css ✗

a{color:lch(54.321 100.456 274.456 / .74567);background-color:lab(54.321 -60.456 70.789)}

csskit ✓

a{color:lch(54.3 100.5 274.5/.746);background-color:lab(54.3-60.5 70.8)}

csslop ✓

a{color:lch(54.3 100.5 274.5/.746);background-color:lab(54.3-60.5 70.8)}

cssnano ✗

a{color:lch(54.321 100.456 274.456/.74567);background-color:lab(54.321 -60.456 70.789)}

csso ✗

a{color:lch(54.321 100.456 274.456/.74567);background-color:lab(54.321-60.456 70.789)}

esbuild ✗

a{color:lch(54.321 100.456 274.456 / .74567);background-color:lab(54.321 -60.456 70.789)}

lightningcss ✗

a{color:lch(54.321% 100.456 274.456/.74567);background-color:lab(54.321% -60.456 70.789)}

sass ✗

a{color:lch(54.321 100.456 274.456/.74567);background-color:lab(54.321 -60.456 70.789)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0007 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

color(srgb-linear) excess precision rounds to 4 decimal places

sRGB-linear channels are in the 0–1 range. Unlike other 0–1 colour spaces which use 3dp, srgb-linear needs 4dp because its linear transfer function amplifies rounding errors for near-black values at 3dp. Alpha is 0–1, so 3dp applies.

Both colours here are out-of-gamut for sRGB, so they stay in their native colour space. In-gamut colours may be minified to hex.

For a lot more detail on this, read Too Much Color.

a {
  color: color(srgb-linear 0.21586 0.04511 1.53123 / 0.8765);
}

Expected

a{color:color(srgb-linear .2159 .0451 1.5312/.877)}

Outputs

clean-css ✗

a{color:color(srgb-linear .21586 .04511 1.53123 / .8765)}

csskit ✓

a{color:color(srgb-linear .2159 .0451 1.5312/.877)}

csslop ✓

a{color:color(srgb-linear .2159 .0451 1.5312/.877)}

cssnano ✗

a{color:color(srgb-linear .21586 .04511 1.53123/.8765)}

csso ✗

a{color:color(srgb-linear .21586 .04511 1.53123/.8765)}

esbuild ✗

a{color:color(srgb-linear .21586 .04511 1.53123 / .8765)}

lightningcss ✗

a{color:color(srgb-linear .21586 .04511 1.53123/.8765)}

sass ✗

a{color:color(srgb-linear .21586 .04511 1.53123/.8765)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0008 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

color(display-p3) excess precision rounds to 3 decimal places

Display P3 channels are in the 0–1 range. 3dp is well below the perceptual JND and provides sufficient headroom for chained colour operations. Alpha is 0–1, so 3dp applies there too.

Both colours here are out-of-gamut for sRGB, so they stay in their native colour space. In-gamut colours may be minified to hex.

For a lot more detail on this, read Too Much Color.

a {
  color: color(display-p3 0.97654 0.12345 0.01789 / 0.8765);
}

Expected

a{color:color(display-p3 .977 .123 .018/.877)}

Outputs

clean-css ✗

a{color:color(display-p3 .97654 .12345 .01789 / .8765)}

csskit ✓

a{color:color(display-p3 .977 .123 .018/.877)}

csslop ✓

a{color:color(display-p3 .977 .123 .018/.877)}

cssnano ✗

a{color:color(display-p3 .97654 .12345 .01789/.8765)}

csso ✗

a{color:color(display-p3 .97654 .12345 .01789/.8765)}

esbuild ✗

a{color:color(display-p3 .97654 .12345 .01789 / .8765)}

lightningcss ✗

a{color:color(display-p3 .97654 .12345 .01789/.8765)}

sass ✗

a{color:color(display-p3 .97654 .12345 .01789/.8765)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0009 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

color(a98-rgb) excess precision rounds to 3 decimal places

A98 RGB channels are in the 0–1 range. 3dp is well below the perceptual JND.

Both colours here are out-of-gamut for sRGB, so they stay in their native colour space. In-gamut colours may be minified to hex.

For a lot more detail on this, read Too Much Color.

a {
  color: color(a98-rgb 1.05123 0.03456 0.07891);
}

Expected

a{color:color(a98-rgb 1.051 .035 .079)}

Outputs

clean-css ✗

a{color:color(a98-rgb 1.05123 .03456 .07891)}

csskit ✓

a{color:color(a98-rgb 1.051 .035 .079)}

csslop ✓

a{color:color(a98-rgb 1.051 .035 .079)}

cssnano ✗

a{color:color(a98-rgb 1.05123 .03456 .07891)}

csso ✗

a{color:color(a98-rgb 1.05123 .03456 .07891)}

esbuild ✗

a{color:color(a98-rgb 1.05123 .03456 .07891)}

lightningcss ✗

a{color:color(a98-rgb 1.05123 .03456 .07891)}

sass ✗

a{color:color(a98-rgb 1.05123 .03456 .07891)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0010 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

color(prophoto-rgb) excess precision rounds to 3 decimal places

ProPhoto RGB channels are in the 0–1 range. 3dp is well below the perceptual JND.

Both colours here are out-of-gamut for sRGB, so they stay in their native colour space. In-gamut colours may be minified to hex.

For a lot more detail on this, read Too Much Color.

a {
  color: color(prophoto-rgb 0.88765 0.01234 0.12345);
}

Expected

a{color:color(prophoto-rgb .888 .012 .123)}

Outputs

clean-css ✗

a{color:color(prophoto-rgb .88765 .01234 .12345)}

csskit ✓

a{color:color(prophoto-rgb .888 .012 .123)}

csslop ✓

a{color:color(prophoto-rgb .888 .012 .123)}

cssnano ✗

a{color:color(prophoto-rgb .88765 .01234 .12345)}

csso ✗

a{color:color(prophoto-rgb .88765 .01234 .12345)}

esbuild ✗

a{color:color(prophoto-rgb .88765 .01234 .12345)}

lightningcss ✗

a{color:color(prophoto-rgb .88765 .01234 .12345)}

sass ✗

a{color:color(prophoto-rgb .88765 .01234 .12345)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0011 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

color(rec2020) excess precision rounds to 3 decimal places

Rec. 2020 channels are in the 0–1 range. 3dp is well below the perceptual JND.

Both colours here are out-of-gamut for sRGB, so they stay in their native colour space. In-gamut colours may be minified to hex.

For a lot more detail on this, read Too Much Color.

a {
  color: color(rec2020 0.93456 0.07891 0.02345);
}

Expected

a{color:color(rec2020 .935 .079 .023)}

Outputs

clean-css ✗

a{color:color(rec2020 .93456 .07891 .02345)}

csskit ✓

a{color:color(rec2020 .935 .079 .023)}

csslop ✓

a{color:color(rec2020 .935 .079 .023)}

cssnano ✗

a{color:color(rec2020 .93456 .07891 .02345)}

csso ✗

a{color:color(rec2020 .93456 .07891 .02345)}

esbuild ✗

a{color:color(rec2020 .93456 .07891 .02345)}

lightningcss ✗

a{color:color(rec2020 .93456 .07891 .02345)}

sass ✗

a{color:color(rec2020 .93456 .07891 .02345)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0012 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

color(xyz-d65) excess precision rounds to 4 decimal places

XYZ D65 channels in CSS color() cover a range beyond 0–1 (D65 white point channels can exceed 1.0 for wide-gamut spaces). Like srgb-linear, this wider range means 3dp can introduce visible rounding errors, so 4dp is required.

Both colours here are out-of-gamut for sRGB, so they stay in their native colour space. In-gamut colours may be minified to hex.

For a lot more detail on this, read Too Much Color.

a {
  color: color(xyz-d65 0.53456 0.28768 0.06789);
}

Expected

a{color:color(xyz-d65 .5346 .2877 .0679)}

Outputs

clean-css ✗

a{color:color(xyz-d65 .53456 .28768 .06789)}

csskit ✓

a{color:color(xyz-d65 .5346 .2877 .0679)}

csslop ✓

a{color:color(xyz-d65 .5346 .2877 .0679)}

cssnano ✗

a{color:color(xyz-d65 .53456 .28768 .06789)}

csso ✗

a{color:color(xyz-d65 .53456 .28768 .06789)}

esbuild ✗

a{color:color(xyz-d65 .53456 .28768 .06789)}

lightningcss ✗

a{color:color(xyz .53456 .28768 .06789)}

sass ✗

a{color:color(xyz .53456 .28768 .06789)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0013 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

color(xyz-d50) excess precision rounds to 4 decimal places

XYZ D50 channels in CSS color() can exceed the 0–1 range (D50 white point values go above 1.0 for some channels). Like srgb-linear and xyz-d65, the wider numeric range means 3dp can introduce visible rounding errors, so 4dp is required.

Both colours here are out-of-gamut for sRGB, so they stay in their native colour space. In-gamut colours may be minified to hex.

For a lot more detail on this, read Too Much Color.

a {
  color: color(xyz-d50 0.54567 0.31098 0.04876);
}

Expected

a{color:color(xyz-d50 .5457 .311 .0488)}

Outputs

clean-css ✗

a{color:color(xyz-d50 .54567 .31098 .04876)}

csskit ✓

a{color:color(xyz-d50 .5457 .311 .0488)}

csslop ✓

a{color:color(xyz-d50 .5457 .311 .0488)}

cssnano ✗

a{color:color(xyz-d50 .54567 .31098 .04876)}

csso ✗

a{color:color(xyz-d50 .54567 .31098 .04876)}

esbuild ✗

a{color:color(xyz-d50 .54567 .31098 .04876)}

lightningcss ✗

a{color:color(xyz-d50 .54567 .31098 .04876)}

sass ✗

a{color:color(xyz-d50 .54567 .31098 .04876)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0014 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

OKLCH percentage lightness when rounding

For oklch(), lightness 100% equals 1, so 70% becomes .7. Dropping the % without scaling gives 70, which clamps to 1 (maximum lightness). The colour is outside sRGB, so it stays in oklch with C at 3dp.

a {
  color: oklch(70% 0.31234 150);
}

Expected

a{color:oklch(.7 .312 150)}

Outputs

clean-css ✗

a{color:oklch(70% .31234 150)}

csskit ✓

a{color:oklch(.7 .312 150)}

csslop ✓

a{color:oklch(.7 .312 150)}

cssnano ✗

a{color:oklch(70% .31234 150)}

csso ✗

a{color:oklch(70%.31234 150)}

esbuild ✗

a{color:oklch(70% .31234 150)}

lightningcss ✗

a{color:oklch(70% .31234 150)}

sass ✗

a{color:oklch(.7 .31234 150)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0015 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

OKLCH percentage chroma kept when shorter

For oklch(), chroma 100% equals 0.4 (not 150 as in lch()), so 80% equals .32. Keeping the percentage is shorter, as % ends the token and no space is needed before the hue. The colour is outside sRGB, so it stays in oklch with hue at 1dp.

a {
  color: oklch(0.7 80% 150.12345);
}

Expected

a{color:oklch(.7 80%150.1)}

Outputs

clean-css ✗

a{color:oklch(.7 80% 150.12345)}

csskit ✗

a{color:oklch(.7 .32 150.1)}

csslop ✓

a{color:oklch(.7 80%150.1)}

cssnano ✗

a{color:oklch(.7 80% 150.12345)}

csso ✗

a{color:oklch(.7 80%150.12345)}

esbuild ✗

a{color:oklch(.7 80% 150.12345)}

lightningcss ✗

a{color:oklch(70% .32 150.123)}

sass ✗

a{color:oklch(.7 .32 150.12345)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0016 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

OKLCH percentage chroma converted when shorter

For oklch(), chroma 100% equals .4. Converting is shorter, even with the space needed before the hue. The colour is outside sRGB, so it stays in oklch with hue at 1dp.

a {
  color: oklch(0.7 100% 150.12345);
}

Expected

a{color:oklch(.7 .4 150.1)}

Outputs

clean-css ✗

a{color:oklch(.7 100% 150.12345)}

csskit ✓

a{color:oklch(.7 .4 150.1)}

csslop ✓

a{color:oklch(.7 .4 150.1)}

cssnano ✗

a{color:oklch(.7 100% 150.12345)}

csso ✗

a{color:oklch(.7 100%150.12345)}

esbuild ✗

a{color:oklch(.7 100% 150.12345)}

lightningcss ✗

a{color:oklch(70% .4 150.123)}

sass ✗

a{color:oklch(.7 .4 150.12345)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 0 / 16 15 / 16 16 / 16 1 / 16 0 / 16 1 / 16 1 / 16 0 / 16
Percent 0% 93.75% 100% 6.25% 0% 6.25% 6.25% 0%
Duration 1ms 4ms 7ms 13ms 2ms 9ms 1ms 11ms

colors #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Hex shortening

#ffffff can be collapsed to #fff when all digit pairs match.

a {
  color: #ffffff;
}

Expected

a{color:#fff}

Outputs

clean-css ✓

a{color:#fff}

csskit ✓

a{color:#fff}

csslop ✓

a{color:#fff}

cssnano ✓

a{color:#fff}

csso ✓

a{color:#fff}

esbuild ✓

a{color:#fff}

lightningcss ✓

a{color:#fff}

sass ✓

a{color:#fff}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Hex to named color

#ff0000 is longer than the named keyword red. The shorter form should be used.

a {
  color: #ff0000;
}

Expected

a{color:red}

Outputs

clean-css ✓

a{color:red}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✓

a{color:red}

csso ✓

a{color:red}

esbuild ✓

a{color:red}

lightningcss ✓

a{color:red}

sass ✓

a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

rgb() to named color

rgb(255, 0, 0) is equivalent to red and shorter.

a {
  color: rgb(255, 0, 0);
}

Expected

a{color:red}

Outputs

clean-css ✓

a{color:red}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✓

a{color:red}

csso ✓

a{color:red}

esbuild ✓

a{color:red}

lightningcss ✓

a{color:red}

sass ✓

a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

rgba() with alpha=1

Fully opaque rgba(0, 0, 0, 1) can drop the alpha channel and convert to a shorter hex form.

a {
  color: rgba(0, 0, 0, 1);
}

Expected

a{color:#000}

Outputs

clean-css ✓

a{color:#000}

csskit ✓

a{color:#000}

csslop ✓

a{color:#000}

cssnano ✓

a{color:#000}

csso ✓

a{color:#000}

esbuild ✓

a{color:#000}

lightningcss ✓

a{color:#000}

sass ✓

a{color:#000}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

rgb() to named color (non-trivial)

rgb(210, 180, 140) equals the named color tan. Tests awareness of the full CSS named-color table, not just the obvious primaries.

a {
  color: rgb(210, 180, 140);
}

Expected

a{color:tan}

Outputs

clean-css ✓

a{color:tan}

csskit ✓

a{color:tan}

csslop ✓

a{color:tan}

cssnano ✓

a{color:tan}

csso ✓

a{color:tan}

esbuild ✓

a{color:tan}

lightningcss ✓

a{color:tan}

sass ✓

a{color:tan}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Hex shortening (non-white)

#aabbcc can be collapsed to #abc. Same rule as #ffffff -> #fff but with a non-trivial color.

a {
  color: #aabbcc;
}

Expected

a{color:#abc}

Outputs

clean-css ✓

a{color:#abc}

csskit ✓

a{color:#abc}

csslop ✓

a{color:#abc}

cssnano ✓

a{color:#abc}

csso ✓

a{color:#abc}

esbuild ✓

a{color:#abc}

lightningcss ✓

a{color:#abc}

sass ✓

a{color:#abc}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0007 ✗ ✓ ✓ ✓ ✗ ✓ ✓ ✗
Details

RGBA to hex alpha notation

rgba(255, 0, 0, 0.5) is shorter as #ff000080 using 8-digit hex with alpha channel.

a {
  color: rgba(255, 0, 0, 0.5);
}

Expected

a{color:#ff000080}

Outputs

clean-css ✗

a{color:rgba(255,0,0,.5)}

csskit ✓

a{color:#ff000080}

csslop ✓

a{color:#ff000080}

cssnano ✓

a{color:#ff000080}

csso ✗

a{color:rgba(255,0,0,.5)}

esbuild ✓

a{color:#ff000080}

lightningcss ✓

a{color:#ff000080}

sass ✗

a{color:rgba(255,0,0,.5)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0008 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

hsl() to named color

hsl(0, 100%, 50%) is pure red. The named keyword red is shorter. Conversion applies from hsl color space, not just rgb/hex.

a {
  color: hsl(0, 100%, 50%);
}

Expected

a{color:red}

Outputs

clean-css ✓

a{color:red}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✓

a{color:red}

csso ✓

a{color:red}

esbuild ✓

a{color:red}

lightningcss ✓

a{color:red}

sass ✓

a{color:red}
1ms
1ms
3ms
1ms
1ms
1ms
1ms
1ms
0009 ✗ ✓ ✓ ✓ ✗ ✓ ✓ ✗
Details

rgba() zero alpha to short hex

rgba(0, 0, 0, 0) is fully transparent. The 4-digit hex #0000 is the shortest equivalent representation (5 chars vs 11 for transparent). Note that 4-digit hex (CSS Color Level 4) may not be emitted by all minifiers -- some produce transparent instead, which is correct but not minimal.

a {
  color: rgba(0, 0, 0, 0);
}

Expected

a{color:#0000}

Outputs

clean-css ✗

a{color:transparent}

csskit ✓

a{color:#0000}

csslop ✓

a{color:#0000}

cssnano ✓

a{color:#0000}

csso ✗

a{color:transparent}

esbuild ✓

a{color:#0000}

lightningcss ✓

a{color:#0000}

sass ✗

a{color:rgba(0,0,0,0)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0010 ✗ ✓ ✓ ✓ ✗ ✓ ✓ ✓
Details

HWB to shorter representation

hwb(0 0% 0%) resolves to pure red (#ff0000) which is shorter as the named color red.

a {
  color: hwb(0 0% 0%);
}

Expected

a{color:red}

Outputs

clean-css ✗

a{color:hwb(0 0% 0%)}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✓

a{color:red}

csso ✗

a{color:hwb(0 0% 0%)}

esbuild ✓

a{color:red}

lightningcss ✓

a{color:red}

sass ✓

a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0011 ✗ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Named color to shorter hex

rebeccapurple (#663399) is shorter as the 3-digit hex #639.

a {
  color: rebeccapurple;
}

Expected

a{color:#639}

Outputs

clean-css ✗

a{color:#663399}

csskit ✓

a{color:#639}

csslop ✓

a{color:#639}

cssnano ✓

a{color:#639}

csso ✓

a{color:#639}

esbuild ✓

a{color:#639}

lightningcss ✓

a{color:#639}

sass ✓

a{color:#639}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0012 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

RGB to named color (olive)

rgb(128, 128, 0) is #808000, which is shorter as the named color olive.

a {
  color: rgb(128, 128, 0);
}

Expected

a{color:olive}

Outputs

clean-css ✓

a{color:olive}

csskit ✓

a{color:olive}

csslop ✓

a{color:olive}

cssnano ✓

a{color:olive}

csso ✓

a{color:olive}

esbuild ✓

a{color:olive}

lightningcss ✓

a{color:olive}

sass ✓

a{color:olive}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0013 ✗ ✓ ✓ ✓ ✓ ✓ ✓ ✗
Details

HSL to named color (green)

hsl(120, 100%, 25%) resolves to #008000 which is shorter as the named color green.

a {
  color: hsl(120, 100%, 25%);
}

Expected

a{color:green}

Outputs

clean-css ✗

a{color:#007f00}

csskit ✓

a{color:green}

csslop ✓

a{color:green}

cssnano ✓

a{color:green}

csso ✓

a{color:green}

esbuild ✓

a{color:green}

lightningcss ✓

a{color:green}

sass ✗

a{color:rgb(0%,50%,0%)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0014 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Uppercase hex to lowercase shorthand

#AABB11 should be lowercased and collapsed to #ab1.

a {
  color: #AABB11;
}

Expected

a{color:#ab1}

Outputs

clean-css ✓

a{color:#ab1}

csskit ✓

a{color:#ab1}

csslop ✓

a{color:#ab1}

cssnano ✓

a{color:#ab1}

csso ✓

a{color:#ab1}

esbuild ✓

a{color:#ab1}

lightningcss ✓

a{color:#ab1}

sass ✓

a{color:#ab1}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0015 ✗ ✓ ✓ ✓ ✗ ✓ ✓ ✗
Details

Modern rgb() with alpha to 8-digit hex

rgb(143 101 98 / 43%) can be converted to the shorter 8-digit hex #8f65626e. The alpha 43% maps to byte 0x6E (110). This is the standard 8-bit quantization browsers apply internally, making the conversion safe.

a {
  background-color: rgb(143 101 98 / 43%);
}

Expected

a{background-color:#8f65626e}

Validate

Outputs

clean-css ✗

a{background-color:rgb(143 101 98 / 43%)}

csskit ✓

a{background-color:#8f65626e}

csslop ✓

a{background-color:#8f65626e}

cssnano ✓

a{background-color:#8f65626e}

csso ✗

a{background-color:rgb(143 101 98/43%)}

esbuild ✓

a{background-color:#8f65626e}

lightningcss ✓

a{background-color:#8f65626e}

sass ✗

a{background-color:rgba(143,101,98,.43)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0016 ✗ ✓ ✓ ✓ ✗ ✓ ✓ ✓
Details

Modern rgb() with alpha 1 to named color

The modern space-separated rgb(255 0 0 / 1) syntax with full opacity should minify to the shortest equivalent named color red, dropping the alpha channel.

a {
  color: rgb(255 0 0 / 1);
}

Expected

a{color:red}

Validate

Outputs

clean-css ✗

a{color:rgb(255 0 0 / 1)}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✓

a{color:red}

csso ✗

a{color:rgb(255 0 0/1)}

esbuild ✓

a{color:red}

lightningcss ✓

a{color:red}

sass ✓

a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0017 ✗ ✓ ✓ ✓ ✗ ✓ ✓ ✗
Details

Modern hsl() with alpha to 8-digit hex

hsl(120 100% 50% / 0.5) resolves to fully saturated green at 50% opacity. This can be converted to the shorter 8-digit hex #00ff0080. The alpha 0.5 maps to byte 0x80 (128) under standard 8-bit quantization.

a {
  color: hsl(120 100% 50% / 0.5);
}

Expected

a{color:#00ff0080}

Validate

Outputs

clean-css ✗

a{color:hsl(120 100% 50% / .5)}

csskit ✓

a{color:#00ff0080}

csslop ✓

a{color:#00ff0080}

cssnano ✓

a{color:#00ff0080}

csso ✗

a{color:hsl(120 100% 50%/.5)}

esbuild ✓

a{color:#00ff0080}

lightningcss ✓

a{color:#00ff0080}

sass ✗

a{color:rgba(0,255,0,.5)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0018 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

color-mix() with known colors flattened to named color

color-mix(in srgb, red 50%, blue 50%) can be resolved at build time. The 50/50 sRGB mix of red (255,0,0) and blue (0,0,255) is (128,0,128) = purple. Minifiers should flatten color-mix() with static arguments to the shortest form.

a {
  color: color-mix(in srgb, red 50%, blue 50%);
}

Expected

a{color:purple}

Validate

Outputs

clean-css ✗

a{color:color-mix(in srgb,red 50%,#00f 50%)}

csskit ✓

a{color:purple}

csslop ✓

a{color:purple}

cssnano ✗

a{color:color-mix(in srgb,red 50%,blue 50%)}

csso ✗

a{color:color-mix(in srgb,red 50%,blue 50%)}

esbuild ✗

a{color:color-mix(in srgb,red 50%,blue 50%)}

lightningcss ✓

a{color:purple}

sass ✗

a{color:color-mix(in srgb, red 50%, blue 50%)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0019 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

color-mix() default percentages flattened to named color

When color-mix() omits percentages (defaulting to 50%/50%) with known color arguments, minifiers can resolve the mix at build time. color-mix(in srgb, red, blue) is the same 50/50 mix as the explicit form, yielding (128,0,128), or purple.

a {
  color: color-mix(in srgb, red, blue);
}

Expected

a{color:purple}

Validate

Outputs

clean-css ✗

a{color:color-mix(in srgb,red,#00f)}

csskit ✓

a{color:purple}

csslop ✓

a{color:purple}

cssnano ✗

a{color:color-mix(in srgb,red,blue)}

csso ✗

a{color:color-mix(in srgb,red,blue)}

esbuild ✗

a{color:color-mix(in srgb,red,blue)}

lightningcss ✓

a{color:purple}

sass ✗

a{color:color-mix(in srgb, red, blue)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0020 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

Static relative color syntax resolves to plain color

color(from red srgb r g b / 0.5) passes all channels through from red unchanged, so it resolves to srgb(1 0 0 / 0.5) which is #ff000080. A minifier that can evaluate static relative color expressions should fold this.

a {
  color: color(from red srgb r g b / 0.5);
}

Expected

a{color:#ff000080}

Outputs

clean-css ✗

a{color:color(from red srgb r g b / .5)}

csskit ✓

a{color:#ff000080}

csslop ✓

a{color:#ff000080}

cssnano ✗

a{color:color(from red srgb r g b/.5)}

csso ✗

a{color:color(from red srgb r g b/.5)}

esbuild ✗

a{color:color(from red srgb r g b / .5)}

lightningcss ✗

a{color:color(srgb 1 0 0/.5)}

sass ✗

a{color:color(from red srgb r g b/0.5)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
9ms
0021 ✗ ✓ ✓ ✓ ✗ ✗ ✓ ✗
Details

rgb() none keyword resolves to 0 outside interpolation

none in rgb(none 128 0) means "missing channel". Outside an interpolation context (like color-mix), missing channels resolve to 0. So this is rgb(0 128 0) = #008000 = green.

a {
  color: rgb(none 128 0);
}

Expected

a{color:green}

Validate

Outputs

clean-css ✗

a{color:rgb(none 128 0)}

csskit ✓

a{color:green}

csslop ✓

a{color:green}

cssnano ✓

a{color:green}

csso ✗

a{color:rgb(none 128 0)}

esbuild ✗

a{color:rgb(none 128 0)}

lightningcss ✓

a{color:green}

sass ✗

a{color:rgb(none 128 0)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0022 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✗
Details

8-digit hex with non-repeating alpha must not shorten

#ff00007a has alpha 7a (not 77), so it cannot be shortened to 4-digit hex #f007. A minifier that naively pairs digits would produce the wrong alpha.

a {
  color: #ff00007a;
}

Expected

a{color:#ff00007a}

Outputs

clean-css ✓

a{color:#ff00007a}

csskit ✓

a{color:#ff00007a}

csslop ✓

a{color:#ff00007a}

cssnano ✓

a{color:#ff00007a}

csso ✓

a{color:#ff00007a}

esbuild ✓

a{color:#ff00007a}

lightningcss ✓

a{color:#ff00007a}

sass ✗

a{color:rgba(255,0,0,.4784313725)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0023 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Named color shorter than any hex equivalent

purple is #800080 -- 6 chars vs 7 for hex, and the digits don't pair so it can't shorten to 3-digit hex either. A minifier must not convert to hex here.

a {
  color: purple;
}

Expected

a{color:purple}

Outputs

clean-css ✓

a{color:purple}

csskit ✓

a{color:purple}

csslop ✓

a{color:purple}

cssnano ✓

a{color:purple}

csso ✓

a{color:purple}

esbuild ✓

a{color:purple}

lightningcss ✓

a{color:purple}

sass ✓

a{color:purple}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0024 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

color-mix with none channel uses the other color's value

In interpolation contexts like color-mix, a none (missing) channel is replaced by the corresponding channel from the other color before mixing. rgb(none 0 0) mixed 50/50 with rgb(200 0 0) yields rgb(200 0 0) = #c80000 because the missing R channel adopts 200 from the other side.

a {
  color: color-mix(in srgb, rgb(none 0 0) 50%, rgb(200 0 0) 50%);
}

Expected

a{color:#c80000}

Validate

Outputs

clean-css ✗

a{color:color-mix(in srgb,rgb(none 0 0) 50%,rgb(200 0 0) 50%)}

csskit ✓

a{color:#c80000}

csslop ✓

a{color:#c80000}

cssnano ✗

a{color:color-mix(in srgb,#000 50%,#c80000 50%)}

csso ✗

a{color:color-mix(in srgb,rgb(none 0 0) 50%,rgb(200 0 0) 50%)}

esbuild ✗

a{color:color-mix(in srgb,rgb(none 0 0) 50%,rgb(200 0 0) 50%)}

lightningcss ✓

a{color:#c80000}

sass ✗

a{color:color-mix(in srgb, rgb(none 0 0) 50%, rgb(200, 0, 0) 50%)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0025 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

currentColor must not be resolved

currentColor is a runtime keyword that inherits the computed color value. It cannot be replaced with a static color at build time because the inherited value depends on the DOM context.

a {
  color: currentColor;
}

Expected

a{color:currentColor}

Outputs

clean-css ✓

a{color:currentColor}

csskit ✓

a{color:currentColor}

csslop ✓

a{color:currentColor}

cssnano ✓

a{color:currentColor}

csso ✓

a{color:currentColor}

esbuild ✓

a{color:currentColor}

lightningcss ✓

a{color:currentColor}

sass ✓

a{color:currentColor}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0026 ✓ ✓ ✓ ✓ ✓ ✓ ✗ ✓
Details

oklch() numeric minification

oklch() values can have their numbers minified (leading zero removal) but must not be converted to sRGB hex since the oklch gamut exceeds sRGB.

a {
  color: oklch(0.7 0.15 180);
}

Expected

a{color:oklch(.7 .15 180)}

Outputs

clean-css ✓

a{color:oklch(.7 .15 180)}

csskit ✓

a{color:oklch(.7 .15 180)}

csslop ✓

a{color:oklch(.7 .15 180)}

cssnano ✓

a{color:oklch(.7 .15 180)}

csso ✓

a{color:oklch(.7 .15 180)}

esbuild ✓

a{color:oklch(.7 .15 180)}

lightningcss ✗

a{color:oklch(70% .15 180)}

sass ✓

a{color:oklch(.7 .15 180)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0027 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

color-mix identity resolves to the color itself

color-mix(in srgb, red, red) mixes a color with itself at equal proportions. The result is always the original color regardless of the interpolation space.

a {
  color: color-mix(in srgb, red, red);
}

Expected

a{color:red}

Outputs

clean-css ✗

a{color:color-mix(in srgb,red,red)}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✗

a{color:color-mix(in srgb,red,red)}

csso ✗

a{color:color-mix(in srgb,red,red)}

esbuild ✗

a{color:color-mix(in srgb,red,red)}

lightningcss ✓

a{color:red}

sass ✗

a{color:color-mix(in srgb, red, red)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0028 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

display-p3 color must not be converted to sRGB

color(display-p3 1 0 0) is a P3 red that cannot be represented in sRGB. Converting to hex or rgb would clamp the value and lose the wider gamut intent. The color function and space must be preserved.

a {
  color: color(display-p3 1 0 0);
}

Expected

a{color:color(display-p3 1 0 0)}

Outputs

clean-css ✓

a{color:color(display-p3 1 0 0)}

csskit ✓

a{color:color(display-p3 1 0 0)}

csslop ✓

a{color:color(display-p3 1 0 0)}

cssnano ✓

a{color:color(display-p3 1 0 0)}

csso ✓

a{color:color(display-p3 1 0 0)}

esbuild ✓

a{color:color(display-p3 1 0 0)}

lightningcss ✓

a{color:color(display-p3 1 0 0)}

sass ✓

a{color:color(display-p3 1 0 0)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0029 ✓ ✗ ✓ ✓ ✓ ✗ ✗ ✗
Details

color-mix with var(): minify literal color argument

rgba(255, 255, 255, 1.0) inside a color-mix() with a var() second argument can still be shortened to #fff. The var() prevents resolving the mix, but the literal color is independently minifiable.

a {
  color: color-mix(in oklch, rgba(255, 255, 255, 1.0), var(--foo));
}

Expected

a{color:color-mix(in oklch,#fff,var(--foo))}

Validate

Outputs

clean-css ✓

a{color:color-mix(in oklch,#fff,var(--foo))}

csskit ✗

a{color:color-mix(in oklch,rgba(255,255,255,1.0),var(--foo))}

csslop ✓

a{color:color-mix(in oklch,#fff,var(--foo))}

cssnano ✓

a{color:color-mix(in oklch,#fff,var(--foo))}

csso ✓

a{color:color-mix(in oklch,#fff,var(--foo))}

esbuild ✗

a{color:color-mix(in oklch,rgba(255,255,255,1),var(--foo))}

lightningcss ✗

a{color:color-mix(in oklch, #fff, var(--foo))}

sass ✗

a{color:color-mix(in oklch, rgb(255, 255, 255), var(--foo))}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0030 ✓ ✗ ✓ ✓ ✓ ✗ ✗ ✗
Details

color-mix with var(): minify hsl to named color

hsl(0, 100%, 50%) inside a color-mix() with a var() second argument can still be shortened to red. The var() prevents resolving the mix, but each literal color argument is independently minifiable.

a {
  color: color-mix(in srgb, hsl(0, 100%, 50%), var(--foo));
}

Expected

a{color:color-mix(in srgb,red,var(--foo))}

Validate

Outputs

clean-css ✓

a{color:color-mix(in srgb,red,var(--foo))}

csskit ✗

a{color:color-mix(in srgb,hsl(0,100%,50%),var(--foo))}

csslop ✓

a{color:color-mix(in srgb,red,var(--foo))}

cssnano ✓

a{color:color-mix(in srgb,red,var(--foo))}

csso ✓

a{color:color-mix(in srgb,red,var(--foo))}

esbuild ✗

a{color:color-mix(in srgb,hsl(0,100%,50%),var(--foo))}

lightningcss ✗

a{color:color-mix(in srgb, red, var(--foo))}

sass ✗

a{color:color-mix(in srgb, hsl(0, 100%, 50%), var(--foo))}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0031 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

color-mix: elide default oklab interpolation space

Per CSS Color 5, oklab is the default interpolation method for color-mix() when none is specified. in oklab can be elided, saving 9 bytes. Browsers already support the omitted form.

a {
  color: color-mix(in oklab, var(--a), var(--b));
}

Expected

a{color:color-mix(var(--a),var(--b))}

Validate

Outputs

clean-css ✗

a{color:color-mix(in oklab,var(--a),var(--b))}

csskit ✗

a{color:color-mix(in oklab,var(--a),var(--b))}

csslop ✓

a{color:color-mix(var(--a),var(--b))}

cssnano ✗

a{color:color-mix(in oklab,var(--a),var(--b))}

csso ✗

a{color:color-mix(in oklab,var(--a),var(--b))}

esbuild ✗

a{color:color-mix(in oklab,var(--a),var(--b))}

lightningcss ✗

a{color:color-mix(in oklab, var(--a), var(--b))}

sass ✗

a{color:color-mix(in oklab, var(--a), var(--b))}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0032 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Named color to hex enables space elision

blue (4 chars) converts to #00f (4 chars) which looks like a no-op, but # is an unambiguous token start so the preceding space can be dropped: 1px solid#00f saves 1 byte over 1px solid blue.

a {
  border: 1px solid blue;
}

Expected

a{border:1px solid#00f}

Outputs

clean-css ✗

a{border:1px solid #00f}

csskit ✗

a{border:1px solid blue}

csslop ✓

a{border:1px solid#00f}

cssnano ✗

a{border:1px solid blue}

csso ✗

a{border:1px solid #00f}

esbuild ✗

a{border:1px solid blue}

lightningcss ✗

a{border:1px solid #00f}

sass ✗

a{border:1px solid blue}
1ms
1ms
1ms
2ms
1ms
1ms
1ms
1ms
0033 ✓ ✓ ✓ ✓ ✓ ✓ ✗ ERROR
Details

Out-of-gamut display-p3 color must not be clamped

color(display-p3 1.2 -0.3 0.5) has channels outside [0,1]. These are valid per CSS Color 4 and represent colors outside the display-p3 gamut. A minifier must not clamp these values or convert to sRGB, as that would destroy the author's intent. Only numeric minification (leading zero removal) is safe.

Additionally 1.2 -0.3 value can have whitespace elided as the leading dash is unambiguous: 1.2-0.3 is two number tokens.

a {
  color: color(display-p3 1.2-0.3 0.5);
}

Expected

a{color:color(display-p3 1.2-.3 .5)}

Outputs

clean-css ✓

a{color:color(display-p3 1.2-.3 .5)}

csskit ✓

a{color:color(display-p3 1.2-.3 .5)}

csslop ✓

a{color:color(display-p3 1.2-.3 .5)}

cssnano ✓

a{color:color(display-p3 1.2-.3 .5)}

csso ✓

a{color:color(display-p3 1.2-.3 .5)}

esbuild ✓

a{color:color(display-p3 1.2-.3 .5)}

lightningcss ✗

a{color:color(display-p3 1.2 -.3 .5)}

sass ✗

$description: The display-p3 color space has 3 channels but (display-p3 0.8999999999999999 0.5) has 2.
  ╷
2 │   color: color(display-p3 1.2-0.3 0.5);
  │          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵
  - 2:10  root stylesheet
1ms
1ms
1ms
1ms
1ms
1ms
1ms
5ms
0034 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

color-mix() with 100% first color eliminates to that color

color-mix(in srgb, red 100%, blue) means 100% of the first color and 0% of the second. The result is just red. Minifiers should detect this and replace the entire expression with the shortest form of the first color.

a {
  color: color-mix(in srgb, red 100%, blue);
}

Expected

a{color:red}

Outputs

clean-css ✗

a{color:color-mix(in srgb,red 100%,#00f)}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✗

a{color:color-mix(in srgb,red 100%,blue)}

csso ✗

a{color:color-mix(in srgb,red 100%,blue)}

esbuild ✗

a{color:color-mix(in srgb,red 100%,blue)}

lightningcss ✓

a{color:red}

sass ✗

a{color:color-mix(in srgb, red 100%, blue)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0035 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

color-mix() with 0% first color eliminates to the second color

color-mix(in srgb, red 0%, blue) means 0% of the first color and 100% of the second. The result is just blue, whose shortest form is #00f. Minifiers should detect this and replace the entire expression with the second color.

a {
  color: color-mix(in srgb, red 0%, blue);
}

Expected

a{color:#00f}

Outputs

clean-css ✗

a{color:color-mix(in srgb,red 0%,#00f)}

csskit ✓

a{color:#00f}

csslop ✓

a{color:#00f}

cssnano ✗

a{color:color-mix(in srgb,red 0%,blue)}

csso ✗

a{color:color-mix(in srgb,red 0%,blue)}

esbuild ✗

a{color:color-mix(in srgb,red 0%,blue)}

lightningcss ✓

a{color:#00f}

sass ✗

a{color:color-mix(in srgb, red 0%, blue)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0036 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

Redundant 50% percentages removed from color-mix()

color-mix(in srgb, currentcolor 50%, red 50%) — 50%/50% is the default mix ratio, so both percentage arguments are redundant and can be removed. The result is color-mix(in srgb, currentcolor, red).

a {
  color: color-mix(in srgb, currentcolor 50%, red 50%);
}

Expected

a{color:color-mix(in srgb,currentcolor,red)}

Outputs

clean-css ✗

a{color:color-mix(in srgb,currentcolor 50%,red 50%)}

csskit ✓

a{color:color-mix(in srgb,currentcolor,red)}

csslop ✓

a{color:color-mix(in srgb,currentcolor,red)}

cssnano ✗

a{color:color-mix(in srgb,currentcolor 50%,red 50%)}

csso ✗

a{color:color-mix(in srgb,currentcolor 50%,red 50%)}

esbuild ✗

a{color:color-mix(in srgb,currentcolor 50%,red 50%)}

lightningcss ✗

a{color:color-mix(in srgb, currentcolor 50%, red 50%)}

sass ✗

a{color:color-mix(in srgb, currentcolor 50%, red 50%)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0037 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

Redundant "shorter hue" removed from color-mix()

color-mix(in oklch shorter hue, currentcolor, red) — shorter is the default hue interpolation method for polar color spaces, so shorter hue is redundant and can be removed. The result is color-mix(in oklch, currentcolor, red).

a {
  color: color-mix(in oklch shorter hue, currentcolor, red);
}

Expected

a{color:color-mix(in oklch,currentcolor,red)}

Outputs

clean-css ✗

a{color:color-mix(in oklch shorter hue,currentcolor,red)}

csskit ✓

a{color:color-mix(in oklch,currentcolor,red)}

csslop ✓

a{color:color-mix(in oklch,currentcolor,red)}

cssnano ✗

a{color:color-mix(in oklch shorter hue,currentcolor,red)}

csso ✗

a{color:color-mix(in oklch shorter hue,currentcolor,red)}

esbuild ✗

a{color:color-mix(in oklch shorter hue,currentcolor,red)}

lightningcss ✗

a{color:color-mix(in oklch shorter hue, currentcolor, red)}

sass ✗

a{color:color-mix(in oklch shorter hue, currentcolor, red)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0038 ✓ ✓ ✓ ✓ ✓ ✗ ✗ ✗
Details

Inner colors minified inside color-mix()

color-mix(in oklch, rgba(255, 255, 255, 1), currentcolor) — the color-mix cannot be statically resolved because currentcolor is dynamic, but the inner rgba(255, 255, 255, 1) can be shortened to #fff. Minifiers should optimize individual color arguments even when the overall mix must be preserved.

a {
  color: color-mix(in oklch, rgba(255, 255, 255, 1), currentcolor);
}

Expected

a{color:color-mix(in oklch,#fff,currentcolor)}

Outputs

clean-css ✓

a{color:color-mix(in oklch,#fff,currentcolor)}

csskit ✓

a{color:color-mix(in oklch,#fff,currentcolor)}

csslop ✓

a{color:color-mix(in oklch,#fff,currentcolor)}

cssnano ✓

a{color:color-mix(in oklch,#fff,currentcolor)}

csso ✓

a{color:color-mix(in oklch,#fff,currentcolor)}

esbuild ✗

a{color:color-mix(in oklch,rgba(255,255,255,1),currentcolor)}

lightningcss ✗

a{color:color-mix(in oklch, #fff, currentcolor)}

sass ✗

a{color:color-mix(in oklch, rgb(255, 255, 255), currentcolor)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0039 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

color-mix() with 0% second color eliminates to the first color

color-mix(in srgb, red, blue 0%) means the second color contributes nothing. The result is just red. Minifiers should detect this and replace the entire expression with the shortest form of the first color.

a {
  color: color-mix(in srgb, red, blue 0%);
}

Expected

a{color:red}

Outputs

clean-css ✗

a{color:color-mix(in srgb,red,#00f 0%)}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✗

a{color:color-mix(in srgb,red,blue 0%)}

csso ✗

a{color:color-mix(in srgb,red,blue 0%)}

esbuild ✗

a{color:color-mix(in srgb,red,blue 0%)}

lightningcss ✓

a{color:red}

sass ✗

a{color:color-mix(in srgb, red, blue 0%)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0040 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

color-mix() percentages below 100% produce semi-transparent result

color-mix(in srgb, red 30%, blue 30%) — the percentages sum to 60%, not 100%. Per CSS Color 5, the mix is normalized to 50%/50% but the alpha of the result is multiplied by sum / 100 = 0.6. The result is rgba(128, 0, 128, 0.6), i.e. a semi-transparent purple. A minifier that resolves this to opaque purple would be incorrect: the alpha multiplier would be lost.

a {
  color: color-mix(in srgb, red 30%, blue 30%);
}

Expected

a{color:#80008099}

Outputs

clean-css ✗

a{color:color-mix(in srgb,red 30%,#00f 30%)}

csskit ✓

a{color:#80008099}

csslop ✓

a{color:#80008099}

cssnano ✗

a{color:color-mix(in srgb,red 30%,blue 30%)}

csso ✗

a{color:color-mix(in srgb,red 30%,blue 30%)}

esbuild ✗

a{color:color-mix(in srgb,red 30%,blue 30%)}

lightningcss ✓

a{color:#80008099}

sass ✗

a{color:color-mix(in srgb, red 30%, blue 30%)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0041 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

color-mix() with percentages summing over 100% must normalize

color-mix(in srgb, red 80%, blue 40%) — the percentages sum to 120%. Per CSS Color 5 percentage normalization, they scale to 66.67%/33.33%. The result is rgb(170, 0, 85) = #a05. A minifier that treats the percentages at face value without normalizing would produce an incorrect color.

a {
  color: color-mix(in srgb, red 80%, blue 40%);
}

Expected

a{color:#a05}

Outputs

clean-css ✗

a{color:color-mix(in srgb,red 80%,#00f 40%)}

csskit ✓

a{color:#a05}

csslop ✓

a{color:#a05}

cssnano ✗

a{color:color-mix(in srgb,red 80%,blue 40%)}

csso ✗

a{color:color-mix(in srgb,red 80%,blue 40%)}

esbuild ✗

a{color:color-mix(in srgb,red 80%,blue 40%)}

lightningcss ✓

a{color:#a05}

sass ✗

a{color:color-mix(in srgb, red 80%, blue 40%)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0042 ✗ ✓ ✓ ✗ ✗ ✓ ✗ ✗
Details

In-gamut oklab colour is minified to hex

oklab(0.5 -0.1 0.1) is within the sRGB gamut. A minifier should convert it to the shortest sRGB representation (#3c740a) rather than keeping the longer oklab form.

a {
  color: oklab(0.5 -0.1 0.1);
}

Expected

a{color:#3c740a}

Outputs

clean-css ✗

a{color:oklab(.5 -.1 .1)}

csskit ✓

a{color:#3c740a}

csslop ✓

a{color:#3c740a}

cssnano ✗

a{color:oklab(.5 -.1 .1)}

csso ✗

a{color:oklab(.5-.1 .1)}

esbuild ✓

a{color:#3c740a}

lightningcss ✗

a{color:oklab(50% -.1 .1)}

sass ✗

a{color:oklab(.5 -0.1 .1)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0043 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

In-gamut display-p3 colour is minified to shortest sRGB form

color(display-p3 0.5 0.5 0.5) is a neutral grey that is within the sRGB gamut. A minifier should convert it to the shortest sRGB representation (the named colour gray) rather than keeping the longer display-p3 form.

a {
  color: color(display-p3 0.5 0.5 0.5);
}

Expected

a{color:gray}

Outputs

clean-css ✗

a{color:color(display-p3 .5 .5 .5)}

csskit ✓

a{color:gray}

csslop ✓

a{color:gray}

cssnano ✗

a{color:color(display-p3 .5 .5 .5)}

csso ✗

a{color:color(display-p3 .5 .5 .5)}

esbuild ✗

a{color:#7f8080}

lightningcss ✗

a{color:color(display-p3 .5 .5 .5)}

sass ✗

a{color:color(display-p3 .5 .5 .5)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0044 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Named colors as quoted strings

When a quoted string contains a named color (green, rebeccapurple, salmon, etc) it should not be minified to hex.

a {
  content: "green";
}

Expected

a{content:"green"}

Outputs

clean-css ✓

a{content:"green"}

csskit ✓

a{content:"green"}

csslop ✓

a{content:"green"}

cssnano ✓

a{content:"green"}

csso ✓

a{content:"green"}

esbuild ✓

a{content:"green"}

lightningcss ✓

a{content:"green"}

sass ✓

a{content:"green"}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0045 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Hex colors as quoted strings

When a quoted string contains a long form hex value (#FF0000, #00FF00FF, etc.) it should not be minified (red, #0F0, etc).

a {
  content: "#FF0000";
}

Expected

a{content:"#FF0000"}

Outputs

clean-css ✓

a{content:"#FF0000"}

csskit ✓

a{content:"#FF0000"}

csslop ✓

a{content:"#FF0000"}

cssnano ✓

a{content:"#FF0000"}

csso ✓

a{content:"#FF0000"}

esbuild ✓

a{content:"#FF0000"}

lightningcss ✓

a{content:"#FF0000"}

sass ✓

a{content:"#FF0000"}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0046 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

URL strings containing color names

When a URL path string contains a color name, it should not be minified to a hex value.

a {
  background-image: url(green.png);
}

Expected

a{background-image:url(green.png)}

Outputs

clean-css ✓

a{background-image:url(green.png)}

csskit ✓

a{background-image:url(green.png)}

csslop ✓

a{background-image:url(green.png)}

cssnano ✓

a{background-image:url(green.png)}

csso ✓

a{background-image:url(green.png)}

esbuild ✓

a{background-image:url(green.png)}

lightningcss ✓

a{background-image:url(green.png)}

sass ✓

a{background-image:url(green.png)}
1ms
3ms
1ms
1ms
1ms
1ms
1ms
1ms
0047 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

color-mix() with 3 colors (N-color support)

color-mix(in oklab, red, orange, purple) mixes three equal-weight colors. CSS Color 5 allows N colors in color-mix(); no percentages means each gets 1/3.

These colours have been carefully chosen so that the mix remains in-gamut, meaning the result can safely be reduced to #d45456.

a {
  color: color-mix(in oklab, red, orange, purple);
}

Expected

a{color:#d45456}

Validate

Outputs

clean-css ✗

a{color:color-mix(in oklab,red,orange,purple)}

csskit ✓

a{color:#d45456}

csslop ✓

a{color:#d45456}

cssnano ✗

a{color:color-mix(in oklab,red,orange,purple)}

csso ✗

a{color:color-mix(in oklab,red,orange,purple)}

esbuild ✗

a{color:color-mix(in oklab,red,orange,purple)}

lightningcss ✗

a{color:color-mix(in oklab, red, orange, purple)}

sass ✗

a{color:color-mix(in oklab, red, orange, purple)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0048 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

color-mix() all-zero percentages become transparent black

color-mix(in srgb, red 0%, green 0%, blue 0%) has all percentages at 0%, so the sum is 0% and leftover is 100%. Per CSS Color 5, when leftover equals 100% the result is transparent black. The shortest representation is #0000.

a {
  color: color-mix(in srgb, red 0%, green 0%, blue 0%);
}

Expected

a{color:#0000}

Validate

Outputs

clean-css ✗

a{color:color-mix(in srgb,red 0%,green 0%,#00f 0%)}

csskit ✓

a{color:#0000}

csslop ✓

a{color:#0000}

cssnano ✗

a{color:color-mix(in srgb,red 0%,green 0%,blue 0%)}

csso ✗

a{color:color-mix(in srgb,red 0%,green 0%,blue 0%)}

esbuild ✗

a{color:color-mix(in srgb,red 0%,green 0%,blue 0%)}

lightningcss ✗

a{color:color-mix(in srgb, red 0%, green 0%, blue 0%)}

sass ✗

a{color:color-mix(in srgb, red 0%, green 0%, blue 0%)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0049 ✓ ✓ ✓ ✓ ✓ ✓ ✗ ✗
Details

color-mix() N-color with var() cannot be resolved

color-mix(in srgb, blue 50%, var(--foo), red 50%) contains a var() mid-list. Even though the known percentages sum to 100%, the var() may carry its own percentage (e.g. green 20%), which would change normalization. A minifier must not reduce this; the result is whitespace-stripped only. Rewriting blue as #00f is equally short, so both forms are accepted.

a {
  color: color-mix(in srgb, blue 50%, var(--foo), red 50%);
}

Expected

a{color:color-mix(in srgb,blue 50%,var(--foo),red 50%)}

Also accepted

a{color:color-mix(in srgb,#00f 50%,var(--foo),red 50%)}

Outputs

clean-css ✓

a{color:color-mix(in srgb,#00f 50%,var(--foo),red 50%)}

csskit ✓

a{color:color-mix(in srgb,blue 50%,var(--foo),red 50%)}

csslop ✓

a{color:color-mix(in srgb,blue 50%,var(--foo),red 50%)}

cssnano ✓

a{color:color-mix(in srgb,blue 50%,var(--foo),red 50%)}

csso ✓

a{color:color-mix(in srgb,blue 50%,var(--foo),red 50%)}

esbuild ✓

a{color:color-mix(in srgb,blue 50%,var(--foo),red 50%)}

lightningcss ✗

a{color:color-mix(in srgb, blue 50%, var(--foo), red 50%)}

sass ✗

a{color:color-mix(in srgb, blue 50%, var(--foo), red 50%)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0050 ✗ ✓ ✓ ✓ ✗ ✗ ✗ ✗
Details

Always shorten the color keyword transparent to hex

According to the CSS3 color specification, the color keyword transparent is equivalent to rbga(0, 0, 0, 0), which can also be written as the shortform hex, #0000, which is shorter than the keyword. As such, all uses of the word "transparent" as a color keyword should be shortend to the hex equivalent.

p {
  background: transparent;
}

Expected

p{background:#0000}

Outputs

clean-css ✗

p{background:0 0}

csskit ✓

p{background:#0000}

csslop ✓

p{background:#0000}

cssnano ✓

p{background:#0000}

csso ✗

p{background:0 0}

esbuild ✗

p{background:transparent}

lightningcss ✗

p{background:0 0}

sass ✗

p{background:rgba(0,0,0,0)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0051 ✗ ✗ ✓ ✓ ✗ ✓ ✓ ✗
Details

Do not convert effectively transparent colors to transparent

All colors with an alpha of 0, are equivalent to the keyword transparent, which according to the spec is technically #0000. However, a minifier should not convert non-black colors with an alpha of 0 to #0000, as that will effect the blending of the color when used in transitions.

p {
  color: #5987FC00;
  background: rgba(133, 40, 55, 0);
  border-color: hsla(180, 100%, 25.1%, 0);
}

Expected

p{color:#5987fc00;background:#85283700;border-color:#00808000}

Outputs

clean-css ✗

p{color:#5987FC00;background:rgba(133,40,55,0);border-color:hsla(180,100%,25.1%,0)}

csskit ✗

p{color:#5987FC00;background:#85283700;border-color:#00808000}

csslop ✓

p{color:#5987fc00;background:#85283700;border-color:#00808000}

cssnano ✓

p{color:#5987fc00;background:#85283700;border-color:#00808000}

csso ✗

p{color:#5987fc00;background:0 0;border-color:transparent}

esbuild ✓

p{color:#5987fc00;background:#85283700;border-color:#00808000}

lightningcss ✓

p{color:#5987fc00;background:#85283700;border-color:#00808000}

sass ✗

p{color:rgba(89,135,252,0);background:rgba(133,40,55,0);border-color:rgba(0%,50.2%,50.2%,0)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0052 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Simplify useless light-dark functions

The light-dark(a, b) CSS functions allows defining two possible colors based on the color-scheme setting. These will automatically switch when the color-scheme changes. However, if both values supplied are identical, then the entire function can be replaced with the value.

a {
  background: light-dark(var(--foo), var(--foo));
  color: light-dark(red, red);
}

Expected

a{background:var(--foo);color:red}

Outputs

clean-css ✗

a{background:light-dark(var(--foo),var(--foo));color:light-dark(red,red)}

csskit ✗

a{background:light-dark(var(--foo),var(--foo));color:light-dark(red,red)}

csslop ✓

a{background:var(--foo);color:red}

cssnano ✗

a{background:light-dark(var(--foo),var(--foo));color:light-dark(red,red)}

csso ✗

a{background:light-dark(var(--foo),var(--foo));color:light-dark(red,red)}

esbuild ✗

a{background:light-dark(var(--foo),var(--foo));color:light-dark(red,red)}

lightningcss ✗

a{background:light-dark(var(--foo),var(--foo));color:red}

sass ✗

a{background:light-dark(var(--foo), var(--foo));color:light-dark(red, red)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0053 ✓ ✓ ✓ ✓ ✓ ✗ ✓ ✗
Details

Shorten colors in light-dark functions

The light-dark(a, b) CSS functions allows defining two possible colors based on the color-scheme setting. These will automatically switch when the color-scheme changes. Both values should be minified to their shortest correct representation.

a {
  color: light-dark(#FF0000, #D2B48C);
}

Expected

a{color:light-dark(red,tan)}

Outputs

clean-css ✓

a{color:light-dark(red,tan)}

csskit ✓

a{color:light-dark(red,tan)}

csslop ✓

a{color:light-dark(red,tan)}

cssnano ✓

a{color:light-dark(red,tan)}

csso ✓

a{color:light-dark(red,tan)}

esbuild ✗

a{color:light-dark(#FF0000,#D2B48C)}

lightningcss ✓

a{color:light-dark(red,tan)}

sass ✗

a{color:light-dark(#FF0000, #D2B48C)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0054 ✗ ✗ ✓ ✗ ✗ ✗ ✓ ✗
Details

Shorten colors in light-dark functions and simplify if useless

After converting both colors in a light-dark function to their shortest representation, if the results are identical values, then the entire function can be replaced by just the value.

a {
  color: light-dark(#FF0000, rgb(255, 0, 0));
}

Expected

a{color:red}

Outputs

clean-css ✗

a{color:light-dark(red,red)}

csskit ✗

a{color:light-dark(red,red)}

csslop ✓

a{color:red}

cssnano ✗

a{color:light-dark(red,red)}

csso ✗

a{color:light-dark(red,red)}

esbuild ✗

a{color:light-dark(#FF0000,rgb(255,0,0))}

lightningcss ✓

a{color:red}

sass ✗

a{color:light-dark(#FF0000, rgb(255, 0, 0))}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0055 ✗ ✗ ✓ ✗ ✗ ✗ ✓ ✗
Details

Remove useless calc's in hsl(from)

The calculations used here can all be resolved and simplified.

  • a{color:hsl(from rebeccapurple calc(h)calc(s*1)calc(l + 0)/calc(1 / 1))}
  • a{color:hsl(from rebeccapurple calc(h)calc(s*1)calc(l + 0)/1)}
  • a{color:hsl(from rebeccapurple calc(h)calc(s*1)l/1)}
  • a{color:hsl(from rebeccapurple calc(h)s l/1)}
  • a{color:hsl(from rebeccapurple h s l/1)}
  • a{color:rebeccapurple}
  • a{color:#639}

a {
  color: hsl(from rebeccapurple calc(h) calc(s * 1) calc(l + 0) / calc(1 / 1));
}

Expected

a{color:#639}

Outputs

clean-css ✗

a{color:hsl(from #663399 calc(h) calc(s * 1) calc(l + 0)/ calc(1 / 1))}

csskit ✗

a{color:hsl(from rebeccapurple calc(h) calc(s * 1) calc(l + 0) / calc(1 / 1))}

csslop ✓

a{color:#639}

cssnano ✗

a{color:hsl(from rebeccapurple calc(h) calc(s) calc(0 + l)/calc(1))}

csso ✗

a{color:hsl(from rebeccapurple calc(h) calc(s*1) calc(l + 0)/calc(1/1))}

esbuild ✗

a{color:hsl(from rebeccapurple h calc(s*1) calc(l + 0) / 1)}

lightningcss ✓

a{color:#639}

sass ✗

a{color:hsl(from rebeccapurple calc(h) calc(s * 1) calc(l + 0)/1)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0056 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Collapse whitesparound around calc in an hsl(from)

Whitespace around adjacent calc's in an hsl(from) can be removed.

a {
  --red:#f01;
  --h:10;
  color: hsl(from var(--red) calc(var(--h)) calc(s * 2) calc(l + 1) / 0.6);
}

Expected

a{--red:#f01;--h:10;color:hsl(from var(--red)calc(var(--h))calc(s*2)calc(l + 1)/.6)}

Outputs

clean-css ✗

a{--red:#f01;--h:10;color:hsl(from var(--red) calc(var(--h)) calc(s * 2) calc(l + 1)/ .6)}

csskit ✗

a{--red:#f01;--h:10;color:hsl(from var(--red) calc(var(--h)) calc(s * 2) calc(l + 1) / .6)}

csslop ✓

a{--red:#f01;--h:10;color:hsl(from var(--red)calc(var(--h))calc(s*2)calc(l + 1)/.6)}

cssnano ✗

a{--red:#f01;--h:10;color:hsl(from var(--red) calc(var(--h)) calc(2 * s) calc(1 + l)/.6)}

csso ✗

a{--red:#f01;--h:10;color:hsl(from var(--red) calc(var(--h)) calc(s*2) calc(l + 1)/.6)}

esbuild ✗

a{--red:#f01;--h:10;color:hsl(from var(--red) calc(var(--h)) calc(s*2) calc(l + 1) / .6)}

lightningcss ✗

a{--red:#f01;--h:10;color:hsl(from var(--red) calc(var(--h)) calc(s * 2) calc(l + 1) / .6)}

sass ✗

a{--red:#f01;--h:10;color:hsl(from var(--red) calc(var(--h)) calc(s * 2) calc(l + 1)/0.6)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0057 ✗ ✓ ✓ ✗ ✗ ✓ ✗ ✗
Details

Convert LAB color to keyword name when shorter

LAB color spaces with percents that exactly produce an in-gamut sRGB color value should be converted to hex or color keyword, whichever is shortest.

a {
  color: lab(54.291% 64.644% 55.913%);
}

Expected

a{color:red}

Outputs

clean-css ✗

a{color:lab(54.291% 64.644% 55.913%)}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✗

a{color:lab(54.291% 64.644% 55.913%)}

csso ✗

a{color:lab(54.291% 64.644% 55.913%)}

esbuild ✓

a{color:red}

lightningcss ✗

a{color:lab(54.291% 80.805 69.8913)}

sass ✗

a{color:lab(54.291 80.805 69.89125)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0058 ✗ ✓ ✓ ✗ ✗ ✓ ✗ ✗
Details

Convert numeric LAB color to keyword name when shorter

LAB color spaces with numbers that exactly produce an in-gamut sRGB color value should be converted to hex or color keyword, whichever is shortest.

a {
  color: lab(54.291 80.805 69.8913);
}

Expected

a{color:red}

Outputs

clean-css ✗

a{color:lab(54.291 80.805 69.8913)}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✗

a{color:lab(54.291 80.805 69.8913)}

csso ✗

a{color:lab(54.291 80.805 69.8913)}

esbuild ✓

a{color:red}

lightningcss ✗

a{color:lab(54.291% 80.805 69.8913)}

sass ✗

a{color:lab(54.291 80.805 69.8913)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0059 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Remove .0 decimal from display-p3

The .0 in the number values of a display-p3 give no additional information and can be removed. Importantly, color(display-p3 1 0 0), should not be converted to a more narrow gamut like sRGB (rgb(255, 0, 0), #F00, red, etc).

a {
  color: color(display-p3 1.0 0.0 0.0);
}

Expected

a{color:color(display-p3 1 0 0)}

Outputs

clean-css ✓

a{color:color(display-p3 1 0 0)}

csskit ✓

a{color:color(display-p3 1 0 0)}

csslop ✓

a{color:color(display-p3 1 0 0)}

cssnano ✓

a{color:color(display-p3 1 0 0)}

csso ✓

a{color:color(display-p3 1 0 0)}

esbuild ✓

a{color:color(display-p3 1 0 0)}

lightningcss ✓

a{color:color(display-p3 1 0 0)}

sass ✓

a{color:color(display-p3 1 0 0)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0060 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Short-hex to color keyword

If a short hex representation is longer than the color keyword representation, use the keyword.

a {
  color: #f00;
}

Expected

a{color:red}

Outputs

clean-css ✓

a{color:red}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✓

a{color:red}

csso ✓

a{color:red}

esbuild ✓

a{color:red}

lightningcss ✓

a{color:red}

sass ✓

a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0061 ✗ ✓ ✓ ✓ ✗ ✓ ✓ ✓
Details

RRGGBBAA Hex to color keyword

If a longform hex can be represented with a shortform hex or color keyword, use the shortest representation.

a {
  color: #ff0000ff;
}

Expected

a{color:red}

Outputs

clean-css ✗

a{color:#ff0000ff}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✓

a{color:red}

csso ✗

a{color:#ff0000ff}

esbuild ✓

a{color:red}

lightningcss ✓

a{color:red}

sass ✓

a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0062 ✗ ✓ ✓ ✓ ✗ ✗ ✓ ✓
Details

Numeric HSL values to color keyword

If an HSL color uses numeric values that could be represented with a shorter hex or color keyword representation, use the shortest option.

a {
  color: hsl(0 100 50);
}

Expected

a{color:red}

Outputs

clean-css ✗

a{color:hsl(0 100 50)}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✓

a{color:red}

csso ✗

a{color:hsl(0 100 50)}

esbuild ✗

a{color:hsl(0 100 50)}

lightningcss ✓

a{color:red}

sass ✓

a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
2ms
0063 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

RGBA to color keyword

Convert all RGBA color representations to hex or color keywords, whichever is shortest.

a {
  color: rgba(255, 0, 0, 1);
}

Expected

a{color:red}

Outputs

clean-css ✓

a{color:red}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✓

a{color:red}

csso ✓

a{color:red}

esbuild ✓

a{color:red}

lightningcss ✓

a{color:red}

sass ✓

a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0064 ✗ ✓ ✓ ✓ ✗ ✗ ✓ ERROR
Details

Numeric HWB values to color keyword

If an HWB color uses numeric values that could be represented with a shorter hex or color keyword representation, use the shortest option.

a {
  color: hwb(0 0 0);
}

Expected

a{color:red}

Outputs

clean-css ✗

a{color:hwb(0 0 0)}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✓

a{color:red}

csso ✗

a{color:hwb(0 0 0)}

esbuild ✗

a{color:hwb(0 0 0)}

lightningcss ✓

a{color:red}

sass ✗

$whiteness: Expected 0 to have unit "%".
  ╷
2 │   color: hwb(0 0 0);
  │          ^^^^^^^^^^
  ╵
  - 2:10  root stylesheet
1ms
1ms
1ms
1ms
1ms
1ms
1ms
2ms
0065 ✗ ✓ ✓ ✓ ✗ ✗ ✓ ✗
Details

Do not convert outline:transparent to outline:none

A transparent outline does not display anything on the screen in most situations, making it equivalent to setting the outline to none. Though this is fewer characters it may break accessibility. Users with their OS in "High Contrast" mode will actually see an outline when it is set to transparent, but will not when it is set to none. You can however convert transparent to #0000, which is functionally equivalent according to the CSS spec.

button {
  outline: transparent;
}

Expected

button{outline:#0000}

Outputs

clean-css ✗

button{outline:transparent}

csskit ✓

button{outline:#0000}

csslop ✓

button{outline:#0000}

cssnano ✓

button{outline:#0000}

csso ✗

button{outline:transparent}

esbuild ✗

button{outline:transparent}

lightningcss ✓

button{outline:#0000}

sass ✗

button{outline:rgba(0,0,0,0)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0066 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

Color-mix in OKLCH to color keyword

If all values in the color mix are the same, they can be merged into a single color and reduced to its shortest representation.

.a {
  color: color-mix(in oklch, #f00, red);
  background: color-mix(in oklch, #d2b48c, tan)
}

Expected

.a{color:red;background:tan}

Outputs

clean-css ✗

.a{color:color-mix(in oklch,red,red);background:color-mix(in oklch,tan,tan)}

csskit ✓

.a{color:red;background:tan}

csslop ✓

.a{color:red;background:tan}

cssnano ✗

.a{color:color-mix(in oklch,red,red);background:color-mix(in oklch,tan,tan)}

csso ✗

.a{color:color-mix(in oklch,red,red);background:color-mix(in oklch,tan,tan)}

esbuild ✗

.a{color:color-mix(in oklch,#f00,red);background:color-mix(in oklch,#d2b48c,tan)}

lightningcss ✗

.a{color:oklch(62.7955% .257683 29.2339);background:oklch(78.6187% .063821 74.619)}

sass ✗

.a{color:color-mix(in oklch, #f00, red);background:color-mix(in oklch, #d2b48c, tan)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0067 ✗ ✓ ✓ ✗ ✗ ✓ ✗ ✗
Details

High precision OKLCH to color keyword

Given a high precision OKLCH color representation that is equivalent to an RGB color value, in this case rgb(255, 0, 0), convert it to its shortest hex or named color keyword representation.

.b {
  color: oklch(62.7955% .257683 29.2339);
  background: oklch(78.6187% .063821 74.619);
}

Expected

.b{color:red;background:tan}

Outputs

clean-css ✗

.b{color:oklch(62.7955% .257683 29.2339);background:oklch(78.6187% .063821 74.619)}

csskit ✓

.b{color:red;background:tan}

csslop ✓

.b{color:red;background:tan}

cssnano ✗

.b{color:oklch(62.7955% .257683 29.2339);background:oklch(78.6187% .063821 74.619)}

csso ✗

.b{color:oklch(62.7955%.257683 29.2339);background:oklch(78.6187%.063821 74.619)}

esbuild ✓

.b{color:red;background:tan}

lightningcss ✗

.b{color:oklch(62.7955% .257683 29.2339);background:oklch(78.6187% .063821 74.619)}

sass ✗

.b{color:oklch(.627955 .257683 29.2339);background:oklch(.786187 .063821 74.619)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0068 ✗ ✓ ✓ ✗ ✗ ✓ ✗ ✗
Details

Low precision OKLCH to color keyword

Lower decimal point precision (DPP) OKLCH representations are perceptually identical to their higher precision versions. Given a lower precision OKLCH color representation that is equivalent to an RGB color value, in this case rgb(255, 0, 0), convert it to its shortest hex or named color keyword representation.

.c {
  color: oklch(.628 .2577 29.23);
  background: oklch(.786 .064 74.6);
}

Expected

.c{color:red;background:tan}

Outputs

clean-css ✗

.c{color:oklch(.628 .2577 29.23);background:oklch(.786 .064 74.6)}

csskit ✓

.c{color:red;background:tan}

csslop ✓

.c{color:red;background:tan}

cssnano ✗

.c{color:oklch(.628 .2577 29.23);background:oklch(.786 .064 74.6)}

csso ✗

.c{color:oklch(.628 .2577 29.23);background:oklch(.786 .064 74.6)}

esbuild ✓

.c{color:red;background:tan}

lightningcss ✗

.c{color:oklch(62.8% .2577 29.23);background:oklch(78.6% .064 74.6)}

sass ✗

.c{color:oklch(.628 .2577 29.23);background:oklch(.786 .064 74.6)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0069 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

Remove space in border shorthand before hex with alpha

The # in a hex color is an unambiguous token start, allowing the preceding space to be dropped.

See also: colors/0034

a {
  border: 3px solid #0006;
}

Expected

a{border:3px solid#0006}

Outputs

clean-css ✗

a{border:3px solid #0006}

csskit ✓

a{border:3px solid#0006}

csslop ✓

a{border:3px solid#0006}

cssnano ✗

a{border:3px solid #0006}

csso ✗

a{border:3px solid #0006}

esbuild ✗

a{border:3px solid #0006}

lightningcss ✗

a{border:3px solid #0006}

sass ✗

a{border:3px solid rgba(0,0,0,.4)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0070 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Do not rename grey/gray when used in a custom-property name

References to custom property names must not be changed.

div {
  background: var(--gray);
  color: var(--grey);
}

Expected

div{background:var(--gray);color:var(--grey)}

Outputs

clean-css ✓

div{background:var(--gray);color:var(--grey)}

csskit ✓

div{background:var(--gray);color:var(--grey)}

csslop ✓

div{background:var(--gray);color:var(--grey)}

cssnano ✓

div{background:var(--gray);color:var(--grey)}

csso ✓

div{background:var(--gray);color:var(--grey)}

esbuild ✓

div{background:var(--gray);color:var(--grey)}

lightningcss ✓

div{background:var(--gray);color:var(--grey)}

sass ✓

div{background:var(--gray);color:var(--grey)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0071 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

color-mix() with none alpha premultiplies after filling alpha

A alpha of none in color-mix() takes the other color's alpha (0.5) before premultiplication, so both colors are premultiplied by 0.5. Treating none as 0 instead gives incorrect results.

References:

a {
  color: color-mix(in srgb, color(srgb 0.4 0.4 0 / none), color(srgb 0.4 0 0.4 / 0.5));
}

Expected

a{color:#66333380}

Outputs

clean-css ✗

a{color:color-mix(in srgb,color(srgb .4 .4 0 / none),color(srgb .4 0 .4 / .5))}

csskit ✓

a{color:#66333380}

csslop ✓

a{color:#66333380}

cssnano ✗

a{color:color-mix(in srgb,color(srgb .4 .4 0/none),color(srgb .4 0 .4/.5))}

csso ✗

a{color:color-mix(in srgb,color(srgb .4 .4 0/none),color(srgb .4 0 .4/.5))}

esbuild ✗

a{color:color-mix(in srgb,color(srgb .4 .4 0 / none),color(srgb .4 0 .4 / .5))}

lightningcss ✓

a{color:#66333380}

sass ✗

a{color:color-mix(in srgb, color(srgb 0.4 0.4 0 / none), color(srgb 0.4 0 0.4 / 0.5))}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0072 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

color-mix() with none alpha in legacy rgb() premultiplies after filling alpha

Like color(srgb ...), rgb() with an alpha of none must keep the missing alpha through interpolation, which means color-mix must adopt 0.5 from the other color. Losing none early gives an incorrect result.

References:

a {
  color: color-mix(in srgb, rgb(100 100 0 / none), rgb(100 0 100 / 0.5));
}

Expected

a{color:#64323280}

Outputs

clean-css ✗

a{color:color-mix(in srgb,rgb(100 100 0 / none),rgb(100 0 100 / .5))}

csskit ✓

a{color:#64323280}

csslop ✓

a{color:#64323280}

cssnano ✗

a{color:color-mix(in srgb,#64640000,#64006480)}

csso ✗

a{color:color-mix(in srgb,rgb(100 100 0/none),rgb(100 0 100/.5))}

esbuild ✗

a{color:color-mix(in srgb,rgb(100 100 0 / none),rgb(100 0 100 / .5))}

lightningcss ✓

a{color:#64323280}

sass ✗

a{color:color-mix(in srgb, rgb(100 100 0 / none), rgba(100, 0, 100, 0.5))}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 27 / 72 63 / 72 72 / 72 42 / 72 29 / 72 38 / 72 48 / 72 25 / 72
Percent 37.5% 87.5% 100% 58.33% 40.27% 52.77% 66.66% 34.72%
Duration 5ms 9ms 18ms 56ms 9ms 38ms 1ms 58ms

combined #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Merge rules after property and selector optimizations

This test validates correct order of operations in a minifier. If the merging or de-duplication of rules occurs prior to selector and/or property optimizations, then it will miss out on opportunities for merging identical rules that are only revealed after they've had those optimizations.

  1. All property optimizations should be done
    • Colors converted to smallest representations
    • Border shorthand applied
    • etc.
  2. Selectors on individual rules are optimized
    • :where(td):where(.error) => :where(td.error)
    • :is(span, div) => span,div
    • etc.
  3. Merging/deduping of rules is applied
    • div,span,:where(td.error),span,div => div,span,:where(td.error)

Before attempting to pass this test, first pass the tests it combines:

  • colors/0002 - #FF0000 -> red
  • colors/0016 - rgba(255 0 0 / 1) -> red
  • colors/0075 - hsl(0 100 50) -> red
  • duplicates/0007 - a{color:red}a{color:red} -> a{color:red}
  • selectors-advanced/0001 - :is(a,b) -> a,b
  • selectors-advanced/0018 - :where(.foo):where([bar]) -> :where(.foo[bar])
  • shorthands/0041 - (border-(color/style/width) = border)

div,
span,
:where(td):where(.error) {
  border: 1px dashed hsl(0 100 50);
  color: #FF0000;
}

:is(div, span) {
  border-color: #F00;
  border-style: dashed;
  border-width: 1px;
  color: rgba(255 0 0 / 1.0);
}

Expected

div,span,:where(td.error){border:1px dashed red;color:red}

Outputs

clean-css ✗

:where(td):where(.error),div,span{border:1px dashed;color:red}:is(div,span){border:1px dashed red;color:rgba(255 0 0 / 1)}

csskit ✗

div,span,:where(td):where(.error){border:1px dashed red;color:red}:is(div,span){border-color:red;border-style:dashed;border-width:1px;color:red}

csslop ✓

div,span,:where(td.error){border:1px dashed red;color:red}

cssnano ✗

:where(td):where(.error),div,span{border:1px dashed red;color:red}:is(div,span){border-color:red;border-style:dashed;border-width:1px;color:red}

csso ✗

:where(td):where(.error),div,span{border:1px dashed hsl(0 100 50);color:red}:is(div,span){border-color:red;border-style:dashed;border-width:1px;color:rgba(255 0 0/1)}

esbuild ✗

div,span,:where(td):where(.error){border:1px dashed hsl(0 100 50);color:red}:is(div,span){border-color:red;border-style:dashed;border-width:1px;color:red}

lightningcss ✗

div,span,:where(td):where(.error),:is(div,span){color:red;border:1px dashed red}

sass ✗

div,span,:where(td):where(.error){border:1px dashed red;color:red}:is(div,span){border-color:red;border-style:dashed;border-width:1px;color:red}
2ms
1ms
2ms
8ms
1ms
1ms
1ms
2ms
0002 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ERROR
Details

Merge identical adjacent rules after color minification

After other optimizations are complete, like minifying color representations, merge any identical adjacent rules.

Combines:

  • colors/0002 - #FF0000
  • colors/0003 - rgb(255, 0, 0)
  • colors/0008 - hsl(0, 100%, 50%)
  • colors/0016 - rgb(255 0 0 / 1)
  • colors/0010 - hwb(0 0% 0%)
  • colors/0021 - rgb(255 none none)
  • colors/0023 - red
  • colors/0024 - color-mix(in srgb, rgb(none 0 0) 50%, rgb(255 0 0) 50%)
  • colors/0028 - color-mix(in srgb, red, red)
  • colors/0036 - color-mix(in srgb, red 100%, blue)
  • colors/0037 - color-mix(in srgb, blue 0%, red)
  • colors/0041 - color-mix(in srgb, red, blue 0%)
  • colors/0067 - light-dark(red, red)
  • colors/0070 - lab(54.291% 64.644% 55.913%)
  • colors/0071 - lab(54.291 80.805 69.8913)
  • colors/0073 - #F00
  • colors/0074 - #FF0000FF
  • colors/0075 - hsl(0 100 50)
  • colors/0076 - rgba(255, 0, 0, 1)
  • colors/0077 - hwb(0 0 0)
  • comments/0001 - a{color:red}/* comment */ -> a{color:red}
  • merging/0002 - .a {color:red}.b{color:red} -> .a,.b{color:red}
  • whitespace/0001 - a {\n color: red;\n} -> a{color:red}

.a { color: #F00; } /* colors/0073 */
.b { color: rgba(255, 0, 0, 1); } /* colors/0076 */
.c { color: red; } /* colors/0023 */
.d { color: #FF0000; } /* colors/0002 */
.e { color: #FF0000FF; } /* colors/0074 */
.f { color: RGBA(255, 0, 0, 1.0); } /* colors/0076 */
.g { color: rgb(255, 0, 0); } /* `colors/0003` */
.h { color: RGB(255 0 0); } /* colors/0016 */
.i { color: rgba(255 0 0 / 1); } /* colors/0016 */
.j { color: rgb(255 none none); } /* colors/0021 */
.k { color: hsl(0 100 50); } /* colors/0075 */
.l { color: HSL(0, 100%, 50%); } /* colors/0008 */
.m { color: hwb(0 0 0); } /* colors/0077 */
.n { color: HWB(0 0% 0%); } /* colors/0010 */
.o { color: light-dark(#F00, red); } /* colors/0067 */
.p { color: lab(54.291% 64.644% 55.913%); } /* colors/0070 */
.q { color: lab(54.291 80.805 69.8913); } /* colors/0071 */
.r { color: color-mix(in srgb, red, red); } /* colors/0028 */
.s { color: color-mix(in srgb, red 100%, blue); } /* colors/0036 */
.t { color: color-mix(in srgb, blue 0%, red); } /* colors/0037 */
.u { color: color-mix(in srgb, red, blue 0%); } /* colors/0041 */
.v { color: color-mix(in srgb, rgb(none 0 0) 50%, rgb(255 0 0) 50%); } /* colors/0024 */

Expected

.a,.b,.c,.d,.e,.f,.g,.h,.i,.j,.k,.l,.m,.n,.o,.p,.q,.r,.s,.t,.u,.v{color:red}

Outputs

clean-css ✗

.a,.b,.c,.d{color:red}.e{color:#ff0000FF}.f,.g{color:red}.h{color:RGB(255 0 0)}.i{color:rgba(255 0 0 / 1)}.j{color:rgb(255 none none)}.k{color:hsl(0 100 50)}.l{color:red}.m{color:hwb(0 0 0)}.n{color:HWB(0 0% 0%)}.o{color:light-dark(red,red)}.p{color:lab(54.291% 64.644% 55.913%)}.q{color:lab(54.291 80.805 69.8913)}.r{color:color-mix(in srgb,red,red)}.s{color:color-mix(in srgb,red 100%,#00f)}.t{color:color-mix(in srgb,#00f 0%,red)}.u{color:color-mix(in srgb,red,#00f 0%)}.v{color:color-mix(in srgb,rgb(none 0 0) 50%,rgb(255 0 0) 50%)}

csskit ✗

.a{color:red}.b{color:red}.c{color:red}.d{color:red}.e{color:red}.f{color:red}.g{color:red}.h{color:red}.i{color:red}.j{color:red}.k{color:red}.l{color:red}.m{color:red}.n{color:red}.o{color:light-dark(red,red)}.p{color:red}.q{color:red}.r{color:red}.s{color:red}.t{color:red}.u{color:red}.v{color:red}

csslop ✓

.a,.b,.c,.d,.e,.f,.g,.h,.i,.j,.k,.l,.m,.n,.o,.p,.q,.r,.s,.t,.u,.v{color:red}

cssnano ✗

.a,.b,.c,.d,.e,.f,.g,.h,.i,.j,.k,.l,.m,.n{color:red}.o{color:light-dark(red,red)}.p{color:lab(54.291% 64.644% 55.913%)}.q{color:lab(54.291 80.805 69.8913)}.r{color:color-mix(in srgb,red,red)}.s{color:color-mix(in srgb,red 100%,blue)}.t{color:color-mix(in srgb,blue 0%,red)}.u{color:color-mix(in srgb,red,blue 0%)}.v{color:color-mix(in srgb,#000 50%,red 50%)}

csso ✗

.a,.b,.c,.d{color:red}.e{color:#ff0000ff}.f{color:RGBA(255,0,0,1)}.g{color:red}.h{color:RGB(255 0 0)}.i{color:rgba(255 0 0/1)}.j{color:rgb(255 none none)}.k{color:hsl(0 100 50)}.l{color:HSL(0,100%,50%)}.m{color:hwb(0 0 0)}.n{color:HWB(0 0% 0%)}.o{color:light-dark(red,red)}.p{color:lab(54.291% 64.644% 55.913%)}.q{color:lab(54.291 80.805 69.8913)}.r{color:color-mix(in srgb,red,red)}.s{color:color-mix(in srgb,red 100%,blue)}.t{color:color-mix(in srgb,blue 0%,red)}.u{color:color-mix(in srgb,red,blue 0%)}.v{color:color-mix(in srgb,rgb(none 0 0) 50%,rgb(255 0 0) 50%)}

esbuild ✗

.a,.b,.c,.d,.e,.f,.g,.h,.i{color:red}.j{color:rgb(255 none none)}.k{color:hsl(0 100 50)}.l{color:red}.m{color:hwb(0 0 0)}.n{color:red}.o{color:light-dark(#F00,red)}.p,.q{color:red}.r{color:color-mix(in srgb,red,red)}.s{color:color-mix(in srgb,red 100%,blue)}.t{color:color-mix(in srgb,blue 0%,red)}.u{color:color-mix(in srgb,red,blue 0%)}.v{color:color-mix(in srgb,rgb(none 0 0) 50%,rgb(255 0 0) 50%)}

lightningcss ✗

.a,.b,.c,.d,.e,.f,.g,.h,.i{color:red}.j{color:red}.k,.l,.m,.n,.o{color:red}.p{color:lab(54.291% 80.805 69.8913)}.q{color:lab(54.291% 80.805 69.8913)}.r,.s,.t,.u,.v{color:red}

sass ✗

$whiteness: Expected 0 to have unit "%".
   ╷
13 │ .m { color: hwb(0 0 0); } /* colors/0077 */
   │             ^^^^^^^^^^
   ╵
  - 13:13  root stylesheet
2ms
1ms
2ms
4ms
1ms
1ms
1ms
4ms
0003 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Introduce nesting to repeated selectors and deduplicate overridden properties

Nest adjacent rules where the selectors all start with the same prefix. Then, if any selectors are used in multiple nested rules with the same properties, remove the earlier defined property. If this results in any empty rules, remove those as well.

Combines:

  • duplicates/0020
    • h1,h2{color:#001}h1{color:#002}h2{color:#003} -> h1{color:#002}h2{color:#003}
  • empty-rules/0004
    • a{color:red;b{}} -> a{color:red}
  • nesting/0020
    • .foo .a{color:red}.foo .b{color:tan} -> .foo{.a{color:red}.b{color:tan}}

.foo {
  color: #001;
}
.foo h1,
.foo h2 {
  color: #002;
}
.foo h1 {
  color: #003;
}
.foo h2 {
  color: #004;
}

Expected

.foo{color:#001;h1{color:#003}h2{color:#004}}

Outputs

clean-css ✗

.foo{color:#001}.foo h1{color:#003}.foo h2{color:#004}

csskit ✗

.foo{color:#001}.foo h1,.foo h2{color:#002}.foo h1{color:#003}.foo h2{color:#004}

csslop ✓

.foo{color:#001;h1{color:#003}h2{color:#004}}

cssnano ✗

.foo{color:#001}.foo h1,.foo h2{color:#002}.foo h1{color:#003}.foo h2{color:#004}

csso ✗

.foo{color:#001}.foo h1{color:#003}.foo h2{color:#004}

esbuild ✗

.foo{color:#001}.foo h1,.foo h2{color:#002}.foo h1{color:#003}.foo h2{color:#004}

lightningcss ✗

.foo{color:#001}.foo h1,.foo h2{color:#002}.foo h1{color:#003}.foo h2{color:#004}

sass ✗

.foo{color:#001}.foo h1,.foo h2{color:#002}.foo h1{color:#003}.foo h2{color:#004}
1ms
1ms
1ms
2ms
1ms
1ms
1ms
1ms
0004 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Linear gradient optimizations and background property shorthand

Convert all colors to their minified representation first, then apply advanced linear-gradient optimizations and combine all background properties to use the background property shorthand.

Combines:

  • colors/0001 - Short hex
    • #ffffff -> #fff
  • colors/0002 - Hex to color keyword
    • #ff0000 -> red
  • colors/0003 - RGB to color keyword
    • rgb(255, 0, 0) -> red
  • colors/0008 - HSL to color keyword
    • hsl(0, 100%, 50%) -> red
  • colors/0011 - Color keyword to hex
    • blue -> #00f
  • gradients/0001 - Remove to bottom.
    • linear-gradient(to bottom, red, tan) -> linear-gradient(red,tan)
  • gradients/0006 - Combine colors in gradient and remove 0%/100%
    • linear-gradient(red 0%,red 50%,tan 50%,tan 100%) -> linear-gradient(red 50%,tan 0)
  • shorthands/0076 - Background properties shorthand
  • values/0072 - keyword to percent
    • background-position:right bottom; -> background-position:100% 100%;

p {
  background: linear-gradient(
    to bottom,
    #ff0000 0%,
    hsl(0, 100%, 50%) 25%,
    rgb(255, 0, 0) 50%,
    blue 50%,
    #0000ff 100%
  );
  background-position: right bottom;
}

Expected

p{background:linear-gradient(red 50%,#00f 0)100% 100%}

Outputs

clean-css ✗

p{background:linear-gradient(to bottom,red 0,red 25%,red 50%,#00f 50%,#00f 100%);background-position:right bottom}

csskit ✗

p{background:linear-gradient(to bottom,red 0%,red 25%,red 50%,blue 50%,#00f 100%);background-position:right bottom}

csslop ✓

p{background:linear-gradient(red 50%,#00f 0)100% 100%}

cssnano ✗

p{background:linear-gradient(180deg,red,red 25%,red 50%,blue 0,#00f);background-position:100% 100%}

csso ✗

p{background:linear-gradient(to bottom,red 0,red 25%,red 50%,#00f 50%,#00f 100%);background-position:right bottom}

esbuild ✗

p{background:linear-gradient(to bottom,red 0% 25%,red 50%,#00f 50% 100%);background-position:right bottom}

lightningcss ✗

p{background:linear-gradient(red 0% 25%,red 50%,#00f 50% 100%) 100% 100%}

sass ✗

p{background:linear-gradient(to bottom, #ff0000 0%, hsl(0, 100%, 50%) 25%, rgb(255, 0, 0) 50%, blue 50%, #0000ff 100%);background-position:right bottom}
1ms
1ms
2ms
2ms
1ms
1ms
1ms
1ms
0005 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Merge selectors with comma and perform advanced property shorthand

Remove the comment, merge rules with identical selectors, apply font shorthand.

Combines:

  • comments/0001 - Basic comment removal
  • merging/0019 - Merge identical selector separated by non-overlapping rules
  • shorthands/0017 - Font longhand merge

body {
  line-height: 1.5;
}
/* Comment */
html {
  color: red;
}
body {
  font-size: 75%;
  font-family: sans-serif;
}

Expected

html{color:red}body{font:75%/1.5 sans-serif}

Also accepted

body{font:75%/1.5 sans-serif}html{color:red}

Outputs

clean-css ✗

body{line-height:1.5;font-size:75%;font-family:sans-serif}html{color:red}

csskit ✗

body{line-height:1.5}html{color:red}body{font-size:75%;font-family:sans-serif}

csslop ✓

html{color:red}body{font:75%/1.5 sans-serif}

cssnano ✗

body{line-height:1.5;font-size:75%;font-family:sans-serif}html{color:red}

csso ✗

body{line-height:1.5;font-size:75%;font-family:sans-serif}html{color:red}

esbuild ✗

body{line-height:1.5}html{color:red}body{font-size:75%;font-family:sans-serif}

lightningcss ✗

body{line-height:1.5}html{color:red}body{font-family:sans-serif;font-size:75%}

sass ✗

body{line-height:1.5}html{color:red}body{font-size:75%;font-family:sans-serif}
1ms
1ms
1ms
2ms
1ms
1ms
1ms
1ms
0006 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Remove useless :is() and useless nesting

If there is no value in nesting selectors, un-nest them. If there is no value in wrapping a selector with :is(), unwrap it.

Combines:

  • nesting/0013 - Unnest empty parent - a{b{color:red}} =>a b{color:red}
  • selectors/0018 - Remove usesless :is() - :is(.x) => .x

:is(.x) {
  :is(.y) {
    color: red;
  }
}

Expected

.x .y{color:red}

Outputs

clean-css ✗

csskit ✗

:is(.x){:is(.y){color:red}}

csslop ✓

.x .y{color:red}

cssnano ✗

:is(.x){:is(.y){color:red}}

csso ✗

esbuild ✗

:is(.x){:is(.y){color:red}}

lightningcss ✗

.x{& .y{color:red}}

sass ✗

:is(.x) :is(.y){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0007 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Complex border shorthand with currentColor

In this example, the border properties are separated. The border-color is assigned to currentColor which is equivalent to initial, the default value for this property. So it can be removed. Because the border-width has multiple values, it cannot be included in the border shorthand. The shortest version of this rule would be to only include the style (dashed) in the border shorthand, followed by border-width as an override (this must not occur before the border shorthand, or the width values will be ignored by the browser). In this example, the border-radius can be placed anywhere in the rule safely.

Combines:

  • initial/0009 - Convert border-color currentcolor value to initial
  • shorthands/0020 - Border shorthand must not clobber border-image
  • shorthands/0059 - Border shorthand containing multiple widths

a {
  border-radius: 6px;
  border-color: currentColor;
  border-style: dashed;
  border-width: 1px 4px;
}

Expected

a{border-radius:6px;border:dashed;border-width:1px 4px}

Also accepted

a{border:dashed;border-radius:6px;border-width:1px 4px}
a{border:dashed;border-width:1px 4px;border-radius:6px}

Outputs

clean-css ✗

a{border-radius:6px;border-color:currentColor;border-style:dashed;border-width:1px 4px}

csskit ✗

a{border-radius:6px;border-color:currentColor;border-style:dashed;border-width:1px 4px}

csslop ✓

a{border-radius:6px;border:dashed;border-width:1px 4px}

cssnano ✗

a{border-radius:6px;border-color:currentcolor;border-style:dashed;border-width:1px 4px}

csso ✗

a{border-radius:6px;border-color:currentColor;border-style:dashed;border-width:1px 4px}

esbuild ✗

a{border-radius:6px;border-color:currentColor;border-style:dashed;border-width:1px 4px}

lightningcss ✗

a{border:1px dashed;border-width:1px 4px;border-radius:6px}

sass ✗

a{border-radius:6px;border-color:currentColor;border-style:dashed;border-width:1px 4px}
1ms
1ms
1ms
3ms
1ms
1ms
1ms
1ms
0008 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Nest adjacent rules separated by a comment with child combinator

In this example, a minifier should remove the comment. Then nest the two adjacent rules that share common ancestors in their selectors. These rules should nest with the direct descendant (child combinator >). The first rule looks unnecessarily nested. A minifier may try to un-nest it, rather than nest it with the following rule, which would result in a longer output.

#a .b {
  > .c {
    color: red;
  }
}
/* comment */
#a .b > .d {
  color: tan;
}

Expected

#a .b{>.c{color:red}>.d{color:tan}}

Outputs

clean-css ✗

csskit ✗

#a .b{>.c{color:red}}#a .b>.d{color:tan}

csslop ✓

#a .b{>.c{color:red}>.d{color:tan}}

cssnano ✗

#a .b{> .c{color:red}}#a .b>.d{color:tan}

csso ✗

#a .b>.d{color:tan}

esbuild ✗

#a .b{>.c{color:red}}#a .b>.d{color:tan}

lightningcss ✗

#a .b{&>.c{color:red}}#a .b>.d{color:tan}

sass ✗

#a .b>.c{color:red}#a .b>.d{color:tan}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0009 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Remove useles rule after unwrapping :is()

In this test the :is contains a single selector of a known-safe value. It is therefore equivalent to unwrap the :is. The remaining rule is followed by a rule targeting a matching selector with all of the same properties, making the first rule redundant and safe to remove.

Combines:

  • duplicates/0002 - Duplicate rule removal - a{x:y}a{x:z} => a{x:z}
  • selectors/0018 - Remove usesless :is() - :is(.x) => .x

:is(a) {
  color: red;
}
a {
  color: tan;
}

Expected

a{color:tan}

Outputs

clean-css ✗

:is(a){color:red}a{color:tan}

csskit ✗

:is(a){color:red}a{color:tan}

csslop ✓

a{color:tan}

cssnano ✗

:is(a){color:red}a{color:tan}

csso ✗

:is(a){color:red}a{color:tan}

esbuild ✗

:is(a){color:red}a{color:tan}

lightningcss ✗

:is(a){color:red}a{color:tan}

sass ✗

:is(a){color:red}a{color:tan}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0010 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Merge and nest rules and media queries separated by each other

In this example, the first media query does not have anything that would override the following rule, so it is safe to move it above the query. This then groups the two rules and two queries to be adjacent to each other. The media query conditions are identical, and can therefor be merged. The rules above, and inside the queries, can be nested.

Combines:

  • merging/0031 - Merge rules and media queries separated by each other
  • nesting/0010 - Introduce nesting

.a .b {
  margin: 0;
}
@media (width < 640px) {
  .a .b {
    margin: 1px;
  }
}
.a .b .c {
  padding: 0;
}
@media (width < 640px) {
  .a .b .c {
    padding: 1px;
  }
}

Expected

.a .b{margin:0;.c{padding:0}}@media(width<640px){.a .b{margin:1px;.c{padding:1px}}}

Outputs

clean-css ✗

.a .b{margin:0}.a .b .c{padding:0}@media (width < 640px){.a .b{margin:1px}.a .b .c{padding:1px}}

csskit ✗

.a .b{margin:0}@media(width<640px){.a .b{margin:1px}}.a .b .c{padding:0}@media(width<640px){.a .b .c{padding:1px}}

csslop ✓

.a .b{margin:0;.c{padding:0}}@media(width<640px){.a .b{margin:1px;.c{padding:1px}}}

cssnano ✗

.a .b{margin:0}.a .b .c{padding:0}@media(width<640px){.a .b{margin:1px}.a .b .c{padding:1px}}

csso ✗

.a .b{margin:0}.a .b .c{padding:0}

esbuild ✗

.a .b{margin:0}@media(width<640px){.a .b{margin:1px}}.a .b .c{padding:0}@media(width<640px){.a .b .c{padding:1px}}

lightningcss ✗

.a .b{margin:0}@media (width<640px){.a .b{margin:1px}}.a .b .c{padding:0}@media (width<640px){.a .b .c{padding:1px}}

sass ✗

.a .b{margin:0}@media(width < 640px){.a .b{margin:1px}}.a .b .c{padding:0}@media(width < 640px){.a .b .c{padding:1px}}
1ms
2ms
2ms
3ms
1ms
1ms
1ms
1ms
0011 ✗ ✗ ✓ ✓ ✓ ✗ ✗ ✗
Details

Merge common properties of adjacent rules after comment removal

Combines:

  • comments\0001 - Basic comment removal
  • merging\0033 - Merge common properties of adjacent rules

a {
  color: red;
}
/* comment */
b {
  color: red;
  line-height: 1;
}

Expected

a,b{color:red}b{line-height:1}

Also accepted

b{line-height:1}a,b{color:red}

Outputs

clean-css ✗

a{color:red}b{color:red;line-height:1}

csskit ✗

a{color:red}b{color:red;line-height:1}

csslop ✓

a,b{color:red}b{line-height:1}

cssnano ✓

a,b{color:red}b{line-height:1}

csso ✓

a,b{color:red}b{line-height:1}

esbuild ✗

a{color:red}b{color:red;line-height:1}

lightningcss ✗

a{color:red}b{color:red;line-height:1}

sass ✗

a{color:red}b{color:red;line-height:1}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0012 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Nest and merge descendant selectors with common properties

Combines:

  • merging/0033 - Merge common properties of adjacent rules
  • nesting/0045 - Nest child selectors with combinator

.foo > .bar::before {
  color: red;
}
.foo > .bar::after {
  color: red;
  padding: 10px;
}

Expected

.foo>.bar{&:before,&:after{color:red}&:after{padding:10px}}

Outputs

clean-css ✗

.foo>.bar::before{color:red}.foo>.bar::after{color:red;padding:10px}

csskit ✗

.foo>.bar::before{color:red}.foo>.bar::after{color:red;padding:10px}

csslop ✓

.foo>.bar{&:before,&:after{color:red}&:after{padding:10px}}

cssnano ✗

.foo>.bar:before{color:red}.foo>.bar:after{color:red;padding:10px}

csso ✗

.foo>.bar::before{color:red}.foo>.bar::after{color:red;padding:10px}

esbuild ✗

.foo>.bar:before{color:red}.foo>.bar:after{color:red;padding:10px}

lightningcss ✗

.foo>.bar:before{color:red}.foo>.bar:after{color:red;padding:10px}

sass ✗

.foo>.bar::before{color:red}.foo>.bar::after{color:red;padding:10px}
1ms
1ms
1ms
2ms
1ms
1ms
1ms
1ms
Subtotal 0 / 12 0 / 12 12 / 12 1 / 12 1 / 12 0 / 12 0 / 12 0 / 12
Percent 0% 0% 100% 8.33% 8.33% 0% 0% 0%
Duration 7ms 6ms 13ms 31ms 5ms 6ms 1ms 14ms

comments #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Basic comment removal

Standard /* ... */ comments should be stripped entirely.

/* comment */
a {
  color: red;
}

Expected

a{color:red}

Outputs

clean-css ✓

a{color:red}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✓

a{color:red}

csso ✓

a{color:red}

esbuild ✓

a{color:red}

lightningcss ✓

a{color:red}

sass ✓

a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Inline comment removal

A comment embedded within a declaration value (color: /* inline */ red) must be removed without breaking the surrounding value.

a {
  color: /* inline */ red;
}

Expected

a{color:red}

Outputs

clean-css ✓

a{color:red}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✓

a{color:red}

csso ✓

a{color:red}

esbuild ✓

a{color:red}

lightningcss ✓

a{color:red}

sass ✓

a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✓ ✗ ✓ ✓ ✗ ✓ ✗ ✓
Details

Important comment preservation

Comments starting with /*! are license/legal markers and must be preserved. Stripping them can cause legal compliance issues.

/*! important */
a {
  color: red;
}

Expected

/*! important */a{color:red}

Outputs

clean-css ✓

/*! important */a{color:red}

csskit ✗

a{color:red}

csslop ✓

/*! important */a{color:red}

cssnano ✓

/*! important */a{color:red}

csso ✗

/*! important */
a{color:red}

esbuild ✓

/*! important */a{color:red}

lightningcss ✗

/*! important */
a{color:red}

sass ✓

/*! important */a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✓ ✗ ✓ ✗ ✓ ✗ ✗ ✗
Details

Comment in custom property value must be preserved

--bar: a/**/b tokenizes as ident:a ident:b with no whitespace between them. Replacing the comment with a space produces a b which is a different token sequence. This matters for @container style() queries matching against custom property values.

a {
  --bar: a/**/b;
}

Expected

a{--bar:a/**/b}

Outputs

clean-css ✓

a{--bar:a/**/b}

csskit ✗

a{--bar:a b}

csslop ✓

a{--bar:a/**/b}

cssnano ✗

a{--bar:a b}

csso ✓

a{--bar:a/**/b}

esbuild ✗

a{--bar: ab}

lightningcss ✗

a{--bar:ab}

sass ✗

a{--bar: a/**/b}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Comment in @container style query custom property must be preserved

@container style(--bar: a/**/b) uses a comment as a zero-width token separator. Replacing it with a space or removing it entirely changes the token sequence the query matches against, breaking the correspondence with the declaration --bar: a/**/b.

@container style(--bar: a/**/b) {
  a {
    color: red;
  }
}

Expected

@container style(--bar:a/**/b){a{color:red}}

Outputs

clean-css ✗

@container style(--bar:ab){a{color:red}}

csskit ✗

@container style(--bar:a b){a{color:red}}

csslop ✓

@container style(--bar:a/**/b){a{color:red}}

cssnano ✗

@container style(--bar: a b){a{color:red}}

csso ✗

@container style(--bar: a/**/b){a{color:red}}

esbuild ✗

@container style(--bar: ab){a{color:red}}

lightningcss ✗

@container style(--bar:ab){a{color:red}}

sass ✗

@container style(--bar: a/**/b){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Remove comments from inside keyframes percents

Comments inside of keyframes should be removed.

@keyframes fade {
  0% {
    /* A comment */
    opacity: 1;
  }
  to {
    /* A comment */
    opacity: 0;
  }
}

Expected

@keyframes fade{0%{opacity:1}to{opacity:0}}

Outputs

clean-css ✓

@keyframes fade{0%{opacity:1}to{opacity:0}}

csskit ✓

@keyframes fade{0%{opacity:1}to{opacity:0}}

csslop ✓

@keyframes fade{0%{opacity:1}to{opacity:0}}

cssnano ✓

@keyframes fade{0%{opacity:1}to{opacity:0}}

csso ✓

@keyframes fade{0%{opacity:1}to{opacity:0}}

esbuild ✓

@keyframes fade{0%{opacity:1}to{opacity:0}}

lightningcss ✓

@keyframes fade{0%{opacity:1}to{opacity:0}}

sass ✓

@keyframes fade{0%{opacity:1}to{opacity:0}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0007 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Remove comments from custom-property values

If a custom-property is assigned to only a CSS comment, the entire comment can safely be removed. However, the custom-property declaration must remain. If a custom-property contains values with a comment between them, then the comment token must remain, though it's contents can be removed.

:root {
  --foo:/*base-color*/;
  --bar:12/* some text */12;
  --black:#000;
}

Expected

:root{--foo:;--bar:12/**/12;--black:#000}

Outputs

clean-css ✗

:root{--foo:/*base-color*/;--bar:12/* some text */12;--black:#000}

csskit ✗

:root{--foo:;--bar:12 12;--black:#000}

csslop ✓

:root{--foo:;--bar:12/**/12;--black:#000}

cssnano ✗

:root{--foo: ;--bar:12 12;--black:#000}

csso ✗

:root{--foo:/*base-color*/;--bar:12/* some text */12;--black:#000}

esbuild ✗

:root{--foo:;--bar:1212;--black:#000}

lightningcss ✗

:root{--foo:;--bar:1212;--black:#000}

sass ✗

:root{--foo:/*base-color*/;--bar:12/* some text */12;--black:#000}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 5 / 7 3 / 7 7 / 7 4 / 7 4 / 7 4 / 7 3 / 7 4 / 7
Percent 71.42% 42.85% 100% 57.14% 57.14% 57.14% 42.85% 57.14%
Duration 1ms 1ms 2ms 6ms 1ms 4ms 1ms 5ms

container #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

@container whitespace removal

Remove whitespace inside @container query while preserving the container name and condition. The space between name and ( is required.

@container sidebar (width > 700px) {
  a {
    color: red;
  }
}

Expected

@container sidebar (width>700px){a{color:red}}

Outputs

clean-css ✗

@container sidebar (width > 700px){a{color:red}}

csskit ✓

@container sidebar (width>700px){a{color:red}}

csslop ✓

@container sidebar (width>700px){a{color:red}}

cssnano ✗

@container sidebar (width > 700px){a{color:red}}

csso ✗

@container sidebar (width > 700px){a{color:red}}

esbuild ✗

@container sidebar (width > 700px){a{color:red}}

lightningcss ✓

@container sidebar (width>700px){a{color:red}}

sass ✗

@container sidebar (width > 700px){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✗
Details

Empty @container removal

An @container rule with no child rules has no effect and can be removed.

@container (min-width: 700px) {
}

Expected

Outputs

clean-css ✓

csskit ✓

csslop ✓

cssnano ✓

csso ✓

esbuild ✓

lightningcss ✓

sass ✗

@container (min-width: 700px){}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✓ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

Container style query whitespace

style() container queries must be preserved. Whitespace around : inside the condition can be removed but the style() function itself must not be stripped as unknown.

@container style(--theme: dark) {
  a {
    color: red;
  }
}

Expected

@container style(--theme:dark){a{color:red}}

Outputs

clean-css ✓

@container style(--theme:dark){a{color:red}}

csskit ✓

@container style(--theme:dark){a{color:red}}

csslop ✓

@container style(--theme:dark){a{color:red}}

cssnano ✗

@container style(--theme: dark){a{color:red}}

csso ✗

@container style(--theme: dark){a{color:red}}

esbuild ✗

@container style(--theme: dark){a{color:red}}

lightningcss ✓

@container style(--theme:dark){a{color:red}}

sass ✗

@container style(--theme: dark){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Convert min-width to range syntax in @container

@container (min-width: 700px) can be shortened to @container(width>=700px) using range syntax. Container queries support the same range forms as media queries. In addition the white space can be elided as an at-keyword cannot contain (.

@container (min-width: 700px) {
  a {
    color: red;
  }
}

Expected

@container(width>=700px){a{color:red}}

Outputs

clean-css ✗

@container (min-width:700px){a{color:red}}

csskit ✗

@container(min-width:700px){a{color:red}}

csslop ✓

@container(width>=700px){a{color:red}}

cssnano ✗

@container (min-width: 700px){a{color:red}}

csso ✗

@container (min-width: 700px){a{color:red}}

esbuild ✗

@container (min-width: 700px){a{color:red}}

lightningcss ✗

@container (width>=700px){a{color:red}}

sass ✗

@container (min-width: 700px){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Convert max-width to range syntax in @container

@container (max-width: 500px) can be shortened to @container(width<=500px) using range syntax. In addition the white space can be elided as an at-keyword cannot contain (.

@container (max-width: 500px) {
  a {
    color: red;
  }
}

Expected

@container(width<=500px){a{color:red}}

Outputs

clean-css ✗

@container (max-width:500px){a{color:red}}

csskit ✗

@container(max-width:500px){a{color:red}}

csslop ✓

@container(width<=500px){a{color:red}}

cssnano ✗

@container (max-width: 500px){a{color:red}}

csso ✗

@container (max-width: 500px){a{color:red}}

esbuild ✗

@container (max-width: 500px){a{color:red}}

lightningcss ✗

@container (width<=500px){a{color:red}}

sass ✗

@container (max-width: 500px){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✗ ✗ ✓ ✗ ✗ ✗ ✓ ✗
Details

Named container with min-width to range syntax

@container sidebar (min-width: 700px) can use range syntax for the condition while preserving the container name: @container sidebar (width>=700px).

@container sidebar (min-width: 700px) {
  a {
    color: red;
  }
}

Expected

@container sidebar (width>=700px){a{color:red}}

Outputs

clean-css ✗

@container sidebar (min-width:700px){a{color:red}}

csskit ✗

@container sidebar (min-width:700px){a{color:red}}

csslop ✓

@container sidebar (width>=700px){a{color:red}}

cssnano ✗

@container sidebar (min-width: 700px){a{color:red}}

csso ✗

@container sidebar (min-width: 700px){a{color:red}}

esbuild ✗

@container sidebar (min-width: 700px){a{color:red}}

lightningcss ✓

@container sidebar (width>=700px){a{color:red}}

sass ✗

@container sidebar (min-width: 700px){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0007 ✗ ✗ ✓ ✗ ✗ ✗ ✓ ✗
Details

Merge identical @container separated by an empty @media

Remove the empty @media, then merge the remaining containers.

@container sidebar (width > 700px) {
  a {
    color: red;
  }
}
@media screen {
}
@container sidebar (width > 700px) {
  b {
    color: tan;
  }
}

Expected

@container sidebar (width>700px){a{color:red}b{color:tan}}

Outputs

clean-css ✗

@container sidebar (width > 700px){a{color:red}b{color:tan}}

csskit ✗

@container sidebar (width>700px){a{color:red}}@container sidebar (width>700px){b{color:tan}}

csslop ✓

@container sidebar (width>700px){a{color:red}b{color:tan}}

cssnano ✗

@container sidebar (width > 700px){a{color:red}b{color:tan}}

csso ✗

@container sidebar (width > 700px){a{color:red}}@container sidebar (width > 700px){b{color:tan}}

esbuild ✗

@container sidebar (width > 700px){a{color:red}}@container sidebar (width > 700px){b{color:tan}}

lightningcss ✓

@container sidebar (width>700px){a{color:red}b{color:tan}}

sass ✗

@container sidebar (width > 700px){a{color:red}}@container sidebar (width > 700px){b{color:tan}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 2 / 7 3 / 7 7 / 7 1 / 7 1 / 7 1 / 7 5 / 7 0 / 7
Percent 28.57% 42.85% 100% 14.28% 14.28% 14.28% 71.42% 0%
Duration 1ms 1ms 1ms 5ms 1ms 4ms 1ms 4ms

counter-style #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✗ ✓ ✓ ✗ ✓ ✗ ✓ ✓
Details

@counter-style whitespace removal

Basic whitespace minification inside a @counter-style rule. The space between the at-keyword and the name must be preserved (unlike @page), but all other internal whitespace is removable. The default encoding is UTF-8, therefore the \1F44D codepoint can be replaced with 👍.

@counter-style thumbs {
  system: cyclic;
  symbols: "\1F44D";
  suffix: " ";
}

Expected

@counter-style thumbs{system:cyclic;symbols:"👍";suffix:" "}

Outputs

clean-css ✗

@counter-style thumbs{system:cyclic;symbols:"\1F44D";suffix:" "}

csskit ✓

@counter-style thumbs{system:cyclic;symbols:"👍";suffix:" "}

csslop ✓

@counter-style thumbs{system:cyclic;symbols:"👍";suffix:" "}

cssnano ✗

@counter-style thumbs{system:cyclic;symbols:"\1F44D";suffix:" "}

csso ✓

@counter-style thumbs{system:cyclic;symbols:"👍";suffix:" "}

esbuild ✗

@counter-style thumbs{system:cyclic;symbols:"\1f44d";suffix:" "}

lightningcss ✓

@counter-style thumbs{system:cyclic;symbols:"👍";suffix:" "}

sass ✓

@counter-style thumbs{system:cyclic;symbols:"👍";suffix:" "}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✓ ✓ ✓ ✓ ✓ ✗ ✗ ✗
Details

Empty @counter-style removal

An empty @counter-style with no descriptors can be removed entirely.

@counter-style empty {
}

Expected

Outputs

clean-css ✓

csskit ✓

csslop ✓

cssnano ✓

csso ✓

esbuild ✗

@counter-style empty{}

lightningcss ✗

@counter-style empty{}

sass ✗

@counter-style empty{}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✗ ✓ ✓ ✗ ✓ ✗ ✗ ✗
Details

Quoted symbols must preserve quotes

symbols: "(" ")" must keep quotes. Parentheses are not valid unquoted ident tokens and stripping quotes would produce a parse error.

The whitespace between quotes can be removed for a very slight improvement in compression.

@counter-style paren {
  system: fixed;
  symbols: "(" ")";
}

Expected

@counter-style paren{system:fixed;symbols:"("")"}

Outputs

clean-css ✗

@counter-style paren{system:fixed;symbols:"(" ")"}

csskit ✓

@counter-style paren{system:fixed;symbols:"("")"}

csslop ✓

@counter-style paren{system:fixed;symbols:"("")"}

cssnano ✗

@counter-style paren{system:fixed;symbols:"(" ")"}

csso ✓

@counter-style paren{system:fixed;symbols:"("")"}

esbuild ✗

@counter-style paren{system:fixed;symbols:"(" ")"}

lightningcss ✗

@counter-style paren{system:fixed;symbols:"(" ")"}

sass ✗

@counter-style paren{system:fixed;symbols:"(" ")"}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 1 / 3 3 / 3 3 / 3 1 / 3 3 / 3 0 / 3 1 / 3 1 / 3
Percent 33.33% 100% 100% 33.33% 100% 0% 33.33% 33.33%
Duration 1ms 1ms 1ms 2ms 1ms 2ms 1ms 1ms

duplicates #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✓ ✗ ✓ ✗ ✓ ✗ ✓ ✗
Details

Duplicate declaration removal

When a property is declared twice in the same rule, the last value wins. The earlier duplicate should be removed.

a {
  color: red;
  color: tan;
}

Expected

a{color:tan}

Outputs

clean-css ✓

a{color:tan}

csskit ✗

a{color:red;color:tan}

csslop ✓

a{color:tan}

cssnano ✗

a{color:red;color:tan}

csso ✓

a{color:tan}

esbuild ✗

a{color:red;color:tan}

lightningcss ✓

a{color:tan}

sass ✗

a{color:red;color:tan}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✓ ✗ ✓ ✗ ✓ ✗ ✓ ✗
Details

Duplicate rule removal

When two adjacent rules share the same selector and the later one completely overrides the earlier, the earlier rule can be removed.

a {
  color: red;
}
a {
  color: tan;
}

Expected

a{color:tan}

Outputs

clean-css ✓

a{color:tan}

csskit ✗

a{color:red}a{color:tan}

csslop ✓

a{color:tan}

cssnano ✗

a{color:red;color:tan}

csso ✓

a{color:tan}

esbuild ✗

a{color:red}a{color:tan}

lightningcss ✓

a{color:tan}

sass ✗

a{color:red}a{color:tan}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✓ ✗ ✓ ✗ ✓ ✗ ✓ ✗
Details

Duplicate rule removal with intervening rule

When a later rule completely overrides an earlier rule with the same selector, the earlier rule should be removed even with other rules between them.

a {
  color: red;
  font-size: 16px;
}
b {
  margin: 0;
}
a {
  color: tan;
  font-size: 16px;
}

Expected

b{margin:0}a{color:tan;font-size:16px}

Also accepted

a{color:tan;font-size:16px}b{margin:0}
b{margin:0}a{font-size:16px;color:tan}
a{font-size:16px;color:tan}b{margin:0}

Outputs

clean-css ✓

b{margin:0}a{color:tan;font-size:16px}

csskit ✗

a{color:red;font-size:16px}b{margin:0}a{color:tan;font-size:16px}

csslop ✓

b{margin:0}a{color:tan;font-size:16px}

cssnano ✗

a{color:red;color:tan;font-size:16px}b{margin:0}

csso ✓

a{color:tan;font-size:16px}b{margin:0}

esbuild ✗

a{color:red;font-size:16px}b{margin:0}a{color:tan;font-size:16px}

lightningcss ✓

b{margin:0}a{color:tan;font-size:16px}

sass ✗

a{color:red;font-size:16px}b{margin:0}a{color:tan;font-size:16px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✓ ✗ ✓ ✓ ✓ ✓ ✗ ✗
Details

Duplicate selector removal within a rule

Duplicate selectors in a selector list should be deduplicated.

h1, h2, h3, h4, h5, h5 {
  color: red;
}

Expected

h1,h2,h3,h4,h5{color:red}

Outputs

clean-css ✓

h1,h2,h3,h4,h5{color:red}

csskit ✗

h1,h2,h3,h4,h5,h5{color:red}

csslop ✓

h1,h2,h3,h4,h5{color:red}

cssnano ✓

h1,h2,h3,h4,h5{color:red}

csso ✓

h1,h2,h3,h4,h5{color:red}

esbuild ✓

h1,h2,h3,h4,h5{color:red}

lightningcss ✗

h1,h2,h3,h4,h5,h5{color:red}

sass ✗

h1,h2,h3,h4,h5,h5{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Duplicate properties with env() fallback must be preserved

The plain 1rem fallback and env() declaration are progressive enhancement. Removing the "duplicate" breaks browsers that don't support env().

a {
  padding-top: 1rem;
  padding-top: calc(1rem + env(safe-area-inset-top));
}

Expected

a{padding-top:1rem;padding-top:calc(1rem + env(safe-area-inset-top))}

Outputs

clean-css ✓

a{padding-top:1rem;padding-top:calc(1rem + env(safe-area-inset-top))}

csskit ✓

a{padding-top:1rem;padding-top:calc(1rem + env(safe-area-inset-top))}

csslop ✓

a{padding-top:1rem;padding-top:calc(1rem + env(safe-area-inset-top))}

cssnano ✓

a{padding-top:1rem;padding-top:calc(1rem + env(safe-area-inset-top))}

csso ✓

a{padding-top:1rem;padding-top:calc(1rem + env(safe-area-inset-top))}

esbuild ✓

a{padding-top:1rem;padding-top:calc(1rem + env(safe-area-inset-top))}

lightningcss ✓

a{padding-top:1rem;padding-top:calc(1rem + env(safe-area-inset-top))}

sass ✓

a{padding-top:1rem;padding-top:calc(1rem + env(safe-area-inset-top))}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✓ ✗ ✓ ✗ ✓ ✗ ✗ ✗
Details

Duplicate declaration removal with !important

When a property is declared with !important and then redeclared without it, the non-important declaration loses and should be removed. The !important declaration always wins regardless of order.

a {
  color: red !important;
  color: blue;
}

Expected

a{color:red!important}

Validate

Outputs

clean-css ✓

a{color:red!important}

csskit ✗

a{color:red!important;color:blue}

csslop ✓

a{color:red!important}

cssnano ✗

a{color:red!important;color:blue}

csso ✓

a{color:red!important}

esbuild ✗

a{color:red!important;color:#00f}

lightningcss ✗

a{color:#00f;color:red!important}

sass ✗

a{color:red !important;color:blue}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0007 ✓ ✗ ✓ ✓ ✓ ✓ ✓ ✗
Details

Entirely identical rule removal

When two rules have the same selector and identical declarations, the duplicate rule is fully redundant and should be removed.

a {
  color: red;
  font-size: 16px;
}
a {
  color: red;
  font-size: 16px;
}

Expected

a{color:red;font-size:16px}

Also accepted

a{font-size:16px;color:red}

Outputs

clean-css ✓

a{color:red;font-size:16px}

csskit ✗

a{color:red;font-size:16px}a{color:red;font-size:16px}

csslop ✓

a{color:red;font-size:16px}

cssnano ✓

a{color:red;font-size:16px}

csso ✓

a{color:red;font-size:16px}

esbuild ✓

a{color:red;font-size:16px}

lightningcss ✓

a{color:red;font-size:16px}

sass ✗

a{color:red;font-size:16px}a{color:red;font-size:16px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0008 ✗ ✗ ✓ ✗ ✓ ✗ ✗ ✗
Details

Remove duplicate scrollbar-gutter

If multiple scrollbar-gutters are applied in the same rule, the last one will be used and the earlier declarations will be ignored.

p {
  scrollbar-gutter: auto;
  scrollbar-gutter: stable;
  scrollbar-gutter: stable both-edges;
}

Expected

p{scrollbar-gutter:stable both-edges}

Outputs

clean-css ✗

p{scrollbar-gutter:auto;scrollbar-gutter:stable;scrollbar-gutter:stable both-edges}

csskit ✗

p{scrollbar-gutter:auto;scrollbar-gutter:stable;scrollbar-gutter:stable both-edges}

csslop ✓

p{scrollbar-gutter:stable both-edges}

cssnano ✗

p{scrollbar-gutter:auto;scrollbar-gutter:stable;scrollbar-gutter:stable both-edges}

csso ✓

p{scrollbar-gutter:stable both-edges}

esbuild ✗

p{scrollbar-gutter:auto;scrollbar-gutter:stable;scrollbar-gutter:stable both-edges}

lightningcss ✗

p{scrollbar-gutter:auto;scrollbar-gutter:stable;scrollbar-gutter:stable both-edges}

sass ✗

p{scrollbar-gutter:auto;scrollbar-gutter:stable;scrollbar-gutter:stable both-edges}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0009 ✓ ✗ ✓ ✓ ✓ ✓ ✗ ✗
Details

Duplicate complex selectors in a selector list

Duplicate compound/complex selectors within a selector list should be deduplicated, including selectors beyond simple type selectors.

.nav .item,
.footer,
.nav .item {
  color: red;
}

Expected

.nav .item,.footer{color:red}

Also accepted

.footer,.nav .item{color:red}

Outputs

clean-css ✓

.footer,.nav .item{color:red}

csskit ✗

.nav .item,.footer,.nav .item{color:red}

csslop ✓

.nav .item,.footer{color:red}

cssnano ✓

.footer,.nav .item{color:red}

csso ✓

.footer,.nav .item{color:red}

esbuild ✓

.nav .item,.footer{color:red}

lightningcss ✗

.nav .item,.footer,.nav .item{color:red}

sass ✗

.nav .item,.footer,.nav .item{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0010 ✓ ✗ ✓ ✓ ✓ ✓ ✗ ✗
Details

Duplicate rules with reordered selectors

Two rules with the same selectors in different order and identical declarations are equivalent. Remove the duplicate by normalizing selector order.

h1, h2 {
  color: red;
}
h2, h1 {
  color: red;
}

Expected

h1,h2{color:red}

Also accepted

h2,h1{color:red}

Outputs

clean-css ✓

h1,h2{color:red}

csskit ✗

h1,h2{color:red}h2,h1{color:red}

csslop ✓

h1,h2{color:red}

cssnano ✓

h1,h2{color:red}

csso ✓

h1,h2{color:red}

esbuild ✓

h1,h2{color:red}

lightningcss ✗

h1,h2,h2,h1{color:red}

sass ✗

h1,h2{color:red}h2,h1{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0011 ✓ ✗ ✓ ✗ ✓ ✗ ✗ ✗
Details

Flat and nested equivalent rules should dedup

.foo .bar{...} and .foo { .bar{...} } resolve to the same selector. When the declarations are identical, the duplicate should be removed.

.foo .bar {
  color: red;
}
.foo {
  .bar {
    color: red;
  }
}

Expected

.foo .bar{color:red}

Outputs

clean-css ✓

.foo .bar{color:red}

csskit ✗

.foo .bar{color:red}.foo{.bar{color:red}}

csslop ✓

.foo .bar{color:red}

cssnano ✗

.foo .bar{color:red}.foo{.bar{color:red}}

csso ✓

.foo .bar{color:red}

esbuild ✗

.foo .bar{color:red}.foo{.bar{color:red}}

lightningcss ✗

.foo .bar{color:red}.foo{& .bar{color:red}}

sass ✗

.foo .bar{color:red}.foo .bar{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0012 ✓ ✗ ✓ ✓ ✓ ✗ ✓ ✗
Details

Partial duplicate rule absorbed by superset

When a later rule for the same selector contains all declarations of an earlier rule plus additional ones, the earlier rule is redundant and can be removed.

a {
  color: red;
}
a {
  color: red;
  font-size: 1rem;
}

Expected

a{color:red;font-size:1rem}

Also accepted

a{font-size:1rem;color:red}

Outputs

clean-css ✓

a{color:red;font-size:1rem}

csskit ✗

a{color:red}a{color:red;font-size:1rem}

csslop ✓

a{color:red;font-size:1rem}

cssnano ✓

a{color:red;font-size:1rem}

csso ✓

a{color:red;font-size:1rem}

esbuild ✗

a{color:red}a{color:red;font-size:1rem}

lightningcss ✓

a{color:red;font-size:1rem}

sass ✗

a{color:red}a{color:red;font-size:1rem}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0013 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

!important wins on custom properties

When a custom property has both a normal and !important declaration, the !important one wins regardless of order. The normal declaration is dead code. Note the space before !important is part of the syntax, not the value.

a {
  --color: blue;
  --color: red !important;
}

Expected

a{--color:red !important}

Outputs

clean-css ✗

a{--color:blue;--color:red!important}

csskit ✗

a{--color:blue;--color:red !important}

csslop ✓

a{--color:red !important}

cssnano ✗

a{--color:blue;--color:red !important}

csso ✗

a{--color:blue;--color:red!important}

esbuild ✗

a{--color: blue;--color: red !important}

lightningcss ✗

a{--color:blue;--color:red!important}

sass ✗

a{--color: blue;--color: red !important}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0014 ✓ ✗ ✓ ✓ ✓ ✗ ✓ ✗
Details

Duplicate shorthand property override

border-top: 1px solid blue followed by border-top: 2px solid red is a duplicate declaration. The last one wins and the first can be removed.

a {
  border-top: 1px solid blue;
  border-top: 2px solid red;
}

Expected

a{border-top:2px solid red}

Outputs

clean-css ✓

a{border-top:2px solid red}

csskit ✗

a{border-top:1px solid blue;border-top:2px solid red}

csslop ✓

a{border-top:2px solid red}

cssnano ✓

a{border-top:2px solid red}

csso ✓

a{border-top:2px solid red}

esbuild ✗

a{border-top:1px solid blue;border-top:2px solid red}

lightningcss ✓

a{border-top:2px solid red}

sass ✗

a{border-top:1px solid blue;border-top:2px solid red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0015 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

UNSAFE: border-top before border-block must not be removed

border-top is physical and border-block is logical. In horizontal-tb writing mode border-block maps to top/bottom, but in vertical writing modes it maps to left/right. Removing border-top would change rendering in some writing modes.

a {
  border-top: 1px solid red;
  border-block: 2px solid red;
}

Expected

a{border-top:1px solid red;border-block:2px solid red}

Also accepted

a{border-block:2px solid red;border-top:1px solid red}

Outputs

clean-css ✓

a{border-top:1px solid red;border-block:2px solid red}

csskit ✓

a{border-top:1px solid red;border-block:2px solid red}

csslop ✓

a{border-top:1px solid red;border-block:2px solid red}

cssnano ✓

a{border-top:1px solid red;border-block:2px solid red}

csso ✓

a{border-top:1px solid red;border-block:2px solid red}

esbuild ✓

a{border-top:1px solid red;border-block:2px solid red}

lightningcss ✓

a{border-top:1px solid red;border-block:2px solid red}

sass ✓

a{border-top:1px solid red;border-block:2px solid red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0016 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

UNSAFE: margin-left before margin-inline-start must not be removed

margin-left is physical and margin-inline-start is logical. In LTR margin-inline-start maps to margin-left, but in RTL it maps to margin-right. Both declarations interact via cascade order and writing mode, so removing either changes rendering in some configurations.

a {
  margin-left: 10px;
  margin-inline-start: 20px;
}

Expected

a{margin-left:10px;margin-inline-start:20px}

Also accepted

a{margin-inline-start:20px;margin-left:10px}

Outputs

clean-css ✓

a{margin-left:10px;margin-inline-start:20px}

csskit ✓

a{margin-left:10px;margin-inline-start:20px}

csslop ✓

a{margin-left:10px;margin-inline-start:20px}

cssnano ✓

a{margin-left:10px;margin-inline-start:20px}

csso ✓

a{margin-left:10px;margin-inline-start:20px}

esbuild ✓

a{margin-left:10px;margin-inline-start:20px}

lightningcss ✓

a{margin-left:10px;margin-inline-start:20px}

sass ✓

a{margin-left:10px;margin-inline-start:20px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0017 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

UNSAFE: padding-top before padding-block-start must not be removed

padding-top is physical and padding-block-start is logical. In horizontal-tb they resolve to the same edge, but in vertical writing modes padding-block-start maps to padding-left or padding-right. Removing either declaration changes rendering in some writing modes.

a {
  padding-top: 10px;
  padding-block-start: 20px;
}

Expected

a{padding-top:10px;padding-block-start:20px}

Also accepted

a{padding-block-start:20px;padding-top:10px}

Outputs

clean-css ✓

a{padding-top:10px;padding-block-start:20px}

csskit ✓

a{padding-top:10px;padding-block-start:20px}

csslop ✓

a{padding-top:10px;padding-block-start:20px}

cssnano ✓

a{padding-top:10px;padding-block-start:20px}

csso ✓

a{padding-top:10px;padding-block-start:20px}

esbuild ✓

a{padding-top:10px;padding-block-start:20px}

lightningcss ✓

a{padding-top:10px;padding-block-start:20px}

sass ✓

a{padding-top:10px;padding-block-start:20px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0018 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

UNSAFE: inset-block-start before top must not be removed

inset-block-start is logical and top is physical. In horizontal-tb they resolve to the same edge, but in vertical writing modes inset-block-start maps to left or right. Removing either changes rendering in some writing modes.

a {
  inset-block-start: 10px;
  top: 20px;
}

Expected

a{inset-block-start:10px;top:20px}

Also accepted

a{top:20px;inset-block-start:10px}

Outputs

clean-css ✓

a{inset-block-start:10px;top:20px}

csskit ✓

a{inset-block-start:10px;top:20px}

csslop ✓

a{inset-block-start:10px;top:20px}

cssnano ✓

a{inset-block-start:10px;top:20px}

csso ✓

a{inset-block-start:10px;top:20px}

esbuild ✓

a{inset-block-start:10px;top:20px}

lightningcss ✓

a{inset-block-start:10px;top:20px}

sass ✓

a{inset-block-start:10px;top:20px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0019 ✗ ✗ ✓ ✓ ✓ ✓ ✓ ✗
Details

Duplicate custom property removal

When a property is declared twice containing custom property values in the same rule, the last value wins. The earlier duplicate should be removed.

a {
  color: var(--x);
  color: var(--x);
}

Expected

a{color:var(--x)}

Outputs

clean-css ✗

a{color:var(--x);color:var(--x)}

csskit ✗

a{color:var(--x);color:var(--x)}

csslop ✓

a{color:var(--x)}

cssnano ✓

a{color:var(--x)}

csso ✓

a{color:var(--x)}

esbuild ✓

a{color:var(--x)}

lightningcss ✓

a{color:var(--x)}

sass ✗

a{color:var(--x);color:var(--x)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0020 ✓ ✗ ✓ ✗ ✓ ✗ ✗ ✗
Details

Remove overridden properties in rules with multiple selectors

If the properties of all selectors in a rule get overridden later in the stylesheet, then that property can be removed from the earlier rule. If no properties are left in the rule (it is empty), the entire rule may be discarded.

h1, h2 {
  color: #001;
}
h1 {
  color: #002;
}
h2 {
  color: #003;
}

h3, h4 {
  margin: 1rem;
  padding: 1px;
}
h3 {
  padding: 2px;
}
h4 {
  padding: 3px;
}

Expected

h1{color:#002}h2{color:#003}h3,h4{margin:1rem}h3{padding:2px}h4{padding:3px}

Outputs

clean-css ✓

h1{color:#002}h2{color:#003}h3,h4{margin:1rem}h3{padding:2px}h4{padding:3px}

csskit ✗

h1,h2{color:#001}h1{color:#002}h2{color:#003}h3,h4{margin:1rem;padding:1px}h3{padding:2px}h4{padding:3px}

csslop ✓

h1{color:#002}h2{color:#003}h3,h4{margin:1rem}h3{padding:2px}h4{padding:3px}

cssnano ✗

h1,h2{color:#001}h1{color:#002}h2{color:#003}h3,h4{margin:1rem;padding:1px}h3{padding:2px}h4{padding:3px}

csso ✓

h1{color:#002}h2{color:#003}h3,h4{margin:1rem}h3{padding:2px}h4{padding:3px}

esbuild ✗

h1,h2{color:#001}h1{color:#002}h2{color:#003}h3,h4{margin:1rem;padding:1px}h3{padding:2px}h4{padding:3px}

lightningcss ✗

h1,h2{color:#001}h1{color:#002}h2{color:#003}h3,h4{margin:1rem;padding:1px}h3{padding:2px}h4{padding:3px}

sass ✗

h1,h2{color:#001}h1{color:#002}h2{color:#003}h3,h4{margin:1rem;padding:1px}h3{padding:2px}h4{padding:3px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0021 ✗ ✗ ✓ ✓ ✗ ✓ ✗ ✗
Details

Convert double-colon before/after to single and de-dupe in same selector

The ::before and ::after pseudo-elements can safely be converted to :before or :after. After this conversion, the minifier should check for duplicate selectors and properties that can be removed.

h1::before,
h1:before {
  content: "j";
}

Expected

h1:before{content:"j"}

Outputs

clean-css ✗

h1::before,h1:before{content:"j"}

csskit ✗

h1::before,h1:before{content:"j"}

csslop ✓

h1:before{content:"j"}

cssnano ✓

h1:before{content:"j"}

csso ✗

h1::before,h1:before{content:"j"}

esbuild ✓

h1:before{content:"j"}

lightningcss ✗

h1:before,h1:before{content:"j"}

sass ✗

h1::before,h1:before{content:"j"}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0022 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Convert double-colon before/after to single and de-dupe separate selector

The ::before and ::after pseudo-elements can safely be converted to :before or :after. After this conversion, the minifier should check for duplicate selectors and properties that can be removed.

h2:before {
  content: "i";
}
h2::before {
  content: "j";
}

Expected

h2:before{content:"j"}

Outputs

clean-css ✗

h2:before{content:"i"}h2::before{content:"j"}

csskit ✗

h2:before{content:"i"}h2::before{content:"j"}

csslop ✓

h2:before{content:"j"}

cssnano ✗

h2:before{content:"i";content:"j"}

csso ✗

h2:before{content:"i"}h2::before{content:"j"}

esbuild ✗

h2:before{content:"i"}h2:before{content:"j"}

lightningcss ✗

h2:before{content:"i";content:"j"}

sass ✗

h2:before{content:"i"}h2::before{content:"j"}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0023 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Do not abstract Data-URIs to custom-properties

Data-URIs can be quite long. When the same one is used multiple times, it could be stored in a custom-property and referenced. However, when GZipped, the custom-property and references actually result in a larger size compared to just letting the duplicate Data-URi's exist and be GZipped away.

body {
  image-rendering: pixelated;
  background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==);
  mask-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==);
}

Expected

body{image-rendering:pixelated;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==);mask-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==)}

Also accepted

body{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==);image-rendering:pixelated;mask-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==)}

Outputs

clean-css ✓

body{image-rendering:pixelated;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==);mask-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==)}

csskit ✓

body{image-rendering:pixelated;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==);mask-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==)}

csslop ✓

body{image-rendering:pixelated;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==);mask-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==)}

cssnano ✓

body{image-rendering:pixelated;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==);mask-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==)}

csso ✓

body{image-rendering:pixelated;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==);mask-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==)}

esbuild ✓

body{image-rendering:pixelated;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==);mask-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==)}

lightningcss ✓

body{image-rendering:pixelated;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==);mask-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==)}

sass ✓

body{image-rendering:pixelated;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==);mask-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAGCAIAAACepSOSAAAAIklEQVR42mP4DwZpxjMxGQwQCojQGAg5AvowteK1D4hxIQApumnK5mwMyQAAAABJRU5ErkJggg==)}
1ms
3ms
1ms
2ms
1ms
1ms
1ms
1ms
0024 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Remove duplicate property in rule when one uses custom-properties

Browsers ignore earlier declared property/value pair declarations when the same property is used in the same rule, unless the later version contains a value it does not recognize. Then it falls back to the most recent previous version of that property with a value it can use. All browsers support custom-properties so in this test, none of them will fall back to the primitive value version. Even if the custom property was never defined the browser will still prefer it over the fallback. This means these fallbacks will never be used and are redundant.

a {
  border: 1px solid tan;
  border: 1px solid var(--x);
  color: var(--a);
  color: red;
  color: var(--y);
  margin: var(--z);
  margin: 10px;
  margin: var(--z);
}

Expected

a{border:1px solid var(--x);color:var(--y);margin:var(--z)}

Also accepted

a{border:1px solid var(--x);margin:var(--z);color:var(--y)}
a{color:var(--y);border:1px solid var(--x);margin:var(--z)}
a{color:var(--y);margin:var(--z);border:1px solid var(--x)}
a{margin:var(--z);color:var(--y);border:1px solid var(--x)}
a{margin:var(--z);border:1px solid var(--x);color:var(--y)}

Outputs

clean-css ✗

a{border:1px solid tan;border:1px solid var(--x);color:var(--a);color:red;color:var(--y);margin:var(--z);margin:10px;margin:var(--z)}

csskit ✗

a{border:1px solid tan;border:1px solid var(--x);color:var(--a);color:red;color:var(--y);margin:var(--z);margin:10px;margin:var(--z)}

csslop ✓

a{border:1px solid var(--x);color:var(--y);margin:var(--z)}

cssnano ✗

a{border:1px solid tan;border:1px solid var(--x);color:var(--a);color:red;color:var(--y);margin:10px;margin:var(--z)}

csso ✗

a{border:1px solid tan;border:1px solid var(--x);color:red;color:var(--y);margin:10px;margin:var(--z)}

esbuild ✗

a{border:1px solid tan;border:1px solid var(--x);color:var(--a);color:red;color:var(--y);margin:10px;margin:var(--z)}

lightningcss ✗

a{border:1px solid tan;border:1px solid var(--x);color:var(--y);margin:var(--z);margin:10px;margin:var(--z)}

sass ✗

a{border:1px solid tan;border:1px solid var(--x);color:var(--a);color:red;color:var(--y);margin:var(--z);margin:10px;margin:var(--z)}
1ms
1ms
1ms
2ms
1ms
1ms
1ms
1ms
0025 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Dedupe after flattening unnecessary nesting

In this example, there is a nested rule with only & as the selector, making properties held within apply to the parent selector. This means those properties can be unnested. In this case that results with the same property applied twice, the later property overrides the previous as part of the cascade, making the previous safe to remove (unless the value assigned to the later version has weak browser support).

Relates to nesting/0040.

a {
  margin: 1px;
  & {
    margin: 2px;
  }
}

Expected

a{margin:2px}

Outputs

clean-css ✗

a{margin:1px}

csskit ✗

a{margin:1px;&{margin:2px}}

csslop ✓

a{margin:2px}

cssnano ✗

a{margin:1px;&{margin:2px}}

csso ✗

a{margin:1px}

esbuild ✗

a{margin:1px;margin:2px}

lightningcss ✗

a{margin:1px;&{margin:2px}}

sass ✗

a{margin:1px}a{margin:2px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0026 ✓ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Remove earlier duplicate property that uses env()

In this example the padding-top property is declared 3 times in the same rule. The final declaration is just a simple pixel value that would be understood by any browser. Meaning there are no instances where a browser would fall back to earlier declarations (making them safe to remove). This test also ensures that usage of env does not recieve special treatment in this scenario, it should also be removed.

a {
  padding-top: 10px;
  padding-top: env(safe-area-inset-top);
  padding-top: 20px;
}

Expected

a{padding-top:20px}

Outputs

clean-css ✓

a{padding-top:20px}

csskit ✗

a{padding-top:10px;padding-top:env(safe-area-inset-top);padding-top:20px}

csslop ✓

a{padding-top:20px}

cssnano ✓

a{padding-top:20px}

csso ✗

a{padding-top:env(safe-area-inset-top);padding-top:20px}

esbuild ✗

a{padding-top:10px;padding-top:env(safe-area-inset-top);padding-top:20px}

lightningcss ✗

a{padding-top:10px;padding-top:env(safe-area-inset-top);padding-top:20px}

sass ✗

a{padding-top:10px;padding-top:env(safe-area-inset-top);padding-top:20px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0027 ✓ ✗ ✓ ✗ ✗ ✗ ✓ ✗
Details

Remove earlier duplicate property that uses calc()

In this example the width property is declared 3 times in the same rule. The final declaration is just a simple pixel value that would be understood by any browser. Meaning there are no instances where a browser would fall back to earlier declarations (making them safe to remove). This test also ensures that usage of calc does not recieve special treatment in this scenario, it should also be removed.

a {
  width: 10px;
  width: calc(100% - 10px);
  width: 20px;
}

Expected

a{width:20px}

Outputs

clean-css ✓

a{width:20px}

csskit ✗

a{width:10px;width:calc(100% - 10px);width:20px}

csslop ✓

a{width:20px}

cssnano ✗

a{width:calc(100% - 10px);width:20px}

csso ✗

a{width:calc(100% - 10px);width:20px}

esbuild ✗

a{width:10px;width:calc(100% - 10px);width:20px}

lightningcss ✓

a{width:20px}

sass ✗

a{width:10px;width:calc(100% - 10px);width:20px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 20 / 27 6 / 27 27 / 27 15 / 27 20 / 27 12 / 27 14 / 27 6 / 27
Percent 74.07% 22.22% 100% 55.55% 74.07% 44.44% 51.85% 22.22%
Duration 3ms 5ms 6ms 26ms 3ms 12ms 1ms 15ms

empty-rules #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Empty rule removal

a {} contains no declarations and should be removed entirely. Empty rules waste bytes and have no effect on rendering.

a {}
b {
  color: red;
}

Expected

b{color:red}

Outputs

clean-css ✓

b{color:red}

csskit ✓

b{color:red}

csslop ✓

b{color:red}

cssnano ✓

b{color:red}

csso ✓

b{color:red}

esbuild ✓

b{color:red}

lightningcss ✓

b{color:red}

sass ✓

b{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Empty rule with comment

A rule containing only a comment has no declarations and should be removed. Comments are stripped during minification so the rule body becomes empty.

a {
  /* this rule is empty */
}
b {
  color: red;
}

Expected

b{color:red}

Outputs

clean-css ✓

b{color:red}

csskit ✓

b{color:red}

csslop ✓

b{color:red}

cssnano ✓

b{color:red}

csso ✓

b{color:red}

esbuild ✓

b{color:red}

lightningcss ✓

b{color:red}

sass ✓

b{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Empty @media rule

An @media block with no rules inside should be removed entirely. It has no effect on rendering.

@media screen {
}
b {
  color: red;
}

Expected

b{color:red}

Outputs

clean-css ✓

b{color:red}

csskit ✓

b{color:red}

csslop ✓

b{color:red}

cssnano ✓

b{color:red}

csso ✓

b{color:red}

esbuild ✓

b{color:red}

lightningcss ✓

b{color:red}

sass ✓

b{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Empty nested rule

An empty nested rule (& b {}) inside a parent should be removed while preserving the parent's own declarations.

a {
  color: red;
  & b {
  }
}

Expected

a{color:red}

Outputs

clean-css ✓

a{color:red}

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✓

a{color:red}

csso ✓

a{color:red}

esbuild ✓

a{color:red}

lightningcss ✓

a{color:red}

sass ✓

a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Remove parent selector when all nested selectors are empty

This verifies that stray empty selectors are not left behind after empty child selectors are removed. If minified correctly, the result will be 0 bytes.

nav {
  a {
  }
}

Expected

Outputs

clean-css ✓

csskit ✓

csslop ✓

cssnano ✓

csso ✓

esbuild ✓

lightningcss ✓

sass ✓

1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Remove empty rules with advanced selectors

This verifies that less common selectors do not impact the removal of empty rules during minification. If minified correctly, the result will be 0 bytes.

kbd {}
ul li:nth-of-type(2n) {}
fieldset > legend {}
input[type="checkbox"] {}
input[type=radio] {}
legend, option {}
*, *:before, *:after {}
button.secondary {}
#unique {}
details[open] {}
:focus {}
a[href*=".pdf"]:after {}
:is(html, body):has(:modal) {}

Expected

Outputs

clean-css ✓

csskit ✓

csslop ✓

cssnano ✓

csso ✓

esbuild ✓

lightningcss ✓

sass ✓

1ms
1ms
1ms
3ms
1ms
1ms
1ms
1ms
0007 ✓ ✓ ✓ ✓ ✓ ✗ ✗ ✗
Details

Remove keyframes with only empty children

If all of the children of a keyframe definition are empty, the entire @keyframes can be removed.

@keyframes fade {
  0% {}
  50% {}
  100% {}
}

Expected

Outputs

clean-css ✓

csskit ✓

csslop ✓

cssnano ✓

csso ✓

esbuild ✗

@keyframes fade{}

lightningcss ✗

@keyframes fade{0%{}50%{}to{}}

sass ✗

@keyframes fade{}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 7 / 7 7 / 7 7 / 7 7 / 7 7 / 7 6 / 7 6 / 7 6 / 7
Percent 100% 100% 100% 100% 100% 85.71% 85.71% 85.71%
Duration 1ms 1ms 1ms 8ms 1ms 3ms 1ms 4ms

escaping #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Escape sequence resolution in identifiers

\66 oo is a CSS escape sequence for foo. Minifiers should resolve escape sequences in identifiers to their plain UTF-8 equivalents when safe.

\66 oo {
  color: red;
}

Expected

foo{color:red}

Validate

Outputs

clean-css ✗

\66 oo{color:red}

csskit ✓

foo{color:red}

csslop ✓

foo{color:red}

cssnano ✗

\66oo{color:red}

csso ✗

\66 oo{color:red}

esbuild ✓

foo{color:red}

lightningcss ✓

foo{color:red}

sass ✓

foo{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✗ ✓ ✓ ✗ ✓ ✓ ✓ ✓
Details

Escape sequence resolution in strings

'\66 oo' should resolve the escape to "foo". Tests both escape resolution within string values and normalization from single to double quotes.

a {
  content: '\66 oo';
}

Expected

a{content:"foo"}

Validate

Outputs

clean-css ✗

a{content:'\66 oo'}

csskit ✓

a{content:"foo"}

csslop ✓

a{content:"foo"}

cssnano ✗

a{content:"\66 oo"}

csso ✓

a{content:"foo"}

esbuild ✓

a{content:"foo"}

lightningcss ✓

a{content:"foo"}

sass ✓

a{content:"foo"}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Multiple consecutive hex escapes in class selector

.\66\6f\6f encodes each letter of foo as a separate hex escape. All three can be resolved to plain ASCII, producing .foo.

.\66\6f\6f {
  color: red;
}

Expected

.foo{color:red}

Validate

Outputs

clean-css ✗

.\66\6f\6f{color:red}

csskit ✓

.foo{color:red}

csslop ✓

.foo{color:red}

cssnano ✗

.\66\6f\6f{color:red}

csso ✗

.\66\6f\6f {color:red}

esbuild ✓

.foo{color:red}

lightningcss ✓

.foo{color:red}

sass ✓

.foo{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Hex escape for hyphen-minus in element name

my\2d component encodes a hyphen-minus, producing my-component. The hyphen is a valid mid-identifier so the escape can be resolved to a literal -.

See also: escaping/0015

custom\2d component {
  color: red;
}

Expected

custom-component{color:red}

Validate

Outputs

clean-css ✗

custom\2d component{color:red}

csskit ✓

custom-component{color:red}

csslop ✓

custom-component{color:red}

cssnano ✗

custom\2d component{color:red}

csso ✗

custom\2d component{color:red}

esbuild ✓

custom-component{color:red}

lightningcss ✓

custom-component{color:red}

sass ✓

custom-component{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Hex escape in attribute selector name

hr\65 f uses a hex escape for e inside the attribute name, producing href. The escape can be resolved to a plain ASCII character.

a[hr\65 f=x] {
  color: red;
}

Expected

a[href=x]{color:red}

Validate

Outputs

clean-css ✗

a[hr\65f=x]{color:red}

csskit ✓

a[href=x]{color:red}

csslop ✓

a[href=x]{color:red}

cssnano ✗

a[hr\65 f=x]{color:red}

csso ✗

a[hr\65 f=x]{color:red}

esbuild ✓

a[href=x]{color:red}

lightningcss ✓

a[href=x]{color:red}

sass ✓

a[href=x]{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Digit-start identifier must keep escape

.\31 23 is the class selector .123. The leading digit must remain escaped because bare 123 is not a valid CSS identifier start. A minifier that resolves this to .123 would produce an invalid selector.

.\31 23 {
  color: red;
}

Expected

.\31 23{color:red}

Validate

Outputs

clean-css ✓

.\31 23{color:red}

csskit ✓

.\31 23{color:red}

csslop ✓

.\31 23{color:red}

cssnano ✓

.\31 23{color:red}

csso ✓

.\31 23{color:red}

esbuild ✓

.\31 23{color:red}

lightningcss ✓

.\31 23{color:red}

sass ✓

.\31 23{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0007 ✓ ✓ ✓ ✓ ✓ ✓ ✗ ✓
Details

Newline escape in string must be preserved

"\a" is a CSS escape for a newline character (U+000A). It cannot be replaced with a literal newline inside the string, as that would terminate the string.

a {
  content: "\a";
}

Expected

a{content:"\a"}

Outputs

clean-css ✓

a{content:"\a"}

csskit ✓

a{content:"\a"}

csslop ✓

a{content:"\a"}

cssnano ✓

a{content:"\a"}

csso ✓

a{content:"\a"}

esbuild ✓

a{content:"\a"}

lightningcss ✗

a{content:"\a "}

sass ✓

a{content:"\a"}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0008 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Escape of special character in class name

.\@ escapes the @ sign to use it in a class name. The escape must be preserved because @ unescaped is not valid in an identifier.

.\@ {
  color: red;
}

Expected

.\@{color:red}

Outputs

clean-css ✓

.\@{color:red}

csskit ✓

.\@{color:red}

csslop ✓

.\@{color:red}

cssnano ✓

.\@{color:red}

csso ✓

.\@{color:red}

esbuild ✓

.\@{color:red}

lightningcss ✓

.\@{color:red}

sass ✓

.\@{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0009 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Hex escape in ID selector

#\66 oo is the ID selector #foo with a hex escape for f. The escape can be resolved since foo is a valid identifier.

#\66 oo {
  color: red;
}

Expected

#foo{color:red}

Validate

Outputs

clean-css ✗

#\66 oo{color:red}

csskit ✓

#foo{color:red}

csslop ✓

#foo{color:red}

cssnano ✗

#\66oo{color:red}

csso ✗

#\66 oo{color:red}

esbuild ✓

#foo{color:red}

lightningcss ✓

#foo{color:red}

sass ✓

#foo{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0010 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Hex escape in compound selector class

a.\62 ar is a.bar with a hex escape for b. Escape resolution applies in compound selectors (element + class).

a.\62 ar {
  color: red;
}

Expected

a.bar{color:red}

Validate

Outputs

clean-css ✗

a.\62 ar{color:red}

csskit ✓

a.bar{color:red}

csslop ✓

a.bar{color:red}

cssnano ✗

a.\62 ar{color:red}

csso ✗

a.\62 ar{color:red}

esbuild ✓

a.bar{color:red}

lightningcss ✓

a.bar{color:red}

sass ✓

a.bar{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0011 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✗
Details

Hex escape in standard property name

\63 olor encodes the c in color as a hex escape. Minifiers should resolve escape sequences in property names to their plain equivalents.

a {
  \63 olor: red;
}

Expected

a{color:red}

Validate

Outputs

clean-css ✗

csskit ✓

a{color:red}

csslop ✓

a{color:red}

cssnano ✗

a{\63 olor:red}

csso ✗

a{\63 olor:red}

esbuild ✓

a{color:red}

lightningcss ✓

a{color:red}

sass ✗

a{\63 olor:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0012 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

Hex escape in custom property name

\66 encodes f as a hex escape in a custom property name, resolving --\66 oo to --foo. The same escape appears in var(--\66 oo) and must resolve consistently.

a {
  --\66 oo: red;
  color: var(--\66 oo);
}

Expected

a{--foo:red;color:var(--foo)}

Validate

Outputs

clean-css ✗

a{color:var(--\66 oo)}

csskit ✓

a{--foo:red;color:var(--foo)}

csslop ✓

a{--foo:red;color:var(--foo)}

cssnano ✗

a{--\66 oo:red;color:var(--\66 oo)}

csso ✗

a{--\66 oo:red;color:var(--\66 oo)}

esbuild ✗

a{--foo: red;color:var(--foo)}

lightningcss ✓

a{--foo:red;color:var(--foo)}

sass ✗

a{--\66 oo: red;color:var(--foo)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0013 ✗ ✗ ✓ ✗ ✗ ✗ ✓ ✗
Details

Escaping HREF attribute values

Attribute selectors can include values in optional quotes. Since HREF specifically deals with URL paths, they will naturally contain characters that need escaped if not wrapped in quotes (#, ., :, etc). A minifier should remove the quotes and favor escaping if the total characters in the escaped version is fewer than if it was kept in quotes. It should remove escapes and prefer quotes when that has fewer characters.

[href="#"],
[href="/"],
[href="file.html"],
[href=https\:\/\/example\.com] {
  color: red;
}

Expected

[href=\#],[href=\/],[href=file\.html],[href="https://example.com"]{color:red}

Validate

Outputs

clean-css ✗

[href="#"],[href="/"],[href="file.html"],[href=https\:\/\/example\.com]{color:red}

csskit ✗

[href="#"],[href="/"],[href="file.html"],[href=https\:\/\/example\.com]{color:red}

csslop ✓

[href=\#],[href=\/],[href=file\.html],[href="https://example.com"]{color:red}

cssnano ✗

[href="#"],[href="/"],[href="file.html"],[href=https\:\/\/example\.com]{color:red}

csso ✗

[href="#"],[href="/"],[href="file.html"],[href=https\:\/\/example\.com]{color:red}

esbuild ✗

[href="#"],[href="/"],[href="file.html"],[href="https://example.com"]{color:red}

lightningcss ✓

[href=\#],[href=\/],[href=file\.html],[href="https://example.com"]{color:red}

sass ✗

[href="#"],[href="/"],[href="file.html"],[href="https://example.com"]{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0014 ✗ ✗ ✓ ✗ ✗ ✗ ✓ ✗
Details

Escape semi-colons in attribute selectors

When an attribute selector includes a semi-colon it must either be surrounded in quotes or escaped. If the total number of escapes required is 3 or more, then prefer quotes to avoid additional characters.

p[style$="maroon;"] {
  background: red;
}
p[style="color:maroon;padding:1px;"] {
  background: tan;
}

Expected

p[style$=maroon\;]{background:red}p[style="color:maroon;padding:1px;"]{background:tan}

Outputs

clean-css ✗

p[style$="maroon;"]{background:red}p[style="color:maroon;padding:1px;"]{background:tan}

csskit ✗

p[style$="maroon;"]{background:red}p[style="color:maroon;padding:1px;"]{background:tan}

csslop ✓

p[style$=maroon\;]{background:red}p[style="color:maroon;padding:1px;"]{background:tan}

cssnano ✗

p[style$="maroon;"]{background:red}p[style="color:maroon;padding:1px;"]{background:tan}

csso ✗

p[style$="maroon;"]{background:red}p[style="color:maroon;padding:1px;"]{background:tan}

esbuild ✗

p[style$="maroon;"]{background:red}p[style="color:maroon;padding:1px;"]{background:tan}

lightningcss ✓

p[style$=maroon\;]{background:red}p[style="color:maroon;padding:1px;"]{background:tan}

sass ✗

p[style$="maroon;"]{background:red}p[style="color:maroon;padding:1px;"]{background:tan}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0015 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✓
Details

Hex escape for hyphen-minus in class name

.\2d foo encodes a hyphen-minus followed by foo, producing .-foo. The hyphen is valid mid-identifier so the escape can be resolved to a literal -.

See also: escaping/0004

.\2d foo {
  color: red;
}

Expected

.-foo{color:red}

Validate

Outputs

clean-css ✗

.\2d foo{color:red}

csskit ✓

.-foo{color:red}

csslop ✓

.-foo{color:red}

cssnano ✗

.\2d foo{color:red}

csso ✗

.\2d foo{color:red}

esbuild ✓

.-foo{color:red}

lightningcss ✓

.-foo{color:red}

sass ✓

.-foo{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 3 / 15 13 / 15 15 / 15 3 / 15 4 / 15 12 / 15 14 / 15 11 / 15
Percent 20% 86.66% 100% 20% 26.66% 80% 93.33% 73.33%
Duration 1ms 1ms 3ms 12ms 1ms 6ms 1ms 8ms

font-face #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

@font-face whitespace removal

@font-face blocks must be preserved with whitespace stripped. This tests basic whitespace removal without any string or URL optimizations.

@font-face {
  font-display: swap;
  font-weight: 400;
}

Expected

@font-face{font-display:swap;font-weight:400}

Outputs

clean-css ✓

@font-face{font-display:swap;font-weight:400}

csskit ✓

@font-face{font-display:swap;font-weight:400}

csslop ✓

@font-face{font-display:swap;font-weight:400}

cssnano ✓

@font-face{font-display:swap;font-weight:400}

csso ✓

@font-face{font-display:swap;font-weight:400}

esbuild ✓

@font-face{font-display:swap;font-weight:400}

lightningcss ✓

@font-face{font-display:swap;font-weight:400}

sass ✓

@font-face{font-display:swap;font-weight:400}
1ms
3ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✓ ✗ ✓ ✓ ✗ ✓ ✓ ✗
Details

font-family quote removal

font-family: "Custom" can be unquoted to font-family: Custom when the value is a valid CSS identifier. This does not apply to names that are CSS-wide values or contain special characters.

@font-face {
  font-family: "Custom";
  font-display: swap;
}

Expected

@font-face{font-family:Custom;font-display:swap}

Outputs

clean-css ✓

@font-face{font-family:Custom;font-display:swap}

csskit ✗

@font-face{font-family:"Custom";font-display:swap}

csslop ✓

@font-face{font-family:Custom;font-display:swap}

cssnano ✓

@font-face{font-family:Custom;font-display:swap}

csso ✗

@font-face{font-family:"Custom";font-display:swap}

esbuild ✓

@font-face{font-family:Custom;font-display:swap}

lightningcss ✓

@font-face{font-family:Custom;font-display:swap}

sass ✗

@font-face{font-family:"Custom";font-display:swap}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✗ ✗ ✓ ✓ ✓ ✓ ✓ ✗
Details

url() quote removal in @font-face src

Quotes inside url() can be removed when the URL contains no special characters (whitespace, parentheses, or single/double quotes). url("font.woff2") becomes url(font.woff2).

@font-face {
  font-family: Custom;
  src: url("font.woff2");
}

Expected

@font-face{font-family:Custom;src:url(font.woff2)}

Outputs

clean-css ✗

@font-face{font-family:Custom;src:url("font.woff2")}

csskit ✗

@font-face{font-family:Custom;src:url("font.woff2")}

csslop ✓

@font-face{font-family:Custom;src:url(font.woff2)}

cssnano ✓

@font-face{font-family:Custom;src:url(font.woff2)}

csso ✓

@font-face{font-family:Custom;src:url(font.woff2)}

esbuild ✓

@font-face{font-family:Custom;src:url(font.woff2)}

lightningcss ✓

@font-face{font-family:Custom;src:url(font.woff2)}

sass ✗

@font-face{font-family:Custom;src:url("font.woff2")}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

format() string to keyword conversion

The format() function in @font-face src accepts both string and keyword syntax per CSS Fonts 4. format("woff2") and format(woff2) are equivalent, so quotes can be safely stripped. Whitespace between url() and format() can also be removed.

@font-face {
  font-family: Custom;
  src: url(font.woff2) format("woff2");
}

Expected

@font-face{font-family:Custom;src:url(font.woff2)format(woff2)}

Outputs

clean-css ✗

@font-face{font-family:Custom;src:url(font.woff2) format("woff2")}

csskit ✗

@font-face{font-family:Custom;src:url(font.woff2)format("woff2")}

csslop ✓

@font-face{font-family:Custom;src:url(font.woff2)format(woff2)}

cssnano ✗

@font-face{font-family:Custom;src:url(font.woff2) format("woff2")}

csso ✗

@font-face{font-family:Custom;src:url(font.woff2)format("woff2")}

esbuild ✗

@font-face{font-family:Custom;src:url(font.woff2) format("woff2")}

lightningcss ✗

@font-face{font-family:Custom;src:url(font.woff2)format("woff2")}

sass ✗

@font-face{font-family:Custom;src:url(font.woff2) format("woff2")}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

font-family quotes required for generic family keywords

Unquoting "serif" produces the generic family keyword serif, which refers to the browser default serif font -- not a custom font named "serif". Quotes must be preserved when the family name matches a generic keyword.

@font-face {
  font-family: "serif";
  src: url(custom.woff2);
}

Expected

@font-face{font-family:"serif";src:url(custom.woff2)}

Outputs

clean-css ✓

@font-face{font-family:"serif";src:url(custom.woff2)}

csskit ✓

@font-face{font-family:"serif";src:url(custom.woff2)}

csslop ✓

@font-face{font-family:"serif";src:url(custom.woff2)}

cssnano ✓

@font-face{font-family:"serif";src:url(custom.woff2)}

csso ✓

@font-face{font-family:"serif";src:url(custom.woff2)}

esbuild ✓

@font-face{font-family:"serif";src:url(custom.woff2)}

lightningcss ✓

@font-face{font-family:"serif";src:url(custom.woff2)}

sass ✓

@font-face{font-family:"serif";src:url(custom.woff2)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✗ ✗ ✓ ✓ ✗ ✗ ✓ ✗
Details

unicode-range wildcard compression

U+0000-00FF can be shortened to U+?? using wildcard notation. The ? replaces trailing hex digits that cover the full 0-F range, and leading zeros in the prefix can be dropped.

@font-face {
  font-family: test;
  src: local(test);
  unicode-range: U+0000-00FF;
}

Expected

@font-face{font-family:test;src:local(test);unicode-range:U+??}

Also accepted

@font-face{font-family:test;src:local(test);unicode-range:u+??}

Outputs

clean-css ✗

@font-face{font-family:test;src:local(test);unicode-range:U+0000-00FF}

csskit ✗

@font-face{font-family:test;src:local(test);unicode-range:U+0000-00FF}

csslop ✓

@font-face{font-family:test;src:local(test);unicode-range:U+??}

cssnano ✓

@font-face{font-family:test;src:local(test);unicode-range:u+??}

csso ✗

@font-face{font-family:test;src:local(test);unicode-range:U+0000-00FF}

esbuild ✗

@font-face{font-family:test;src:local(test);unicode-range:U+0000-00FF}

lightningcss ✓

@font-face{font-family:test;src:local(test);unicode-range:U+??}

sass ✗

@font-face{font-family:test;src:local(test);unicode-range:U+0000-00FF}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0007 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Use ranges for adjacent unicode-range values

If there are multiple adjacent (off by 1) unicode values in a unicode range, the first and last item in a group can be combined in a range (U+2000,U+2001,U+2002 becomes U+2000-2002).

@font-face {
  unicode-range:
    U+1F170,
    U+1F172,
    U+1F173,
    U+1F175,
    U+1F177,
    U+1F178,
    U+1F179,
    U+1F17A,
    U+1F17C-1F180;
}

Expected

@font-face{unicode-range:U+1F170,U+1F172-1F173,U+1F175,U+1F177-1F17A,U+1F17C-1F180}

Also accepted

@font-face{unicode-range:u+1f170,u+1f172-1f173,u+1f175,u+1f177-1f17a,u+1f17c-1f180}

Outputs

clean-css ✗

@font-face{unicode-range:U+1F170,U+1F172,U+1F173,U+1F175,U+1F177,U+1F178,U+1F179,U+1F17A,U+1F17C-1F180}

csskit ✗

@font-face{unicode-range:U+1F170,U+1F172,U+1F173,U+1F175,U+1F177,U+1F178,U+1F179,U+1F17A,U+1F17C-1F180}

csslop ✓

@font-face{unicode-range:U+1F170,U+1F172-1F173,U+1F175,U+1F177-1F17A,U+1F17C-1F180}

cssnano ✓

@font-face{unicode-range:u+1f170,u+1f172-1f173,u+1f175,u+1f177-1f17a,u+1f17c-1f180}

csso ✗

@font-face{unicode-range:U+1F170,U+1F172,U+1F173,U+1F175,U+1F177,U+1F178,U+1F179,U+1F17A,U+1F17C-1F180}

esbuild ✗

@font-face{unicode-range:U+1F170,U+1F172,U+1F173,U+1F175,U+1F177,U+1F178,U+1F179,U+1F17A,U+1F17C-1F180}

lightningcss ✗

@font-face{unicode-range:U+1F170,U+1F172,U+1F173,U+1F175,U+1F177,U+1F178,U+1F179,U+1F17A,U+1F17C-1F180}

sass ✗

@font-face{unicode-range:U+1F170,U+1F172,U+1F173,U+1F175,U+1F177,U+1F178,U+1F179,U+1F17A,U+1F17C-1F180}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0008 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Remove duplicate unicode-range values

If a unicode-range contains a duplicate value it can be removed.

@font-face {
  unicode-range: U+2001, U+2001;
}

Expected

@font-face{unicode-range:U+2001}

Also accepted

@font-face{unicode-range:u+2001}

Outputs

clean-css ✗

@font-face{unicode-range:U+2001,U+2001}

csskit ✗

@font-face{unicode-range:U+2001,U+2001}

csslop ✓

@font-face{unicode-range:U+2001}

cssnano ✓

@font-face{unicode-range:u+2001}

csso ✗

@font-face{unicode-range:U+2001,U+2001}

esbuild ✗

@font-face{unicode-range:U+2001,U+2001}

lightningcss ✗

@font-face{unicode-range:U+2001,U+2001}

sass ✗

@font-face{unicode-range:U+2001,U+2001}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0009 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Remove unicode-range values that exist in other unicode ranges

If a unicode range contains a duplicate value that is stored in another range, the duplicate can be removed.

@font-face {
  unicode-range: U+2000-2002, U+2001;
}

Expected

@font-face{unicode-range:U+2000-2002}

Also accepted

@font-face{unicode-range:u+2000-2002}

Outputs

clean-css ✗

@font-face{unicode-range:U+2000-2002,U+2001}

csskit ✗

@font-face{unicode-range:U+2000-2002,U+2001}

csslop ✓

@font-face{unicode-range:U+2000-2002}

cssnano ✓

@font-face{unicode-range:u+2000-2002}

csso ✗

@font-face{unicode-range:U+2000-2002,U+2001}

esbuild ✗

@font-face{unicode-range:U+2000-2002,U+2001}

lightningcss ✗

@font-face{unicode-range:U+2000-2002,U+2001}

sass ✗

@font-face{unicode-range:U+2000-2002,U+2001}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0010 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Merge overlapping unicode ranges

If unicode ranges overlap, merge them into one range.

@font-face {
  unicode-range: U+2000-2002, U+2001-2004;
}

Expected

@font-face{unicode-range:U+2000-2004}

Also accepted

@font-face{unicode-range:u+2000-2004}

Outputs

clean-css ✗

@font-face{unicode-range:U+2000-2002,U+2001-2004}

csskit ✗

@font-face{unicode-range:U+2000-2002,U+2001-2004}

csslop ✓

@font-face{unicode-range:U+2000-2004}

cssnano ✓

@font-face{unicode-range:u+2000-2004}

csso ✗

@font-face{unicode-range:U+2000-2002,U+2001-2004}

esbuild ✗

@font-face{unicode-range:U+2000-2002,U+2001-2004}

lightningcss ✗

@font-face{unicode-range:U+2000-2002,U+2001-2004}

sass ✗

@font-face{unicode-range:U+2000-2002,U+2001-2004}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0011 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Merge unicode ranges with wildcards that are encompassed by larger ranges

If a unicode range with wildcards is fully encompassed by other ranges, merge them into one range. For example, U+4?? represents the range of U+400-4FF. If a larger range encompasses those values, then the wildcard could be removed.

@font-face {
  unicode-range: U+4??, U+399-500;
}

Expected

@font-face{unicode-range:U+399-500}

Also accepted

@font-face{unicode-range:u+399-500}

Outputs

clean-css ✗

@font-face{unicode-range:U+4??,U+399-500}

csskit ✗

@font-face{unicode-range:U+4??,U+399-500}

csslop ✓

@font-face{unicode-range:U+399-500}

cssnano ✓

@font-face{unicode-range:u+399-500}

csso ✗

@font-face{unicode-range:U+4??,U+399-500}

esbuild ✗

@font-face{unicode-range:U+4??,U+399-500}

lightningcss ✗

@font-face{unicode-range:U+4??,U+399-500}

sass ✗

@font-face{unicode-range:U+4??,U+399-500}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0012 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Merge overlapping unicode ranges with wildcards

If a unicode range with wildcards has a partial overlap with other ranges, merge them into one range. For example, U+4?? represents the range of U+400-4FF. If another range contains some of the same values, replace them both with a single range that handles all associated values.

@font-face {
  unicode-range: U+4??, U+455-555;
}

Expected

@font-face{unicode-range:U+400-555}

Also accepted

@font-face{unicode-range:u+400-555}

Outputs

clean-css ✗

@font-face{unicode-range:U+4??,U+455-555}

csskit ✗

@font-face{unicode-range:U+4??,U+455-555}

csslop ✓

@font-face{unicode-range:U+400-555}

cssnano ✓

@font-face{unicode-range:u+400-555}

csso ✗

@font-face{unicode-range:U+4??,U+455-555}

esbuild ✗

@font-face{unicode-range:U+4??,U+455-555}

lightningcss ✗

@font-face{unicode-range:U+4??,U+455-555}

sass ✗

@font-face{unicode-range:U+4??,U+455-555}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0013 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Merge overlapping unicode ranges into wildcard

When unicode ranges map to a set of values that could be represented with wildcards, they should be replaced with the wildcard to reduce character count.

@font-face {
  unicode-range: U+500-503, U+504-5FF;
}

Expected

@font-face{unicode-range:U+5??}

Also accepted

@font-face{unicode-range:u+5??}

Outputs

clean-css ✗

@font-face{unicode-range:U+500-503,U+504-5FF}

csskit ✗

@font-face{unicode-range:U+500-503,U+504-5FF}

csslop ✓

@font-face{unicode-range:U+5??}

cssnano ✓

@font-face{unicode-range:u+5??}

csso ✗

@font-face{unicode-range:U+500-503,U+504-5FF}

esbuild ✗

@font-face{unicode-range:U+500-503,U+504-5FF}

lightningcss ✗

@font-face{unicode-range:U+500-503,U+504-5FF}

sass ✗

@font-face{unicode-range:U+500-503,U+504-5FF}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 3 / 13 2 / 13 13 / 13 12 / 13 3 / 13 4 / 13 5 / 13 2 / 13
Percent 23.07% 15.38% 100% 92.3% 23.07% 30.76% 38.46% 15.38%
Duration 1ms 5ms 2ms 9ms 1ms 6ms 1ms 7ms

gradients #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✗ ✗ ✓ ✗ ✗ ✗ ✓ ✗
Details

Default gradient direction omission

linear-gradient(to bottom, ...) can omit the direction since to bottom (180deg) is the default.

a {
  background: linear-gradient(to bottom, red, blue);
}

Expected

a{background:linear-gradient(red,#00f)}

Validate

Outputs

clean-css ✗

a{background:linear-gradient(to bottom,red,#00f)}

csskit ✗

a{background:linear-gradient(to bottom,red,blue)}

csslop ✓

a{background:linear-gradient(red,#00f)}

cssnano ✗

a{background:linear-gradient(180deg,red,blue)}

csso ✗

a{background:linear-gradient(to bottom,red,#00f)}

esbuild ✗

a{background:linear-gradient(to bottom,red,#00f)}

lightningcss ✓

a{background:linear-gradient(red,#00f)}

sass ✗

a{background:linear-gradient(to bottom, red, blue)}
1ms
1ms
2ms
1ms
1ms
1ms
1ms
1ms
0002 ✗ ✗ ✓ ✗ ✗ ✗ ✓ ✗
Details

180deg gradient direction omission

linear-gradient(180deg, ...) is equivalent to the default direction and can be omitted.

a {
  background: linear-gradient(180deg, red, blue);
}

Expected

a{background:linear-gradient(red,#00f)}

Validate

Outputs

clean-css ✗

a{background:linear-gradient(180deg,red,#00f)}

csskit ✗

a{background:linear-gradient(180deg,red,blue)}

csslop ✓

a{background:linear-gradient(red,#00f)}

cssnano ✗

a{background:linear-gradient(180deg,red,blue)}

csso ✗

a{background:linear-gradient(180deg,red,#00f)}

esbuild ✗

a{background:linear-gradient(180deg,red,#00f)}

lightningcss ✓

a{background:linear-gradient(red,#00f)}

sass ✗

a{background:linear-gradient(180deg, red, blue)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✗ ✗ ✓ ✗ ✗ ✗ ✓ ✗
Details

Gradient direction keyword to angle

to right can be replaced with 90deg which is shorter.

a {
  background: linear-gradient(to right, red, blue);
}

Expected

a{background:linear-gradient(90deg,red,#00f)}

Validate

Outputs

clean-css ✗

a{background:linear-gradient(to right,red,#00f)}

csskit ✗

a{background:linear-gradient(to right,red,blue)}

csslop ✓

a{background:linear-gradient(90deg,red,#00f)}

cssnano ✗

a{background:linear-gradient(90deg,red,blue)}

csso ✗

a{background:linear-gradient(to right,red,#00f)}

esbuild ✗

a{background:linear-gradient(to right,red,#00f)}

lightningcss ✓

a{background:linear-gradient(90deg,red,#00f)}

sass ✗

a{background:linear-gradient(to right, red, blue)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✗ ✗ ✓ ✓ ✗ ✓ ✗ ✗
Details

Redundant gradient stop positions

0% on the first stop and 100% on the last stop are defaults and can be removed.

a {
  background: linear-gradient(red 0%, tan 25%, #00f 100%);
}

Expected

a{background:linear-gradient(red,tan 25%,#00f)}

Validate

Outputs

clean-css ✗

a{background:linear-gradient(red 0,tan 25%,#00f 100%)}

csskit ✗

a{background:linear-gradient(red 0%,tan 25%,#00f 100%)}

csslop ✓

a{background:linear-gradient(red,tan 25%,#00f)}

cssnano ✓

a{background:linear-gradient(red,tan 25%,#00f)}

csso ✗

a{background:linear-gradient(red 0,tan 25%,#00f 100%)}

esbuild ✓

a{background:linear-gradient(red,tan 25%,#00f)}

lightningcss ✗

a{background:linear-gradient(red 0%,tan 25%,#00f 100%)}

sass ✗

a{background:linear-gradient(red 0%, tan 25%, #00f 100%)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✗ ✗ ✓ ✗ ✗ ✗ ✓ ✗
Details

Default radial-gradient shape and position

ellipse at center is the default for radial-gradient and can be omitted entirely.

a {
  background: radial-gradient(ellipse at center, red, blue);
}

Expected

a{background:radial-gradient(red,#00f)}

Validate

Outputs

clean-css ✗

a{background:radial-gradient(ellipse at center,red,#00f)}

csskit ✗

a{background:radial-gradient(ellipse at center,red,blue)}

csslop ✓

a{background:radial-gradient(red,#00f)}

cssnano ✗

a{background:radial-gradient(ellipse at center,red,blue)}

csso ✗

a{background:radial-gradient(ellipse at center,red,#00f)}

esbuild ✗

a{background:radial-gradient(ellipse at center,red,#00f)}

lightningcss ✓

a{background:radial-gradient(red,#00f)}

sass ✗

a{background:radial-gradient(ellipse at center, red, blue)}
1ms
3ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Combine adjacent identical colors in linear-gradient and remove 0%/100%

If the same color has multiple adjacent color stops, the color stops can be combined, retaining only the first and last percent and separating them with a space. If the first percent is 0% or the last percent is 100% they can be removed as these are automatically implied. If the first percent is the same as the last percent of the previous color stop, it can become a unitless 0.

p {
  background: linear-gradient(
    red 0%,
    red 50%,
    tan 50%,
    tan 100%
  );
}

Expected

p{background:linear-gradient(red 50%,tan 0)}

Outputs

clean-css ✗

p{background:linear-gradient(red 0,red 50%,tan 50%,tan 100%)}

csskit ✗

p{background:linear-gradient(red 0%,red 50%,tan 50%,tan 100%)}

csslop ✓

p{background:linear-gradient(red 50%,tan 0)}

cssnano ✗

p{background:linear-gradient(red,red 50%,tan 0,tan)}

csso ✗

p{background:linear-gradient(red 0,red 50%,tan 50%,tan 100%)}

esbuild ✗

p{background:linear-gradient(red 0% 50%,tan 50% 100%)}

lightningcss ✗

p{background:linear-gradient(red 0% 50%,tan 50% 100%)}

sass ✗

p{background:linear-gradient(red 0%, red 50%, tan 50%, tan 100%)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0007 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Combine adjacent identical colors in linear-gradient

If the same color has multiple adjacent color stops the color stops can be combined, retaining only the first and last percent and separating them with a space. When defining the start and stop of a color you can use 0 (without a percent sign) to indicate that the first value will be the same as the last value in the previous color stop.

p {
  background: linear-gradient(
    #fff,
    red 25%,
    red 35%,
    red 50%,
    tan 50%,
    tan 75%,
    tan 85%,
    #fff
  );
}

Expected

p{background:linear-gradient(#fff,red 25% 50%,tan 0 85%,#fff)}

Outputs

clean-css ✗

p{background:linear-gradient(#fff,red 25%,red 35%,red 50%,tan 50%,tan 75%,tan 85%,#fff)}

csskit ✗

p{background:linear-gradient(#fff,red 25%,red 35%,red 50%,tan 50%,tan 75%,tan 85%,#fff)}

csslop ✓

p{background:linear-gradient(#fff,red 25% 50%,tan 0 85%,#fff)}

cssnano ✗

p{background:linear-gradient(#fff,red 25%,red 35%,red 50%,tan 0,tan 75%,tan 85%,#fff)}

csso ✗

p{background:linear-gradient(#fff,red 25%,red 35%,red 50%,tan 50%,tan 75%,tan 85%,#fff)}

esbuild ✗

p{background:linear-gradient(#fff,red 25% 35%,red 50%,tan 50% 75%,tan 85%,#fff)}

lightningcss ✗

p{background:linear-gradient(#fff,red 25% 35%,red 50%,tan 50% 75%,tan 85%,#fff)}

sass ✗

p{background:linear-gradient(#fff, red 25%, red 35%, red 50%, tan 50%, tan 75%, tan 85%, #fff)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0008 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Remove 0% and 100% from grouped color stops in gradient

You can group the start and stop of a color in a gradient together with a space separation. However, 0% and 100% are not required because they are implied for the first and last color in the list. You can also use a unitless 0 to indicate the first position of a color is the same as the stop of the previous color.

p {
  background: linear-gradient(
    red 0% 40%,
    tan 0 70%,
    #00f 0 100%
  );
}

Expected

p{background:linear-gradient(red 40%,tan 0 70%,#00f 0)}

Outputs

clean-css ✗

p{background:linear-gradient(red 0 40%,tan 0 70%,#00f 0 100%)}

csskit ✗

p{background:linear-gradient(red 0% 40%,tan 0 70%,#00f 0 100%)}

csslop ✓

p{background:linear-gradient(red 40%,tan 0 70%,#00f 0)}

cssnano ✗

p{background:linear-gradient(red 0 40%,tan 0 70%,#00f 0 100%)}

csso ✗

p{background:linear-gradient(red 0 40%,tan 0 70%,#00f 0 100%)}

esbuild ✗

p{background:linear-gradient(red 0% 40%,tan 0 70%,#00f 0 100%)}

lightningcss ✗

p{background:linear-gradient(red 0% 40%,tan 0 70%,#00f 0 100%)}

sass ✗

p{background:linear-gradient(red 0% 40%, tan 0 70%, #00f 0 100%)}
1ms
1ms
1ms
2ms
1ms
1ms
1ms
1ms
0009 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Replace color-start with 0 when it matches the prior color-stop

You can group the start and stop of a color in a gradient together with a space separation. You can also use a unitless 0 to indicate the first position of a color is the same as the stop of the previous color.

p {
  background: linear-gradient(
    red 40%,
    tan 40% 70%,
    #00f 70%
  );
}

Expected

p{background:linear-gradient(red 40%,tan 0 70%,#00f 0)}

Outputs

clean-css ✗

p{background:linear-gradient(red 40%,tan 40% 70%,#00f 70%)}

csskit ✗

p{background:linear-gradient(red 40%,tan 40% 70%,#00f 70%)}

csslop ✓

p{background:linear-gradient(red 40%,tan 0 70%,#00f 0)}

cssnano ✓

p{background:linear-gradient(red 40%,tan 0 70%,#00f 0)}

csso ✗

p{background:linear-gradient(red 40%,tan 40% 70%,#00f 70%)}

esbuild ✗

p{background:linear-gradient(red 40%,tan 40% 70%,#00f 70%)}

lightningcss ✗

p{background:linear-gradient(red 40%,tan 40% 70%,#00f 70%)}

sass ✗

p{background:linear-gradient(red 40%, tan 40% 70%, #00f 70%)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
2ms
0010 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Remove triple 100% from end of gradient

If a gradient's color stop ends with 100%, and is followed by another color of 100% start and 100% end, both can be removed, as the 100% will be implied. Even though the prior color stop ends with the same percent as the start of the next color, since the start is 100% it can be removed, instead of replaced with unitless 0.

p {
  background: radial-gradient(
    circle farthest-side at 0% 0%,
    #000 0% 25%,
    #ff0 50% 100%,
    #000 100% 100%
  );
}

Expected

p{background:radial-gradient(circle farthest-side at 0% 0%,#000 25%,#ff0 50% 100%,#000)}

Outputs

clean-css ✗

p{background:radial-gradient(circle farthest-side at 0 0,#000 0 25%,#ff0 50% 100%,#000 100% 100%)}

csskit ✗

p{background:radial-gradient(circle farthest-side at 0% 0%,#000 0% 25%,#ff0 50% 100%,#000 100% 100%)}

csslop ✓

p{background:radial-gradient(circle farthest-side at 0% 0%,#000 25%,#ff0 50% 100%,#000)}

cssnano ✗

p{background:radial-gradient(circle farthest-side at 0 0,#000 0 25%,#ff0 50% 100%,#000 0 0)}

csso ✗

p{background:radial-gradient(circle farthest-side at 0 0,#000 0 25%,#ff0 50% 100%,#000 100% 100%)}

esbuild ✗

p{background:radial-gradient(circle farthest-side at 0% 0%,#000 0% 25%,#ff0 50% 100%,#000 100% 100%)}

lightningcss ✗

p{background:radial-gradient(circle farthest-side at 0 0,#000 0% 25%,#ff0 50% 100%,#000 100% 100%)}

sass ✗

p{background:radial-gradient(circle farthest-side at 0% 0%, #000 0% 25%, #ff0 50% 100%, #000 100% 100%)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0011 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Remove triple 0% from start of gradient

If the first color in a gradient has a color start and stop of 0%, both can be removed. If the following color starts with the same percent as the stop of the previous color, it can be renamed to a unitless 0.

p {
  background: radial-gradient(
    circle farthest-side at 0% 0%,
    #0ff 0% 0%,
    #000 0% 25%,
    #ff0 50%
  );
}

Expected

p{background:radial-gradient(circle farthest-side at 0% 0%,#0ff,#000 0 25%,#ff0 50%)}

Outputs

clean-css ✗

p{background:radial-gradient(circle farthest-side at 0 0,#0ff 0 0,#000 0 25%,#ff0 50%)}

csskit ✗

p{background:radial-gradient(circle farthest-side at 0% 0%,#0ff 0% 0%,#000 0% 25%,#ff0 50%)}

csslop ✓

p{background:radial-gradient(circle farthest-side at 0% 0%,#0ff,#000 0 25%,#ff0 50%)}

cssnano ✗

p{background:radial-gradient(circle farthest-side at 0 0,#0ff 0 0,#000 0 25%,#ff0 50%)}

csso ✗

p{background:radial-gradient(circle farthest-side at 0 0,#0ff 0 0,#000 0 25%,#ff0 50%)}

esbuild ✗

p{background:radial-gradient(circle farthest-side at 0% 0%,#0ff 0% 0%,#000 0% 25%,#ff0 50%)}

lightningcss ✗

p{background:radial-gradient(circle farthest-side at 0 0,#0ff 0% 0%,#000 0% 25%,#ff0 50%)}

sass ✗

p{background:radial-gradient(circle farthest-side at 0% 0%, #0ff 0% 0%, #000 0% 25%, #ff0 50%)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0012 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✗
Details

Simple linear gradient

This is a simple linear gradient with a color keyword and 6-digit hex.

a {
  background: linear-gradient(red, #123456);
}

Expected

a{background:linear-gradient(red,#123456)}

Outputs

clean-css ✓

a{background:linear-gradient(red,#123456)}

csskit ✓

a{background:linear-gradient(red,#123456)}

csslop ✓

a{background:linear-gradient(red,#123456)}

cssnano ✓

a{background:linear-gradient(red,#123456)}

csso ✓

a{background:linear-gradient(red,#123456)}

esbuild ✓

a{background:linear-gradient(red,#123456)}

lightningcss ✓

a{background:linear-gradient(red,#123456)}

sass ✗

a{background:linear-gradient(red, #123456)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0013 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✗
Details

Simple radial gradient

This is a simple radial gradient between a color keyword and a 6-digit hex.

a {
  background: radial-gradient(red, #123456);
}

Expected

a{background:radial-gradient(red,#123456)}

Outputs

clean-css ✓

a{background:radial-gradient(red,#123456)}

csskit ✓

a{background:radial-gradient(red,#123456)}

csslop ✓

a{background:radial-gradient(red,#123456)}

cssnano ✓

a{background:radial-gradient(red,#123456)}

csso ✓

a{background:radial-gradient(red,#123456)}

esbuild ✓

a{background:radial-gradient(red,#123456)}

lightningcss ✓

a{background:radial-gradient(red,#123456)}

sass ✗

a{background:radial-gradient(red, #123456)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0014 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Respect percents inside color-mix in gradients

The 0% and 100% used inside the color-mix functions must be retained as they impact how much of the --x/red to show versus the #0000 in the mix. However the 0% used for the first color stop in the gradient can be implied, as well as the 100% used for the last color stop. The 50% cannot be implied and must be retained.

a {
  background: linear-gradient(
    color-mix(in srgb, var(--x, red) 0%, #0000) 0%,
    color-mix(in srgb, var(--x, red) 100%, #0000) 50%,
    color-mix(in srgb, var(--x, red) 0%, #0000) 100%
  );
}

Expected

a{background:linear-gradient(color-mix(in srgb,var(--x,red)0%,#0000),color-mix(in srgb,var(--x,red)100%,#0000)50%,color-mix(in srgb,var(--x,red)0%,#0000))}

Outputs

clean-css ✗

a{background:linear-gradient(color-mix(in srgb,var(--x,red) 0,#0000) 0,color-mix(in srgb,var(--x,red) 100%,#0000) 50%,color-mix(in srgb,var(--x,red) 0,#0000) 100%)}

csskit ✗

a{background:linear-gradient(color-mix(in srgb,var(--x,red) 0%,#0000) 0%,color-mix(in srgb,var(--x,red) 100%,#0000) 50%,color-mix(in srgb,var(--x,red) 0%,#0000) 100%)}

csslop ✓

a{background:linear-gradient(color-mix(in srgb,var(--x,red)0%,#0000),color-mix(in srgb,var(--x,red)100%,#0000)50%,color-mix(in srgb,var(--x,red)0%,#0000))}

cssnano ✗

a{background:linear-gradient(color-mix(in srgb,var(--x,red) 0%,#0000) 0,color-mix(in srgb,var(--x,red) 100%,#0000) 50%,color-mix(in srgb,var(--x,red) 0%,#0000) 100%)}

csso ✗

a{background:linear-gradient(color-mix(in srgb,var(--x, red) 0%,#0000) 0%,color-mix(in srgb,var(--x, red) 100%,#0000) 50%,color-mix(in srgb,var(--x, red) 0%,#0000) 100%)}

esbuild ✗

a{background:linear-gradient(color-mix(in srgb,var(--x, red) 0%,#0000),color-mix(in srgb,var(--x, red) 100%,#0000),color-mix(in srgb,var(--x, red) 0%,#0000))}

lightningcss ✗

a{background:linear-gradient(color-mix(in srgb, var(--x,red) 0%, #0000) 0%, color-mix(in srgb, var(--x,red) 100%, #0000) 50%, color-mix(in srgb, var(--x,red) 0%, #0000) 100%)}

sass ✗

a{background:linear-gradient(color-mix(in srgb, var(--x, red) 0%, rgba(0, 0, 0, 0)) 0%, color-mix(in srgb, var(--x, red) 100%, rgba(0, 0, 0, 0)) 50%, color-mix(in srgb, var(--x, red) 0%, rgba(0, 0, 0, 0)) 100%)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 2 / 14 2 / 14 14 / 14 4 / 14 2 / 14 3 / 14 6 / 14 0 / 14
Percent 14.28% 14.28% 100% 28.57% 14.28% 21.42% 42.85% 0%
Duration 2ms 5ms 4ms 14ms 3ms 7ms 1ms 10ms

idempotency #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Test idempotency

Given a test input like this: a{color:rebeccapurple;}, a minifier may produce an output like this a{color:#663399}. If we then run that output through the same minfier and it produces a different value, like a{color:#639}, then it has failed at idempotency for that test.

A minifier is considered idempotent if the minified output could be minifed itself and no changes occur. This test takes the minified output of every test in the css-minify-tests Test Suite, and checks if they change when being minifed.

If a minifier fails idempotency for any test, the name of the test will be listed in the Outputs below. Whether the output passes the original test is not relevant to idempotency, giving the same incorrect answer on re-run is still idempotent.

/* See description for test details. */

Expected

Outputs

clean-css ✗

Failures: colors/0011, colors/0055, merging/0026, merging/0038, shorthands/0047

csskit ✗

Failures: calc/0001

csslop ✓

cssnano ✓

csso ✗

Failures: merging/0028, shorthands/0053

esbuild ✗

Failures: duplicates/0025, shorthand-values/0016

lightningcss ✗

Failures: combined/0002, selectors/0019, values/0062

sass ✗

Failures: calc/0036, colors/0022, selectors-advanced/0031
0ms
0ms
0ms
0ms
0ms
0ms
0ms
0ms
Subtotal 0 / 1 0 / 1 1 / 1 1 / 1 0 / 1 0 / 1 0 / 1 0 / 1
Percent 0% 0% 100% 100% 0% 0% 0% 0%
Duration 0ms 0ms 0ms 0ms 0ms 0ms 0ms 0ms

import #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✓
Details

url() to string form in @import

@import url("foo.css") can be shortened to @import"foo.css". The CSS spec allows both forms and the string form is always shorter. No space needed between @import and the string token.

@import url("foo.css");

Expected

@import"foo.css"

Outputs

clean-css ✗

@import url(foo.css);

csskit ✗

@import"foo.css";

csslop ✓

@import"foo.css"

cssnano ✗

@import "foo.css";

csso ✗

@import url(foo.css);

esbuild ✗

@import"foo.css";

lightningcss ✗

@import "foo.css";

sass ✓

@import"foo.css"
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✓
Details

@import with media query

@import url("foo.css") screen shortens to @import"foo.css"screen. The string form removes the url() wrapper and no space is needed between the closing quote and the media query keyword.

@import url("foo.css") screen;

Expected

@import"foo.css"screen

Outputs

clean-css ✗

@import url(foo.css) screen;

csskit ✗

@import"foo.css"screen;

csslop ✓

@import"foo.css"screen

cssnano ✗

@import "foo.css" screen;

csso ✗

@import url(foo.css)screen;

esbuild ✗

@import"foo.css"screen;

lightningcss ✗

@import "foo.css" screen;

sass ✓

@import"foo.css"screen
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✓
Details

Unquoted url() to string form in @import

@import url(foo.css) shortens to @import"foo.css". Even when the url() value is already unquoted, the string form is shorter because it removes the url( and ) wrapper (5 chars) and adds only 2 quote chars.

@import url(foo.css);

Expected

@import"foo.css"

Outputs

clean-css ✗

@import url(foo.css);

csskit ✗

@import"foo.css";

csslop ✓

@import"foo.css"

cssnano ✗

@import "foo.css";

csso ✗

@import url(foo.css);

esbuild ✗

@import"foo.css";

lightningcss ✗

@import "foo.css";

sass ✓

@import"foo.css"
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✓
Details

@import with layer keyword

@import url("foo.css") layer shortens to @import"foo.css"layer. The layer keyword follows the import URL and no space is needed after the closing quote.

@import url("foo.css") layer;

Expected

@import"foo.css"layer

Outputs

clean-css ✗

@import url(foo.css) layer;

csskit ✗

@import"foo.css"layer;

csslop ✓

@import"foo.css"layer

cssnano ✗

@import "foo.css" layer;

csso ✗

@import url(foo.css)layer;

esbuild ✗

@import"foo.css"layer;

lightningcss ✗

@import "foo.css" layer;

sass ✓

@import"foo.css"layer
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

@import with layer() and supports()

@import url("foo.css") layer(base) supports(foo: bar) removes url() wrapper, removes spaces between the closing ) and next keyword/function, and removes whitespace inside the supports() condition. Uses an unknown property so minifiers cannot elide the supports() condition.

@import url("foo.css") layer(base) supports(foo: bar);

Expected

@import"foo.css"layer(base)supports(foo:bar)

Outputs

clean-css ✗

@import url(foo.css) layer(base) supports(foo: bar);

csskit ✗

@import url("foo.css") layer(base) supports(foo:bar);

csslop ✓

@import"foo.css"layer(base)supports(foo:bar)

cssnano ✗

@import "foo.css" layer(base) supports(foo: bar);

csso ✗

@import url("foo.css") layer(base) supports(foo: bar);

esbuild ✗

@import"foo.css"layer(base) supports(foo: bar);

lightningcss ✗

@import "foo.css" layer(base) supports(foo:bar);

sass ✗

@import"foo.css"layer(base) supports(foo: bar)
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Keep color-mix() with three colours in @import supports()

The supports() condition on @import follows the same rules as @supports. Resolving the mix to #555 would load the stylesheet in browsers which might not support color-mix(), or not support color-mix with with three or more colours.

@import "a.css" supports(color: color-mix(in srgb, red, blue, lime));

Expected

@import"a.css"supports(color:color-mix(in srgb,red,blue,lime))

Outputs

clean-css ✗

@import url(a.css) supports(color: color-mix(in srgb, red, blue, lime));

csskit ✗

@import"a.css" supports(color:color-mix(in srgb,red,blue,lime));

csslop ✓

@import"a.css"supports(color:color-mix(in srgb,red,blue,lime))

cssnano ✗

@import "a.css" supports(color: color-mix(in srgb, red, blue, lime));

csso ✗

@import "a.css" supports(color: color-mix(in srgb, red, blue, lime));

esbuild ✗

@import"a.css"supports(color: color-mix(in srgb,red,blue,lime));

lightningcss ✗

@import "a.css" supports(color:color-mix(in srgb, red, blue, lime));

sass ✗

@import"a.css"supports(color: color-mix(in srgb, red, blue, lime))
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 0 / 6 0 / 6 6 / 6 0 / 6 0 / 6 0 / 6 0 / 6 4 / 6
Percent 0% 0% 100% 0% 0% 0% 0% 66.66%
Duration 1ms 1ms 1ms 3ms 1ms 2ms 1ms 3ms

initial #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Convert background-clip border-box value to initial

The initial value for background-clip is border-box, so they are equivalent. However, initial is both shorter and a global value (giving more opportunities for gzipping).

a {
  background-clip: border-box;
}

Expected

a{background-clip:initial}

Outputs

clean-css ✗

a{background-clip:border-box}

csskit ✗

a{background-clip:border-box}

csslop ✓

a{background-clip:initial}

cssnano ✓

a{background-clip:initial}

csso ✗

a{background-clip:border-box}

esbuild ✗

a{background-clip:border-box}

lightningcss ✗

a{background-clip:border-box}

sass ✗

a{background-clip:border-box}
1ms
3ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Convert background-origin padding-box value to initial

The initial value for background-origin is padding-box, so they are equivalent. However, initial is both shorter and a global value (giving more opportunities for gzipping).

a {
  background-origin: padding-box;
}

Expected

a{background-origin:initial}

Outputs

clean-css ✗

a{background-origin:padding-box}

csskit ✗

a{background-origin:padding-box}

csslop ✓

a{background-origin:initial}

cssnano ✓

a{background-origin:initial}

csso ✗

a{background-origin:padding-box}

esbuild ✗

a{background-origin:padding-box}

lightningcss ✗

a{background-origin:padding-box}

sass ✗

a{background-origin:padding-box}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Convert border-collapse separate value to initial

The initial value for border-collapse is separate, so they are equivalent. However, initial is both shorter and a global value (giving more opportunities for gzipping).

a {
  border-collapse: separate;
}

Expected

a{border-collapse:initial}

Outputs

clean-css ✗

a{border-collapse:separate}

csskit ✗

a{border-collapse:separate}

csslop ✓

a{border-collapse:initial}

cssnano ✓

a{border-collapse:initial}

csso ✗

a{border-collapse:separate}

esbuild ✗

a{border-collapse:separate}

lightningcss ✗

a{border-collapse:separate}

sass ✗

a{border-collapse:separate}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Convert box-sizing content-box value to initial

The initial value for box-sizing is content-box, so they are equivalent. However, initial is both shorter and a global value (giving more opportunities for gzipping).

p {
  box-sizing: content-box;
}

Expected

p{box-sizing:initial}

Outputs

clean-css ✗

p{box-sizing:content-box}

csskit ✗

p{box-sizing:content-box}

csslop ✓

p{box-sizing:initial}

cssnano ✓

p{box-sizing:initial}

csso ✗

p{box-sizing:content-box}

esbuild ✗

p{box-sizing:content-box}

lightningcss ✗

p{box-sizing:content-box}

sass ✗

p{box-sizing:content-box}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Convert mask-clip border-box value to initial

The initial value for mask-clip is border-box, so they are equivalent. However, initial is both shorter and a global value (giving more opportunities for gzipping).

a {
  mask-clip: border-box;
}

Expected

a{mask-clip:initial}

Outputs

clean-css ✗

a{mask-clip:border-box}

csskit ✗

a{mask-clip:border-box}

csslop ✓

a{mask-clip:initial}

cssnano ✓

a{mask-clip:initial}

csso ✗

a{mask-clip:border-box}

esbuild ✗

a{mask-clip:border-box}

lightningcss ✗

a{mask-clip:border-box}

sass ✗

a{mask-clip:border-box}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Convert mask-origin border-box value to initial

The initial value for mask-origin is border-box, so they are equivalent. However, initial is both shorter and a global value (giving more opportunities for gzipping).

a {
  mask-origin: border-box;
}

Expected

a{mask-origin:initial}

Outputs

clean-css ✗

a{mask-origin:border-box}

csskit ✗

a{mask-origin:border-box}

csslop ✓

a{mask-origin:initial}

cssnano ✓

a{mask-origin:initial}

csso ✗

a{mask-origin:border-box}

esbuild ✗

a{mask-origin:border-box}

lightningcss ✗

a{mask-origin:border-box}

sass ✗

a{mask-origin:border-box}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0007 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Convert vertical-align baseline value to initial

The initial value for vertical-align is baseline, so they are equivalent. However, initial is both shorter and a global value (giving more opportunities for gzipping).

a {
  vertical-align: baseline;
}

Expected

a{vertical-align:initial}

Outputs

clean-css ✗

a{vertical-align:baseline}

csskit ✗

a{vertical-align:baseline}

csslop ✓

a{vertical-align:initial}

cssnano ✓

a{vertical-align:initial}

csso ✗

a{vertical-align:baseline}

esbuild ✗

a{vertical-align:baseline}

lightningcss ✗

a{vertical-align:baseline}

sass ✗

a{vertical-align:baseline}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0008 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Convert writing-mode horizontal-tb value to initial

The initial value for writing-mode is horizontal-tb, so they are equivalent. However, initial is both shorter and a global value (giving more opportunities for gzipping).

a {
  writing-mode: horizontal-tb;
}

Expected

a{writing-mode:initial}

Outputs

clean-css ✗

a{writing-mode:horizontal-tb}

csskit ✗

a{writing-mode:horizontal-tb}

csslop ✓

a{writing-mode:initial}

cssnano ✗

a{writing-mode:horizontal-tb}

csso ✗

a{writing-mode:horizontal-tb}

esbuild ✗

a{writing-mode:horizontal-tb}

lightningcss ✗

a{writing-mode:horizontal-tb}

sass ✗

a{writing-mode:horizontal-tb}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0009 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Convert border-*-color currentcolor value to initial

The initial value for border-top-color, border-right-color, border-bottom-color, border-left-color, and border-color is currentcolor. This makes currentcolor (or currentColor) equivalent to initial for these properties. However, initial is both shorter and a global value (giving more opportunities for gzipping), so it should be used instead.

.a {
  border-top-color: currentcolor;
}
.b {
  border-right-color: currentcolor;
}
.c {
  border-bottom-color: currentcolor;
}
.d {
  border-left-color: currentcolor;
}
.e {
  border-color: currentcolor;
}

Expected

.a{border-top-color:initial}.b{border-right-color:initial}.c{border-bottom-color:initial}.d{border-left-color:initial}.e{border-color:initial}

Outputs

clean-css ✗

.a{border-top-color:currentcolor}.b{border-right-color:currentcolor}.c{border-bottom-color:currentcolor}.d{border-left-color:currentcolor}.e{border-color:currentcolor}

csskit ✗

.a{border-top-color:currentcolor}.b{border-right-color:currentcolor}.c{border-bottom-color:currentcolor}.d{border-left-color:currentcolor}.e{border-color:currentcolor}

csslop ✓

.a{border-top-color:initial}.b{border-right-color:initial}.c{border-bottom-color:initial}.d{border-left-color:initial}.e{border-color:initial}

cssnano ✗

.a{border-top-color:initial}.b{border-right-color:initial}.c{border-bottom-color:initial}.d{border-left-color:initial}.e{border-color:currentcolor}

csso ✗

.a{border-top-color:currentcolor}.b{border-right-color:currentcolor}.c{border-bottom-color:currentcolor}.d{border-left-color:currentcolor}.e{border-color:currentcolor}

esbuild ✗

.a{border-top-color:currentcolor}.b{border-right-color:currentcolor}.c{border-bottom-color:currentcolor}.d{border-left-color:currentcolor}.e{border-color:currentcolor}

lightningcss ✗

.a{border-top-color:currentColor}.b{border-right-color:currentColor}.c{border-bottom-color:currentColor}.d{border-left-color:currentColor}.e{border-color:currentColor}

sass ✗

.a{border-top-color:currentcolor}.b{border-right-color:currentcolor}.c{border-bottom-color:currentcolor}.d{border-left-color:currentcolor}.e{border-color:currentcolor}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 0 / 9 0 / 9 9 / 9 7 / 9 0 / 9 0 / 9 0 / 9 0 / 9
Percent 0% 0% 100% 77.77% 0% 0% 0% 0%
Duration 1ms 5ms 1ms 5ms 1ms 4ms 1ms 2ms

keyframes #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✗ ✗ ✓ ✓ ✓ ✓ ✓ ✗
Details

@keyframes 100% to to

The 100% keyframe stop can be replaced with the shorter to keyword.

@keyframes fade {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

Expected

@keyframes fade{0%{opacity:0}to{opacity:1}}

Outputs

clean-css ✗

@keyframes fade{0%{opacity:0}100%{opacity:1}}

csskit ✗

@keyframes fade{0%{opacity:0}100%{opacity:1}}

csslop ✓

@keyframes fade{0%{opacity:0}to{opacity:1}}

cssnano ✓

@keyframes fade{0%{opacity:0}to{opacity:1}}

csso ✓

@keyframes fade{0%{opacity:0}to{opacity:1}}

esbuild ✓

@keyframes fade{0%{opacity:0}to{opacity:1}}

lightningcss ✓

@keyframes fade{0%{opacity:0}to{opacity:1}}

sass ✗

@keyframes fade{0%{opacity:0}100%{opacity:1}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✗ ✗ ✓ ✓ ✓ ✓ ✓ ✗
Details

Keyframes from/to keyword optimization

from becomes 0% and 100% becomes to since these are shorter representations.

@keyframes fade {
  from {
    opacity: 0;
  }
  50% {
    opacity: 0.5;
  }
  100% {
    opacity: 1;
  }
}

Expected

@keyframes fade{0%{opacity:0}50%{opacity:.5}to{opacity:1}}

Outputs

clean-css ✗

@keyframes fade{from{opacity:0}50%{opacity:.5}100%{opacity:1}}

csskit ✗

@keyframes fade{from{opacity:0}50%{opacity:.5}100%{opacity:1}}

csslop ✓

@keyframes fade{0%{opacity:0}50%{opacity:.5}to{opacity:1}}

cssnano ✓

@keyframes fade{0%{opacity:0}50%{opacity:.5}to{opacity:1}}

csso ✓

@keyframes fade{0%{opacity:0}50%{opacity:.5}to{opacity:1}}

esbuild ✓

@keyframes fade{0%{opacity:0}50%{opacity:.5}to{opacity:1}}

lightningcss ✓

@keyframes fade{0%{opacity:0}50%{opacity:.5}to{opacity:1}}

sass ✗

@keyframes fade{from{opacity:0}50%{opacity:.5}100%{opacity:1}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 0 / 2 0 / 2 2 / 2 2 / 2 2 / 2 2 / 2 2 / 2 0 / 2
Percent 0% 0% 100% 100% 100% 100% 100% 0%
Duration 1ms 1ms 1ms 2ms 1ms 1ms 1ms 1ms

lang #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✗ ✗ ✓ ✓ ✗ ✗ ✓ ✗
Details

Remove quotes from language-code in :lang()

Quotes surrounding a language code (en, fr-ca, etc) are optional in the CSS :lang() function.

:lang("fr") {
  color: red;
}

Expected

:lang(fr){color:red}

Outputs

clean-css ✗

:lang("fr"){color:red}

csskit ✗

:lang("fr"){color:red}

csslop ✓

:lang(fr){color:red}

cssnano ✓

:lang(fr){color:red}

csso ✗

esbuild ✗

:lang("fr"){color:red}

lightningcss ✓

:lang(fr){color:red}

sass ✗

:lang("fr"){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Combine language-codes in :lang() with comma-separation

The :lang() function accepts a comma-separated list of language codes.

:lang(de), :lang(ja) {
  color: red;
}

Expected

:lang(de,ja){color:red}

Outputs

clean-css ✗

:lang(de),:lang(ja){color:red}

csskit ✗

:lang(de),:lang(ja){color:red}

csslop ✓

:lang(de,ja){color:red}

cssnano ✗

:lang(de),:lang(ja){color:red}

csso ✗

:lang(de),:lang(ja){color:red}

esbuild ✗

:lang(de),:lang(ja){color:red}

lightningcss ✗

:lang(de),:lang(ja){color:red}

sass ✗

:lang(de),:lang(ja){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Lowercase language-codes in :lang()

Language-codes used by :lang() are case-insensitive. Lowercasing them consistently, much like with hex values in color, can potentially aid in gzip compression.

:lang(DE) {
  color: red;
}

Expected

:lang(de){color:red}

Outputs

clean-css ✗

:lang(DE){color:red}

csskit ✗

:lang(DE){color:red}

csslop ✓

:lang(de){color:red}

cssnano ✗

:lang(DE){color:red}

csso ✗

:lang(DE){color:red}

esbuild ✗

:lang(DE){color:red}

lightningcss ✗

:lang(DE){color:red}

sass ✗

:lang(DE){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✗ ✗ ✓ ✗ ✗ ✗ ✓ ✗
Details

Remove quotes from :lang() while escaping wildcard

Language-codes used by :lang() can contain an asterisk as wild card character. Because this character also has semantic significance in CSS, it must either be quoted, or escaped. In this case, escaping requires fewer characters.

:lang("*-latn") {
  color: red;
}

Expected

:lang(\*-latn){color:red}

Outputs

clean-css ✗

:lang("*-latn"){color:red}

csskit ✗

:lang("*-latn"){color:red}

csslop ✓

:lang(\*-latn){color:red}

cssnano ✗

:lang("*-latn"){color:red}

csso ✗

esbuild ✗

:lang("*-latn"){color:red}

lightningcss ✓

:lang(\*-latn){color:red}

sass ✗

:lang("*-latn"){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Add quotes to :lang() when shorter than escaping

Language-codes used by :lang() can contain an asterisk as wild card character. Because this character also has semantic significance in CSS, it must either be quoted, or escaped. In cases where you are escaping more than twice, it is shorter to wrap the language-code in quotes.

:lang(\*-\*-\*,fr) {
  color: red;
}

Expected

:lang("*-*-*",fr){color:red}

Outputs

clean-css ✗

:lang(\*-\*-\*,fr){color:red}

csskit ✗

:lang(\*-\*-\*,fr){color:red}

csslop ✓

:lang("*-*-*",fr){color:red}

cssnano ✗

:lang(\*-\*-\*,fr){color:red}

csso ✗

esbuild ✗

:lang(\*-\*-\*,fr){color:red}

lightningcss ✗

:lang(\*-\*-\*,fr){color:red}

sass ✗

:lang(\*-\*-\*,fr){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Combine selectors that only differ in language-code in :lang()

If a rule has selectors that are identical except for the language-code used in :lang(), they can be combined.

:lang(tr) .foo em,
:lang(zh-hant) .foo em {
  color: red;
}

Expected

:lang(tr,zh-hant) .foo em{color:red}

Outputs

clean-css ✗

:lang(tr) .foo em,:lang(zh-hant) .foo em{color:red}

csskit ✗

:lang(tr) .foo em,:lang(zh-hant) .foo em{color:red}

csslop ✓

:lang(tr,zh-hant) .foo em{color:red}

cssnano ✗

:lang(tr) .foo em,:lang(zh-hant) .foo em{color:red}

csso ✗

:lang(tr) .foo em,:lang(zh-hant) .foo em{color:red}

esbuild ✗

:lang(tr) .foo em,:lang(zh-hant) .foo em{color:red}

lightningcss ✗

:lang(tr) .foo em,:lang(zh-hant) .foo em{color:red}

sass ✗

:lang(tr) .foo em,:lang(zh-hant) .foo em{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0007 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Combine rules that only differ in language-code in :lang()

If two rules are identical except for the language-code used in :lang(), they can be combined, with the language-codes comma-separated inside the :lang() function.

:lang(ar) .foo em {
  color: red;
}
:lang(ru) .foo em {
  color: red;
}

Expected

:lang(ar,ru) .foo em{color:red}

Outputs

clean-css ✗

:lang(ar) .foo em,:lang(ru) .foo em{color:red}

csskit ✗

:lang(ar) .foo em{color:red}:lang(ru) .foo em{color:red}

csslop ✓

:lang(ar,ru) .foo em{color:red}

cssnano ✗

:lang(ar) .foo em,:lang(ru) .foo em{color:red}

csso ✗

:lang(ar) .foo em,:lang(ru) .foo em{color:red}

esbuild ✗

:lang(ar) .foo em{color:red}:lang(ru) .foo em{color:red}

lightningcss ✗

:lang(ar) .foo em,:lang(ru) .foo em{color:red}

sass ✗

:lang(ar) .foo em{color:red}:lang(ru) .foo em{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0008 ✗ ✗ ✓ ✗ ✓ ✗ ✓ ✗
Details

Discard rules where the :lang selector contains an unespaced space

If a value in the :lang() psuedo-class contains an unescaped space that is not in quotes, then it is an invalid locale and the entire rule will be ignored by the browser (unless wrapped in a :is()). In this example, merging the two rules would result in both being ignored. Since the second rule is invalid and ignored by browsers it is safe to remove it.

:lang(de) {
  color: red;
}
:lang(en fr) {
  color: red;
}

Expected

:lang(de){color:red}

Outputs

clean-css ✗

:lang(de),:lang(enfr){color:red}

csskit ✗

:lang(de){color:red}:lang(en fr){color:red}

csslop ✓

:lang(de){color:red}

cssnano ✗

:lang(de){color:red}:lang(en fr){color:red}

csso ✓

:lang(de){color:red}

esbuild ✗

:lang(de){color:red}:lang(en fr){color:red}

lightningcss ✓

:lang(de){color:red}

sass ✗

:lang(de){color:red}:lang(en fr){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 0 / 8 0 / 8 8 / 8 1 / 8 1 / 8 0 / 8 3 / 8 0 / 8
Percent 0% 0% 100% 12.5% 12.5% 0% 37.5% 0%
Duration 1ms 1ms 1ms 7ms 1ms 4ms 1ms 3ms

layer #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✗ ✗ ✓ ✗ ✗ ✗ ✓ ✗
Details

Duplicate @layer statement removal

Duplicate @layer declarations can be deduplicated since layer order is established by first occurrence.

@layer utilities;
@layer utilities;
a {
  color: red;
}

Expected

@layer utilities;a{color:red}

Outputs

clean-css ✗

@layer utilities;@layer utilities;a{color:red}

csskit ✗

@layer utilities;@layer utilities;a{color:red}

csslop ✓

@layer utilities;a{color:red}

cssnano ✗

@layer utilities;@layer utilities;a{color:red}

csso ✗

@layer utilities;@layer utilities;a{color:red}

esbuild ✗

@layer utilities;@layer utilities;a{color:red}

lightningcss ✓

@layer utilities;a{color:red}

sass ✗

@layer utilities;@layer utilities;a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✓ ✗ ✓ ✗ ✗ ✗ ✓ ✗
Details

Non-adjacent @layer blocks can merge

Layer ordering is determined by first appearance of the layer name, not by physical position of rule blocks. Two @layer base blocks separated by @layer utilities can be merged because layer precedence is unchanged.

@layer base {
  a {
    color: blue;
  }
}

@layer utilities {
  a {
    color: red;
  }
}

@layer base {
  a {
    font-weight: bold;
  }
}

Expected

@layer base{a{color:#00f;font-weight:700}}@layer utilities{a{color:red}}

Outputs

clean-css ✓

@layer base{a{color:#00f;font-weight:700}}@layer utilities{a{color:red}}

csskit ✗

@layer base{a{color:blue}}@layer utilities{a{color:red}}@layer base{a{font-weight:bold}}

csslop ✓

@layer base{a{color:#00f;font-weight:700}}@layer utilities{a{color:red}}

cssnano ✗

@layer base{a{color:blue}}@layer utilities{a{color:red}}@layer base{a{font-weight:700}}

csso ✗

@layer base{a{color:#00f}}@layer utilities{a{color:red}}@layer base{a{font-weight:700}}

esbuild ✗

@layer base{a{color:#00f}}@layer utilities{a{color:red}}@layer base{a{font-weight:700}}

lightningcss ✓

@layer base{a{color:#00f;font-weight:700}}@layer utilities{a{color:red}}

sass ✗

@layer base{a{color:blue}}@layer utilities{a{color:red}}@layer base{a{font-weight:bold}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✗ ✓ ✓ ✗ ✓ ✓ ✓ ✗
Details

Remove whitespace in comma-separated layer names

Spaces and returns between named cascade layers are optional.

@layer reset, base,
       components;
a{color:red}

Expected

@layer reset,base,components;a{color:red}

Outputs

clean-css ✗

csskit ✓

@layer reset,base,components;a{color:red}

csslop ✓

@layer reset,base,components;a{color:red}

cssnano ✗

@layer reset, base,
       components;a{color:red}

csso ✓

@layer reset,base,components;a{color:red}

esbuild ✓

@layer reset,base,components;a{color:red}

lightningcss ✓

@layer reset,base,components;a{color:red}

sass ✗

@layer reset, base,
       components;a{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✓
Details

Remove @layer trailing semi-colon

If there is no other CSS after a @layer declaration, then the semi-colon is not separating it from anything and can be removed.

@layer reset,base;

Expected

@layer reset,base

Outputs

clean-css ✗

csskit ✗

@layer reset,base;

csslop ✓

@layer reset,base

cssnano ✗

@layer reset,base;

csso ✗

@layer reset,base;

esbuild ✗

@layer reset,base;

lightningcss ✗

@layer reset,base;

sass ✓

@layer reset,base
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 1 / 4 1 / 4 4 / 4 0 / 4 1 / 4 1 / 4 3 / 4 1 / 4
Percent 25% 25% 100% 0% 25% 25% 75% 25%
Duration 1ms 1ms 1ms 4ms 1ms 2ms 1ms 2ms

media #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

@media whitespace removal

Strip whitespace inside a basic @media block with nested rules.

@media screen {
  a {
    color: red;
  }
}

Expected

@media screen{a{color:red}}

Outputs

clean-css ✓

@media screen{a{color:red}}

csskit ✓

@media screen{a{color:red}}

csslop ✓

@media screen{a{color:red}}

cssnano ✓

@media screen{a{color:red}}

csso ✓

@media screen{a{color:red}}

esbuild ✓

@media screen{a{color:red}}

lightningcss ✓

@media screen{a{color:red}}

sass ✓

@media screen{a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Merge nested @media into one query

A @media nested directly inside another only applies when both match, so the two can be joined with and. screen and (width>=768px) is shorter than keeping the inner @media block. Rule order is unchanged, so the cascade is unaffected.

@media screen {
  @media (width >= 768px) {
    a {
      color: red;
    }
  }
}

Expected

@media screen and (width>=768px){a{color:red}}

Outputs

clean-css ✗

@media screen{@media (width >= 768px){a{color:red}}}

csskit ✗

@media screen{@media(width>=768px){a{color:red}}}

csslop ✓

@media screen and (width>=768px){a{color:red}}

cssnano ✗

@media screen{@media(width>=768px){a{color:red}}}

csso ✗

esbuild ✗

@media screen{@media(width>=768px){a{color:red}}}

lightningcss ✗

@media screen{@media (width>=768px){a{color:red}}}

sass ✗

@media screen and (width >= 768px){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Remove redundant all and in @media

@media all and (condition) is equivalent to @media (condition).

@media all and (width >= 500px) {
  a {
    color: red;
  }
}

Expected

@media(width>=500px){a{color:red}}

Outputs

clean-css ✗

@media all and (width >= 500px){a{color:red}}

csskit ✗

@media all and (width>=500px){a{color:red}}

csslop ✓

@media(width>=500px){a{color:red}}

cssnano ✓

@media(width>=500px){a{color:red}}

csso ✗

esbuild ✗

@media all and (width>=500px){a{color:red}}

lightningcss ✗

@media (width>=500px){a{color:red}}

sass ✗

@media all and (width >= 500px){a{color:red}}
1ms
3ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✗ ✗ ✓ ✓ ✗ ✗ ✓ ✗
Details

Adjacent identical @media merge

Adjacent @media blocks with the same query should be merged into one.

@media screen and (width >= 768px) {
  a {
    color: red;
  }
}
@media screen and (width >= 768px) {
  b {
    margin: 0;
  }
}

Expected

@media screen and (width>=768px){a{color:red}b{margin:0}}

Outputs

clean-css ✗

@media screen and (width >= 768px){a{color:red}b{margin:0}}

csskit ✗

@media screen and (width>=768px){a{color:red}}@media screen and (width>=768px){b{margin:0}}

csslop ✓

@media screen and (width>=768px){a{color:red}b{margin:0}}

cssnano ✓

@media screen and (width>=768px){a{color:red}b{margin:0}}

csso ✗

esbuild ✗

@media screen and (width>=768px){a{color:red}}@media screen and (width>=768px){b{margin:0}}

lightningcss ✓

@media screen and (width>=768px){a{color:red}b{margin:0}}

sass ✗

@media screen and (width >= 768px){a{color:red}}@media screen and (width >= 768px){b{margin:0}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Convert min-width to range syntax

(min-width: 768px) can be shortened to (width>=768px) using Media Queries Level 4 range syntax. Do not minify to width>767px as this is not technically accurate, because fractional units, like 767.5px are valid in CSS and would be included with >767px, but would not be included with >=768px.

@media (min-width: 768px) {
  a {
    color: red;
  }
}

Expected

@media(width>=768px){a{color:red}}

Outputs

clean-css ✗

@media (min-width:768px){a{color:red}}

csskit ✗

@media(min-width:768px){a{color:red}}

csslop ✓

@media(width>=768px){a{color:red}}

cssnano ✗

@media(min-width:768px){a{color:red}}

csso ✗

@media (min-width:768px){a{color:red}}

esbuild ✗

@media(min-width:768px){a{color:red}}

lightningcss ✗

@media (width>=768px){a{color:red}}

sass ✗

@media(min-width: 768px){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Convert max-width to range syntax

(max-width: 1024px) can be shortened to (width<=1024px) using Media Queries Level 4 range syntax. Do not minify to width<1025px as this is not technically accurate, because fractional units, like 1024.5px are valid in CSS.

@media (max-width: 1024px) {
  a {
    color: red;
  }
}

Expected

@media(width<=1024px){a{color:red}}

Outputs

clean-css ✗

@media (max-width:1024px){a{color:red}}

csskit ✗

@media(max-width:1024px){a{color:red}}

csslop ✓

@media(width<=1024px){a{color:red}}

cssnano ✗

@media(max-width:1024px){a{color:red}}

csso ✗

@media (max-width:1024px){a{color:red}}

esbuild ✗

@media(max-width:1024px){a{color:red}}

lightningcss ✗

@media (width<=1024px){a{color:red}}

sass ✗

@media(max-width: 1024px){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0007 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Convert min-height to range syntax

(min-height: 600px) can be shortened to (height>=600px) using Media Queries Level 4 range syntax. Do not minify to height>599px as this is not technically accurate, because fractional units, like 599.5px are valid in CSS and would be included with <599px, but would not be included with <=600px.

@media (min-height: 600px) {
  a {
    color: red;
  }
}

Expected

@media(height>=600px){a{color:red}}

Outputs

clean-css ✗

@media (min-height:600px){a{color:red}}

csskit ✗

@media(min-height:600px){a{color:red}}

csslop ✓

@media(height>=600px){a{color:red}}

cssnano ✗

@media(min-height:600px){a{color:red}}

csso ✗

@media (min-height:600px){a{color:red}}

esbuild ✗

@media(min-height:600px){a{color:red}}

lightningcss ✗

@media (height>=600px){a{color:red}}

sass ✗

@media(min-height: 600px){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0008 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Convert max-height to range syntax

(max-height: 900px) can be shortened to (height<=900px) using Media Queries Level 4 range syntax. Do not minify to height<899px as this is not technically accurate, because fractional units, like 899.5px are valid in CSS and would be included with <899px, but would not be included with <=900px.

@media (max-height: 900px) {
  a {
    color: red;
  }
}

Expected

@media(height<=900px){a{color:red}}

Outputs

clean-css ✗

@media (max-height:900px){a{color:red}}

csskit ✗

@media(max-height:900px){a{color:red}}

csslop ✓

@media(height<=900px){a{color:red}}

cssnano ✗

@media(max-height:900px){a{color:red}}

csso ✗

@media (max-height:900px){a{color:red}}

esbuild ✗

@media(max-height:900px){a{color:red}}

lightningcss ✗

@media (height<=900px){a{color:red}}

sass ✗

@media(max-height: 900px){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0009 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Combined min-width/max-width to range syntax

(min-width: 768px) and (max-width: 1024px) can be collapsed into a single range condition (768px<=width<=1024px), eliminating the and keyword and one pair of parentheses. Do not minify to 767px<width<1025px as this is not technically accurate, because fractional units, like 767.5px are valid in CSS.

@media (min-width: 768px) and (max-width: 1024px) {
  a {
    color: red;
  }
}

Expected

@media(768px<=width<=1024px){a{color:red}}

Outputs

clean-css ✗

@media (min-width:768px) and (max-width:1024px){a{color:red}}

csskit ✗

@media(min-width:768px)and (max-width:1024px){a{color:red}}

csslop ✓

@media(768px<=width<=1024px){a{color:red}}

cssnano ✗

@media(min-width:768px) and (max-width:1024px){a{color:red}}

csso ✗

@media (min-width:768px) and (max-width:1024px){a{color:red}}

esbuild ✗

@media(min-width:768px)and (max-width:1024px){a{color:red}}

lightningcss ✗

@media (width>=768px) and (width<=1024px){a{color:red}}

sass ✗

@media(min-width: 768px)and (max-width: 1024px){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0010 ✗ ✓ ✓ ✗ ✗ ✓ ✗ ✗
Details

Retain @custom-media

The @custom-media feature allows for abstracting and reusing media query conditions. It should be retained with optional whitespace removed.

@custom-media --modern (color), (hover);
@media (--modern) {
  a {
    color: red;
  }
}

Expected

@custom-media --modern (color),(hover);@media(--modern){a{color:red}}

Outputs

clean-css ✗

csskit ✓

@custom-media --modern (color),(hover);@media(--modern){a{color:red}}

csslop ✓

@custom-media --modern (color),(hover);@media(--modern){a{color:red}}

cssnano ✗

@custom-media --modern (color), (hover);@media(--modern){a{color:red}}

csso ✗

@custom-media --modern (color),(hover);@media (--modern){a{color:red}}

esbuild ✓

@custom-media --modern (color),(hover);@media(--modern){a{color:red}}

lightningcss ✗

@custom-media --modern (color), (hover);@media (--modern){a{color:red}}

sass ✗

@custom-media --modern (color), (hover);@media(--modern){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0011 ✗ ✓ ✓ ✓ ✗ ✓ ✗ ✗
Details

Remove space after @media before parens in media query

If the first condition in a media query is wrapped in parenthesis, then a space following @media is not required.

@media (orientation: landscape) {
  a {
    color: red;
  }
}

Expected

@media(orientation:landscape){a{color:red}}

Outputs

clean-css ✗

@media (orientation:landscape){a{color:red}}

csskit ✓

@media(orientation:landscape){a{color:red}}

csslop ✓

@media(orientation:landscape){a{color:red}}

cssnano ✓

@media(orientation:landscape){a{color:red}}

csso ✗

@media (orientation:landscape){a{color:red}}

esbuild ✓

@media(orientation:landscape){a{color:red}}

lightningcss ✗

@media (orientation:landscape){a{color:red}}

sass ✗

@media(orientation: landscape){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0012 ✗ ✓ ✓ ✗ ✗ ✓ ✗ ✗
Details

Remove space after parens before and in media query

If a media query contains an and following a condition wrapped in parenthesis, there is no need to include a space to separate them. It does however require a space after the and.

@media(width>30em) and (orientation: landscape) {
  a {
    color: red;
  }
}

Expected

@media(width>30em)and (orientation:landscape){a{color:red}}

Outputs

clean-css ✗

@media(width>30em) and (orientation:landscape){a{color:red}}

csskit ✓

@media(width>30em)and (orientation:landscape){a{color:red}}

csslop ✓

@media(width>30em)and (orientation:landscape){a{color:red}}

cssnano ✗

@media(width>30em) and (orientation:landscape){a{color:red}}

csso ✗

esbuild ✓

@media(width>30em)and (orientation:landscape){a{color:red}}

lightningcss ✗

@media (width>30em) and (orientation:landscape){a{color:red}}

sass ✗

@media(width > 30em)and (orientation: landscape){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0013 ✗ ✗ ✓ ✓ ✗ ✓ ✗ ✗
Details

Merge identical media queries with differing whitespace

This tests validates that minifiers do not treat media queries differently when there is, or is not, a space following @media before the start of the conditions parenthesis (().

@media (prefers-color-scheme: dark) {
  a {
    color: red;
  }
}
@media(prefers-color-scheme: dark) {
  a {
    color: red;
  }
}

Expected

@media(prefers-color-scheme:dark){a{color:red}}

Outputs

clean-css ✗

@media (prefers-color-scheme:dark){a{color:red}}@media(prefers-color-scheme:dark){a{color:red}}

csskit ✗

@media(prefers-color-scheme:dark){a{color:red}}@media(prefers-color-scheme:dark){a{color:red}}

csslop ✓

@media(prefers-color-scheme:dark){a{color:red}}

cssnano ✓

@media(prefers-color-scheme:dark){a{color:red}}

csso ✗

@media (prefers-color-scheme:dark){a{color:red}}

esbuild ✓

@media(prefers-color-scheme:dark){a{color:red}}

lightningcss ✗

@media (prefers-color-scheme:dark){a{color:red}}

sass ✗

@media(prefers-color-scheme: dark){a{color:red}}@media(prefers-color-scheme: dark){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0014 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Ratio numbers use scientific notation when shorter

<ratio> is made of <number>s, not <integer>s, so 1000000/1 in a media query is shorter as 1e6/1.

@media (min-aspect-ratio: 1000000/1) {
  a {
    color: red;
  }
}

Expected

@media(min-aspect-ratio:1e6/1){a{color:red}}

Outputs

clean-css ✗

@media (min-aspect-ratio:1000000/1){a{color:red}}

csskit ✗

@media(min-aspect-ratio:1000000/1){a{color:red}}

csslop ✓

@media(min-aspect-ratio:1e6/1){a{color:red}}

cssnano ✗

@media(min-aspect-ratio:1000000/1){a{color:red}}

csso ✗

@media (min-aspect-ratio:1000000/1){a{color:red}}

esbuild ✗

@media(min-aspect-ratio:1000000/1){a{color:red}}

lightningcss ✗

@media (aspect-ratio>=1000000){a{color:red}}

sass ✗

@media(min-aspect-ratio: 1000000/1){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0015 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Merge nested @media conditions with and

Two nested media conditions can be joined into a single condition with and. (width>=768px)and (hover:hover) is shorter than repeating @media and an extra pair of braces.

@media (width >= 768px) {
  @media (hover: hover) {
    a {
      color: red;
    }
  }
}

Expected

@media(width>=768px)and (hover:hover){a{color:red}}

Outputs

clean-css ✗

@media (width >= 768px){@media (hover:hover){a{color:red}}}

csskit ✗

@media(width>=768px){@media(hover:hover){a{color:red}}}

csslop ✓

@media(width>=768px)and (hover:hover){a{color:red}}

cssnano ✗

@media(width>=768px){@media(hover:hover){a{color:red}}}

csso ✗

esbuild ✗

@media(width>=768px){@media(hover:hover){a{color:red}}}

lightningcss ✗

@media (width>=768px){@media (hover:hover){a{color:red}}}

sass ✗

@media(width >= 768px)and (hover: hover){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0016 ✗ ✓ ✓ ✓ ✗ ✓ ✗ ✗
Details

Do not merge nested @media into a not query

not negates the whole query, so not print and (width>=768px) means "not (print and wide)" and would also match narrow screens. A media type cannot be negated on its own inside a condition, so the nesting must be kept.

@media not print {
  @media (width >= 768px) {
    a {
      color: red;
    }
  }
}

Expected

@media not print{@media(width>=768px){a{color:red}}}

Also accepted

@media(width>=768px){@media not print{a{color:red}}}

Outputs

clean-css ✗

@media not print{@media (width >= 768px){a{color:red}}}

csskit ✓

@media not print{@media(width>=768px){a{color:red}}}

csslop ✓

@media not print{@media(width>=768px){a{color:red}}}

cssnano ✓

@media not print{@media(width>=768px){a{color:red}}}

csso ✗

esbuild ✓

@media not print{@media(width>=768px){a{color:red}}}

lightningcss ✗

@media not print{@media (width>=768px){a{color:red}}}

sass ✗

@media not print{@media(width >= 768px){a{color:red}}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0017 ✗ ✓ ✓ ✓ ✗ ✓ ✗ ✗
Details

Do not naively merge nested @media with a query list

screen and (hover:hover),(pointer:fine) is two queries, the second of which also matches print. The correct merge, screen and ((hover:hover)or (pointer:fine)), is one byte longer than keeping the nesting.

@media screen {
  @media (hover: hover), (pointer: fine) {
    a {
      color: red;
    }
  }
}

Expected

@media screen{@media(hover:hover),(pointer:fine){a{color:red}}}

Also accepted

@media(hover:hover),(pointer:fine){@media screen{a{color:red}}}

Outputs

clean-css ✗

@media screen{@media (hover:hover),(pointer:fine){a{color:red}}}

csskit ✓

@media screen{@media(hover:hover),(pointer:fine){a{color:red}}}

csslop ✓

@media screen{@media(hover:hover),(pointer:fine){a{color:red}}}

cssnano ✓

@media screen{@media(hover:hover),(pointer:fine){a{color:red}}}

csso ✗

@media screen{@media (hover:hover),(pointer:fine){a{color:red}}}

esbuild ✓

@media screen{@media(hover:hover),(pointer:fine){a{color:red}}}

lightningcss ✗

@media screen{@media (hover:hover),(pointer:fine){a{color:red}}}

sass ✗

@media screen and (hover: hover),screen and (pointer: fine){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0018 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Drop repeated media type when merging nested @media

The inner query already requires screen, so the outer @media screen adds nothing. Merging leaves a single screen and (width>=768px) query.

@media screen {
  @media screen and (width >= 768px) {
    a {
      color: red;
    }
  }
}

Expected

@media screen and (width>=768px){a{color:red}}

Outputs

clean-css ✗

@media screen{@media screen and (width >= 768px){a{color:red}}}

csskit ✗

@media screen{@media screen and (width>=768px){a{color:red}}}

csslop ✓

@media screen and (width>=768px){a{color:red}}

cssnano ✗

@media screen{@media screen and (width>=768px){a{color:red}}}

csso ✗

esbuild ✗

@media screen{@media screen and (width>=768px){a{color:red}}}

lightningcss ✗

@media screen{@media screen and (width>=768px){a{color:red}}}

sass ✗

@media screen and (width >= 768px){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0019 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✓
Details

Remove nested @media with mutually exclusive media types

A document has one media type at a time, so print nested inside screen can never match. The whole block is dead and can be removed.

@media screen {
  @media print {
    a {
      color: red;
    }
  }
}
b {
  color: red;
}

Expected

b{color:red}

Outputs

clean-css ✗

@media screen{@media print{a{color:red}}}b{color:red}

csskit ✗

@media screen{@media print{a{color:red}}}b{color:red}

csslop ✓

b{color:red}

cssnano ✗

@media screen{@media print{a{color:red}}}b{color:red}

csso ✗

@media screen{@media print{a{color:red}}}b{color:red}

esbuild ✗

@media screen{@media print{a{color:red}}}b{color:red}

lightningcss ✗

@media screen{@media print{a{color:red}}}b{color:red}

sass ✓

b{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0020 ✗ ✓ ✓ ✓ ✗ ✓ ✗ ✗
Details

Do not naively merge nested @media into an outer query list

screen,print and (width>=768px) is two queries, so the first would match narrow screens. A correct merge has to repeat the condition for each query (screen and (width>=768px),print and (width>=768px)), which is longer than keeping the nesting.

@media screen, print {
  @media (width >= 768px) {
    a {
      color: red;
    }
  }
}

Expected

@media screen,print{@media(width>=768px){a{color:red}}}

Also accepted

@media(width>=768px){@media screen,print{a{color:red}}}
@media print,screen{@media(width>=768px){a{color:red}}}

Outputs

clean-css ✗

@media screen,print{@media (width >= 768px){a{color:red}}}

csskit ✓

@media screen,print{@media(width>=768px){a{color:red}}}

csslop ✓

@media screen,print{@media(width>=768px){a{color:red}}}

cssnano ✓

@media print,screen{@media(width>=768px){a{color:red}}}

csso ✗

esbuild ✓

@media screen,print{@media(width>=768px){a{color:red}}}

lightningcss ✗

@media screen,print{@media (width>=768px){a{color:red}}}

sass ✗

@media screen and (width >= 768px),print and (width >= 768px){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0021 ✗ ✓ ✓ ✓ ✗ ✓ ✗ ✗
Details

Do not remove a sub-pixel @media range

(767px<width<768px) looks empty but is not: viewport widths can be fractional. Firefox at a device pixel ratio of 2 gives a 767.5px wide frame, which matches. The block must be kept, not removed as dead code.

@media (767px < width < 768px) {
  a {
    color: red;
  }
}

Expected

@media(767px<width<768px){a{color:red}}

Outputs

clean-css ✗

@media (767px < width < 768px){a{color:red}}

csskit ✓

@media(767px<width<768px){a{color:red}}

csslop ✓

@media(767px<width<768px){a{color:red}}

cssnano ✓

@media(767px<width<768px){a{color:red}}

csso ✗

esbuild ✓

@media(767px<width<768px){a{color:red}}

lightningcss ✗

@media (767px<width<768px){a{color:red}}

sass ✗

@media(767px < width < 768px){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0022 ✗ ✓ ✓ ✓ ✗ ✓ ✗ ✗
Details

Do not remove a mixed-unit @media range

em in a media query is relative to the user's initial font size, not a fixed 16px. With the default it is 640px<=width<=600px and never matches, but a user font size of 12px makes it 480px<=width<=600px. The block must be kept.

@media (40em <= width <= 600px) {
  a {
    color: red;
  }
}

Expected

@media(40em<=width<=600px){a{color:red}}

Outputs

clean-css ✗

@media (40em <= width <= 600px){a{color:red}}

csskit ✓

@media(40em<=width<=600px){a{color:red}}

csslop ✓

@media(40em<=width<=600px){a{color:red}}

cssnano ✓

@media(40em<=width<=600px){a{color:red}}

csso ✗

esbuild ✓

@media(40em<=width<=600px){a{color:red}}

lightningcss ✗

@media (40em<=width<=600px){a{color:red}}

sass ✗

@media(40em <= width <= 600px){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 1 / 22 9 / 22 22 / 22 10 / 22 1 / 22 10 / 22 2 / 22 2 / 22
Percent 4.54% 40.9% 100% 45.45% 4.54% 45.45% 9.09% 9.09%
Duration 1ms 5ms 3ms 17ms 2ms 10ms 1ms 11ms

merging #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✓ ✗ ✓ ✓ ✓ ✗ ✓ ✗
Details

Merge adjacent rules with same selector

Adjacent rules sharing the same selector can be merged into one rule with combined declarations.

a {
  color: red;
}
a {
  font-size: 16px;
}

Expected

a{color:red;font-size:16px}

Outputs

clean-css ✓

a{color:red;font-size:16px}

csskit ✗

a{color:red}a{font-size:16px}

csslop ✓

a{color:red;font-size:16px}

cssnano ✓

a{color:red;font-size:16px}

csso ✓

a{color:red;font-size:16px}

esbuild ✗

a{color:red}a{font-size:16px}

lightningcss ✓

a{color:red;font-size:16px}

sass ✗

a{color:red}a{font-size:16px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✓ ✗ ✓ ✓ ✓ ✓ ✓ ✗
Details

Merge adjacent rules with same declarations

Adjacent rules with identical declarations can merge their selectors into a comma-separated list.

.a {
  color: red;
}
.b {
  color: red;
}

Expected

.a,.b{color:red}

Outputs

clean-css ✓

.a,.b{color:red}

csskit ✗

.a{color:red}.b{color:red}

csslop ✓

.a,.b{color:red}

cssnano ✓

.a,.b{color:red}

csso ✓

.a,.b{color:red}

esbuild ✓

.a,.b{color:red}

lightningcss ✓

.a,.b{color:red}

sass ✗

.a{color:red}.b{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✓ ✗ ✓ ✓ ✓ ✗ ✓ ✗
Details

Merge adjacent @media with same query

Adjacent @media rules with the same query can be merged into a single @media block.

@media screen {
  a {
    color: red;
  }
}
@media screen {
  b {
    margin: 0;
  }
}

Expected

@media screen{a{color:red}b{margin:0}}

Outputs

clean-css ✓

@media screen{a{color:red}b{margin:0}}

csskit ✗

@media screen{a{color:red}}@media screen{b{margin:0}}

csslop ✓

@media screen{a{color:red}b{margin:0}}

cssnano ✓

@media screen{a{color:red}b{margin:0}}

csso ✓

@media screen{a{color:red}b{margin:0}}

esbuild ✗

@media screen{a{color:red}}@media screen{b{margin:0}}

lightningcss ✓

@media screen{a{color:red}b{margin:0}}

sass ✗

@media screen{a{color:red}}@media screen{b{margin:0}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✓ ✗ ✓ ✓ ✓ ✗ ✗ ✗
Details

Merge rules with identical selectors separated by non-overlapping rules

Adjacent rules with identical selectors can always be merged. However, if there are other rules between them, they can only be merged if the separating rules have no property declarations that could potentially override the values in the first rule in the merge, or if the selector is of a lower specificity.

In this example <p class="x"> should have background:#0ff;color:#0f0.

.x {
  color: #0f0;
}
p {
  color: #00f;
}
#foo {
  padding: 2px;
}
.x {
  background: #0ff;
}

Expected

p{color:#00f}#foo{padding:2px}.x{color:#0f0;background:#0ff}

Also accepted

.x{color:#0f0;background:#0ff}p{color:#00f}#foo{padding:2px}
p{color:#00f}#foo{padding:2px}.x{background:#0ff;color:#0f0}
.x{background:#0ff;color:#0f0}p{color:#00f}#foo{padding:2px}

Outputs

clean-css ✓

.x{color:#0f0;background:#0ff}p{color:#00f}#foo{padding:2px}

csskit ✗

.x{color:#0f0}p{color:#00f}#foo{padding:2px}.x{background:#0ff}

csslop ✓

p{color:#00f}#foo{padding:2px}.x{color:#0f0;background:#0ff}

cssnano ✓

.x{color:#0f0;background:#0ff}p{color:#00f}#foo{padding:2px}

csso ✓

.x{color:#0f0;background:#0ff}p{color:#00f}#foo{padding:2px}

esbuild ✗

.x{color:#0f0}p{color:#00f}#foo{padding:2px}.x{background:#0ff}

lightningcss ✗

.x{color:#0f0}p{color:#00f}#foo{padding:2px}.x{background:#0ff}

sass ✗

.x{color:lime}p{color:blue}#foo{padding:2px}.x{background:aqua}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✗ ✗ ✓ ✓ ✓ ✗ ✗ ✗
Details

Partial merge of shared declarations

When adjacent rules share some declarations, the common part can be factored out.

a {
  color: red;
}
b {
  color: red;
  font-size: 16px;
}

Expected

a,b{color:red}b{font-size:16px}

Outputs

clean-css ✗

a{color:red}b{color:red;font-size:16px}

csskit ✗

a{color:red}b{color:red;font-size:16px}

csslop ✓

a,b{color:red}b{font-size:16px}

cssnano ✓

a,b{color:red}b{font-size:16px}

csso ✓

a,b{color:red}b{font-size:16px}

esbuild ✗

a{color:red}b{color:red;font-size:16px}

lightningcss ✗

a{color:red}b{color:red;font-size:16px}

sass ✗

a{color:red}b{color:red;font-size:16px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✗ ✗ ✓ ✓ ✓ ✗ ✓ ✗
Details

Overridden @keyframes removal

When two @keyframes share the same name, only the last definition is kept.

@keyframes fade {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
@keyframes fade {
  0% {
    opacity: 0.5;
  }
  100% {
    opacity: 1;
  }
}

Expected

@keyframes fade{0%{opacity:.5}to{opacity:1}}

Outputs

clean-css ✗

@keyframes fade{0%{opacity:0;opacity:.5}100%{opacity:1}}

csskit ✗

@keyframes fade{0%{opacity:0}100%{opacity:1}}@keyframes fade{0%{opacity:.5}100%{opacity:1}}

csslop ✓

@keyframes fade{0%{opacity:.5}to{opacity:1}}

cssnano ✓

@keyframes fade{0%{opacity:.5}to{opacity:1}}

csso ✓

@keyframes fade{0%{opacity:.5}to{opacity:1}}

esbuild ✗

@keyframes fade{0%{opacity:0}to{opacity:1}}@keyframes fade{0%{opacity:.5}to{opacity:1}}

lightningcss ✓

@keyframes fade{0%{opacity:.5}to{opacity:1}}

sass ✗

@keyframes fade{0%{opacity:0}100%{opacity:1}}@keyframes fade{0%{opacity:.5}100%{opacity:1}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0007 ✓ ✓ ✓ ✓ ✗ ✓ ✓ ✓
Details

Merging rules is unsafe with the all property

Merging .foo{color:red} and .bar{all:unset;color:red} into .bar,.foo{color:red}.bar{all:unset} is unsafe because all:unset resets color, so the merged color declaration would be overridden.

.foo {
  color: red;
}

.bar {
  all: unset;
  color: red;
}

Expected

.foo{color:red}.bar{all:unset;color:red}

Validate

Outputs

clean-css ✓

.foo{color:red}.bar{all:unset;color:red}

csskit ✓

.foo{color:red}.bar{all:unset;color:red}

csslop ✓

.foo{color:red}.bar{all:unset;color:red}

cssnano ✓

.foo{color:red}.bar{all:unset;color:red}

csso ✗

.bar,.foo{color:red}.bar{all:unset}

esbuild ✓

.foo{color:red}.bar{all:unset;color:red}

lightningcss ✓

.foo{color:red}.bar{all:unset;color:red}

sass ✓

.foo{color:red}.bar{all:unset;color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0008 ✗ ✓ ✓ ✗ ✗ ✓ ✗ ✗
Details

Non-adjacent @media merge is unsafe due to cascade

Merging two identical @media (width >= 1px) blocks that have intervening rules between them changes the cascade order. The intervening a{color:green} must remain between the two @media blocks so it correctly overrides the first block's color:red.

@media (width >= 1px) {
  a {
    color: red;
  }
}

a {
  color: green;
}

@media (width >= 1px) {
  a {
    background: #0b0;
  }
}

Expected

@media(width>=1px){a{color:red}}a{color:green}@media(width>=1px){a{background:#0b0}}

Validate

Outputs

clean-css ✗

@media (width >= 1px){a{color:red;background:#0b0}}a{color:green}

csskit ✓

@media(width>=1px){a{color:red}}a{color:green}@media(width>=1px){a{background:#0b0}}

csslop ✓

@media(width>=1px){a{color:red}}a{color:green}@media(width>=1px){a{background:#0b0}}

cssnano ✗

@media(width>=1px){a{color:red;background:#0b0}}a{color:green}

csso ✗

a{color:green}

esbuild ✓

@media(width>=1px){a{color:red}}a{color:green}@media(width>=1px){a{background:#0b0}}

lightningcss ✗

@media (width>=1px){a{color:red}}a{color:green}@media (width>=1px){a{background:#0b0}}

sass ✗

@media(width >= 1px){a{color:red}}a{color:green}@media(width >= 1px){a{background:#0b0}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0009 ✓ ✓ ✓ ✓ ✗ ✓ ✓ ✓
Details

Merging rules is unsafe with all:initial

Merging .foo{color:red} and .bar{all:initial;color:red} into .bar,.foo{color:red}.bar{all:initial} is unsafe because all:initial resets color to its initial value, so the merged color declaration would be overridden.

.foo {
  color: red;
}

.bar {
  all: initial;
  color: red;
}

Expected

.foo{color:red}.bar{all:initial;color:red}

Validate

Outputs

clean-css ✓

.foo{color:red}.bar{all:initial;color:red}

csskit ✓

.foo{color:red}.bar{all:initial;color:red}

csslop ✓

.foo{color:red}.bar{all:initial;color:red}

cssnano ✓

.foo{color:red}.bar{all:initial;color:red}

csso ✗

.bar,.foo{color:red}.bar{all:initial}

esbuild ✓

.foo{color:red}.bar{all:initial;color:red}

lightningcss ✓

.foo{color:red}.bar{all:initial;color:red}

sass ✓

.foo{color:red}.bar{all:initial;color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0010 ✓ ✓ ✓ ✓ ✗ ✓ ✓ ✓
Details

Merging rules is unsafe with all:revert-layer

Merging .foo{color:red} and .bar{all:revert-layer;color:red} into .bar,.foo{color:red}.bar{all:revert-layer} is unsafe because all:revert-layer rolls back color to the previous cascade layer, so the merged color declaration would be overridden.

.foo {
  color: red;
}

.bar {
  all: revert-layer;
  color: red;
}

Expected

.foo{color:red}.bar{all:revert-layer;color:red}

Validate

Outputs

clean-css ✓

.foo{color:red}.bar{all:revert-layer;color:red}

csskit ✓

.foo{color:red}.bar{all:revert-layer;color:red}

csslop ✓

.foo{color:red}.bar{all:revert-layer;color:red}

cssnano ✓

.foo{color:red}.bar{all:revert-layer;color:red}

csso ✗

.bar,.foo{color:red}.bar{all:revert-layer}

esbuild ✓

.foo{color:red}.bar{all:revert-layer;color:red}

lightningcss ✓

.foo{color:red}.bar{all:revert-layer;color:red}

sass ✓

.foo{color:red}.bar{all:revert-layer;color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0011 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Merging rules is unsafe when custom idents differ

animation-name: pulse and animation-name: shake name different keyframes, so the rules cannot share a selector list. Minifiers need to check the actual value to ensure they don't merge different values.

a {
  animation-name: pulse;
}

b {
  animation-name: shake;
}

Expected

a{animation-name:pulse}b{animation-name:shake}

Outputs

clean-css ✓

a{animation-name:pulse}b{animation-name:shake}

csskit ✓

a{animation-name:pulse}b{animation-name:shake}

csslop ✓

a{animation-name:pulse}b{animation-name:shake}

cssnano ✓

a{animation-name:pulse}b{animation-name:shake}

csso ✓

a{animation-name:pulse}b{animation-name:shake}

esbuild ✓

a{animation-name:pulse}b{animation-name:shake}

lightningcss ✓

a{animation-name:pulse}b{animation-name:shake}

sass ✓

a{animation-name:pulse}b{animation-name:shake}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0012 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Merging rules is unsafe when strings differ

content: "i" and content: "j" insert different text, so the rules cannot share a selector list. A minifier needs to check the actual value and cannot merge these rules.

a {
  content: "i";
}

b {
  content: "j";
}

Expected

a{content:"i"}b{content:"j"}

Outputs

clean-css ✓

a{content:"i"}b{content:"j"}

csskit ✓

a{content:"i"}b{content:"j"}

csslop ✓

a{content:"i"}b{content:"j"}

cssnano ✓

a{content:"i"}b{content:"j"}

csso ✓

a{content:"i"}b{content:"j"}

esbuild ✓

a{content:"i"}b{content:"j"}

lightningcss ✓

a{content:"i"}b{content:"j"}

sass ✓

a{content:"i"}b{content:"j"}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0013 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✗
Details

Merging rules is unsafe when function arguments differ

scale(2,3) and scale(3,2) scale the two axes by swapped factors, so the rules cannot be merged. A minifier might compare the arguments regardless of order, and treat these two transforms as the same transform.

a {
  transform: scale(2, 3);
}

b {
  transform: scale(3, 2);
}

Expected

a{transform:scale(2,3)}b{transform:scale(3,2)}

Outputs

clean-css ✓

a{transform:scale(2,3)}b{transform:scale(3,2)}

csskit ✓

a{transform:scale(2,3)}b{transform:scale(3,2)}

csslop ✓

a{transform:scale(2,3)}b{transform:scale(3,2)}

cssnano ✓

a{transform:scale(2,3)}b{transform:scale(3,2)}

csso ✓

a{transform:scale(2,3)}b{transform:scale(3,2)}

esbuild ✓

a{transform:scale(2,3)}b{transform:scale(3,2)}

lightningcss ✓

a{transform:scale(2,3)}b{transform:scale(3,2)}

sass ✗

a{transform:scale(2, 3)}b{transform:scale(3, 2)}
1ms
3ms
1ms
1ms
1ms
1ms
1ms
1ms
0014 ✓ ✓ ✓ ✓ ✓ ✗ ✗ ✓
Details

Merging rules is unsafe when the value after a slash differs

The mask shorthand takes the mask size after a slash, so center/cover and center/contain scale the mask differently and the rules cannot be merged.

a {
  mask: center / cover;
}

b {
  mask: center / contain;
}

Expected

a{mask:center/cover}b{mask:center/contain}

Outputs

clean-css ✓

a{mask:center/cover}b{mask:center/contain}

csskit ✓

a{mask:center/cover}b{mask:center/contain}

csslop ✓

a{mask:center/cover}b{mask:center/contain}

cssnano ✓

a{mask:center/cover}b{mask:center/contain}

csso ✓

a{mask:center/cover}b{mask:center/contain}

esbuild ✗

a{mask:center / cover}b{mask:center / contain}

lightningcss ✗

a{mask:none 50%/cover}b{mask:none 50%/contain}

sass ✓

a{mask:center/cover}b{mask:center/contain}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0015 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✗
Details

Do not merge rules with identical selectors separated by overlapping rules

Adjacent rules with identical selectors can always be merged. However, if there are other rules between them, they can only be merged if the separating rules have no property declarations that could potentially override the values in the first rule in the merge, or if the selector is of a lower specificity.

In this example <div class="x y"> should get background:#0ff;color:#00f.

.x {
  color: #0f0;
}
.y {
  background: #0f0;
  color: #00f;
}
#foo {
  padding: 2px;
}
.x {
  background: #0ff;
}

Expected

.x{color:#0f0}.y{background:#0f0;color:#00f}#foo{padding:2px}.x{background:#0ff}

Also accepted

.x{color:#0f0}.y{color:#00f;background:#0f0}#foo{padding:2px}.x{background:#0ff}

Outputs

clean-css ✓

.x{color:#0f0}.y{background:#0f0;color:#00f}#foo{padding:2px}.x{background:#0ff}

csskit ✓

.x{color:#0f0}.y{background:#0f0;color:#00f}#foo{padding:2px}.x{background:#0ff}

csslop ✓

.x{color:#0f0}.y{background:#0f0;color:#00f}#foo{padding:2px}.x{background:#0ff}

cssnano ✓

.x{color:#0f0}.y{background:#0f0;color:#00f}#foo{padding:2px}.x{background:#0ff}

csso ✓

.x{color:#0f0}.y{background:#0f0;color:#00f}#foo{padding:2px}.x{background:#0ff}

esbuild ✓

.x{color:#0f0}.y{background:#0f0;color:#00f}#foo{padding:2px}.x{background:#0ff}

lightningcss ✓

.x{color:#0f0}.y{color:#00f;background:#0f0}#foo{padding:2px}.x{background:#0ff}

sass ✗

.x{color:lime}.y{background:lime;color:blue}#foo{padding:2px}.x{background:aqua}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0016 ✗ ✓ ✓ ✓ ✗ ✓ ✓ ✗
Details

Do not merge rules with identical selectors separated by overlapping rules

Adjacent rules with identical selectors can always be merged. However, if there are other rules between them, they can only be merged if the separating rules have no property declarations that could potentially override the values in the first rule in the merge, or if the selector is of a lower specificity.

In this example <div class="x"> should get background:#0ff;color:#00f, because :where(.x) is a selector with 0 0 0 specificty, where as div has a higher specificity of 0 0 1.

:where(.x) {
  color: #0f0;
}
div {
  background: #0f0;
  color: #00f;
}
#foo {
  padding: 2px;
}
:where(.x) {
  background: #0ff;
}

Expected

:where(.x){color:#0f0}div{background:#0f0;color:#00f}#foo{padding:2px}:where(.x){background:#0ff}

Also accepted

:where(.x){color:#0f0}div{color:#00f;background:#0f0}#foo{padding:2px}:where(.x){background:#0ff}

Outputs

clean-css ✗

:where(.x){color:#0f0;background:#0ff}div{background:#0f0;color:#00f}#foo{padding:2px}

csskit ✓

:where(.x){color:#0f0}div{background:#0f0;color:#00f}#foo{padding:2px}:where(.x){background:#0ff}

csslop ✓

:where(.x){color:#0f0}div{background:#0f0;color:#00f}#foo{padding:2px}:where(.x){background:#0ff}

cssnano ✓

:where(.x){color:#0f0}div{background:#0f0;color:#00f}#foo{padding:2px}:where(.x){background:#0ff}

csso ✗

:where(.x){color:#0f0;background:#0ff}div{background:#0f0;color:#00f}#foo{padding:2px}

esbuild ✓

:where(.x){color:#0f0}div{background:#0f0;color:#00f}#foo{padding:2px}:where(.x){background:#0ff}

lightningcss ✓

:where(.x){color:#0f0}div{color:#00f;background:#0f0}#foo{padding:2px}:where(.x){background:#0ff}

sass ✗

:where(.x){color:lime}div{background:lime;color:blue}#foo{padding:2px}:where(.x){background:aqua}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0017 ✓ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Merge rules with identical selectors separated by rules that get overridden

Adjacent rules with identical selectors can always be merged. However, if there are other rules between them, they can only be merged if the separating rules have no property declarations that could potentially override the values in the first rule in the merge, or if the selector is of a lower specificity.

If the separating rules could potentially override the first rule, but the last rule to merge has no conflicts, it can be merged into the first rule. This preserves any potential property overrides, while still reducing total character count.

In this example <div class="x y"> should get background:#0ff;color:#00f, because .y overrides the color value in .x when applied to the same element.

.x {
  color: #0f0;
}
.y {
  color: #00f;
}
#foo {
  padding: 2px;
}
.x {
  background: #0ff;
}

Expected

.x{color:#0f0;background:#0ff}.y{color:#00f}#foo{padding:2px}

Also accepted

.x{background:#0ff;color:#0f0}.y{color:#00f}#foo{padding:2px}

Outputs

clean-css ✓

.x{color:#0f0;background:#0ff}.y{color:#00f}#foo{padding:2px}

csskit ✗

.x{color:#0f0}.y{color:#00f}#foo{padding:2px}.x{background:#0ff}

csslop ✓

.x{color:#0f0;background:#0ff}.y{color:#00f}#foo{padding:2px}

cssnano ✓

.x{color:#0f0;background:#0ff}.y{color:#00f}#foo{padding:2px}

csso ✗

.x{color:#0f0}.y{color:#00f}#foo{padding:2px}.x{background:#0ff}

esbuild ✗

.x{color:#0f0}.y{color:#00f}#foo{padding:2px}.x{background:#0ff}

lightningcss ✗

.x{color:#0f0}.y{color:#00f}#foo{padding:2px}.x{background:#0ff}

sass ✗

.x{color:lime}.y{color:blue}#foo{padding:2px}.x{background:aqua}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0018 ✓ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Merge rules with identical selectors separated by rules potentially overridden

Adjacent rules with identical selectors can always be merged. However, if there are other rules between them, they can only be merged if the separating rules have no property declarations that could potentially override the values in the first rule in the merge, or if the selector is of a lower specificity.

If the separating rules could potentially be overridden by the last rule, but do not potentially override anything in the first rule, then the first rule can be merged into the last rule. This preserves any potential property overrides, while still reducing total character count.

In this example <div class="x y"> should get background:#0ff;color:#0f0, because .x overrides the color value in .y when applied to the same element.

.x {
  background: #0ff;
}
.y {
  color: #00f;
}
#foo {
  padding: 2px;
}
.x {
  color: #0f0;
}

Expected

.y{color:#00f}#foo{padding:2px}.x{background:#0ff;color:#0f0}

Also accepted

.y{color:#00f}#foo{padding:2px}.x{color:#0f0;background:#0ff}

Outputs

clean-css ✓

.y{color:#00f}#foo{padding:2px}.x{background:#0ff;color:#0f0}

csskit ✗

.x{background:#0ff}.y{color:#00f}#foo{padding:2px}.x{color:#0f0}

csslop ✓

.y{color:#00f}#foo{padding:2px}.x{background:#0ff;color:#0f0}

cssnano ✓

.y{color:#00f}#foo{padding:2px}.x{background:#0ff;color:#0f0}

csso ✗

.x{background:#0ff}.y{color:#00f}#foo{padding:2px}.x{color:#0f0}

esbuild ✗

.x{background:#0ff}.y{color:#00f}#foo{padding:2px}.x{color:#0f0}

lightningcss ✗

.x{background:#0ff}.y{color:#00f}#foo{padding:2px}.x{color:#0f0}

sass ✗

.x{background:aqua}.y{color:blue}#foo{padding:2px}.x{color:lime}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0019 ✓ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Merge rules with identical selectors separated by non-overlapping rules

Adjacent rules with identical selectors can always be merged. However, if there are other rules between them, they can only be merged if the separating rules have no property declarations that could potentially override the values in the first rule in the merge, or if the selector is of a lower specificity.

.x {
  margin: 1px;
}
.y {
  color: red;
}
.x {
  padding: 1px;
}

Expected

.y{color:red}.x{margin:1px;padding:1px}

Also accepted

.y{color:red}.x{padding:1px;margin:1px}
.x{padding:1px;margin:1px}.y{color:red}
.x{margin:1px;padding:1px}.y{color:red}

Outputs

clean-css ✓

.x{margin:1px;padding:1px}.y{color:red}

csskit ✗

.x{margin:1px}.y{color:red}.x{padding:1px}

csslop ✓

.y{color:red}.x{margin:1px;padding:1px}

cssnano ✓

.x{margin:1px;padding:1px}.y{color:red}

csso ✗

.x{margin:1px}.y{color:red}.x{padding:1px}

esbuild ✗

.x{margin:1px}.y{color:red}.x{padding:1px}

lightningcss ✗

.x{margin:1px}.y{color:red}.x{padding:1px}

sass ✗

.x{margin:1px}.y{color:red}.x{padding:1px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0020 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Preserve distinct children when parent declarations overlap

When the similar rules overlap one another, merging them with a combinatory selector works only if they are an exact match. This test ensures minifiers do not exclude properties that are only in one rule.

.a {
  color: red;
}
.a .x {
  color: tan;
}
.b {
  color: red;
  padding: 1px;
}
.b .y {
  color: gold;
}

Expected

.a{color:red;.x{color:tan}}.b{color:red;padding:1px;.y{color:gold}}

Outputs

clean-css ✗

.a{color:red}.a .x{color:tan}.b{color:red;padding:1px}.b .y{color:gold}

csskit ✗

.a{color:red}.a .x{color:tan}.b{color:red;padding:1px}.b .y{color:gold}

csslop ✓

.a{color:red;.x{color:tan}}.b{color:red;padding:1px;.y{color:gold}}

cssnano ✗

.a{color:red}.a .x{color:tan}.b{color:red;padding:1px}.b .y{color:gold}

csso ✗

.a,.b{color:red}.a .x{color:tan}.b{padding:1px}.b .y{color:gold}

esbuild ✗

.a{color:red}.a .x{color:tan}.b{color:red;padding:1px}.b .y{color:gold}

lightningcss ✗

.a{color:red}.a .x{color:tan}.b{color:red;padding:1px}.b .y{color:gold}

sass ✗

.a{color:red}.a .x{color:tan}.b{color:red;padding:1px}.b .y{color:gold}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0021 ✗ ✗ ✓ ✗ ✓ ✗ ✗ ✗
Details

Merge matching rules with !important properties separated by another rule

If two rules use the same selectors, they can be merged. Even with another rule between them. In this case of a property has a higher specificity via !important. Since the separating rule also applies to the same property, but has a lower specificity, it does not matter if the .a class is merged above or below the separator.

.a {
  color: red !important;
}
.b {
  color: tan;
}
.a {
  color: tan;
}

Expected

.a{color:red!important}.b{color:tan}

Also accepted

.b{color:tan}.a{color:red!important}

Outputs

clean-css ✗

.a{color:red!important}.a,.b{color:tan}

csskit ✗

.a{color:red!important}.b{color:tan}.a{color:tan}

csslop ✓

.a{color:red!important}.b{color:tan}

cssnano ✗

.a{color:red!important}.a,.b{color:tan}

csso ✓

.a{color:red!important}.b{color:tan}

esbuild ✗

.a{color:red!important}.b,.a{color:tan}

lightningcss ✗

.a{color:red!important}.b,.a{color:tan}

sass ✗

.a{color:red !important}.b{color:tan}.a{color:tan}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0022 ✓ ✗ ✓ ✗ ✓ ✗ ✓ ✗
Details

Merge matching rules with !important properties separated by another rule

If two rules use the same selectors, they can be merged. Even with another rule between them. In this case both matching rules and the separating rule use the same property, but the later matching rule's property has a higher specificity via !important. If the an element has both a class of a and b applied, it will recieve tan whether .a is above or below it, so the placement of the merge can appear in either place.

.a {
  color: red;
}
.b {
  color: gold;
}
.a {
  color: tan !important;
}

Expected

.b{color:gold}.a{color:tan!important}

Outputs

clean-css ✓

.b{color:gold}.a{color:tan!important}

csskit ✗

.a{color:red}.b{color:gold}.a{color:tan!important}

csslop ✓

.b{color:gold}.a{color:tan!important}

cssnano ✗

.a{color:red}.b{color:gold}.a{color:tan!important}

csso ✓

.b{color:gold}.a{color:tan!important}

esbuild ✗

.a{color:red}.b{color:gold}.a{color:tan!important}

lightningcss ✓

.b{color:gold}.a{color:tan!important}

sass ✗

.a{color:red}.b{color:gold}.a{color:tan !important}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0023 ✓ ✗ ✓ ✗ ✓ ✗ ✓ ✗
Details

Merge matching rules with !important properties separated by another rule

If two rules use the same selectors, they can be merged. Even with another rule between them. In this case both matching rules and the separating rule use the same property, but he separating rule's property has a higher specificity via !important. If the an element has both a class of a and b applied, it will recieve gold whether .a is above or below it, so the placement of the merge can appear in either place.

.a {
  color: red;
}
.b {
  color: gold !important;
}
.a {
  color: tan;
}

Expected

.b{color:gold!important}.a{color:tan}

Also accepted

.a{color:tan}.b{color:gold!important}

Outputs

clean-css ✓

.b{color:gold!important}.a{color:tan}

csskit ✗

.a{color:red}.b{color:gold!important}.a{color:tan}

csslop ✓

.b{color:gold!important}.a{color:tan}

cssnano ✗

.a{color:red}.b{color:gold!important}.a{color:tan}

csso ✓

.b{color:gold!important}.a{color:tan}

esbuild ✗

.a{color:red}.b{color:gold!important}.a{color:tan}

lightningcss ✓

.b{color:gold!important}.a{color:tan}

sass ✗

.a{color:red}.b{color:gold !important}.a{color:tan}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0024 ✓ ✗ ✓ ✗ ✓ ✗ ✓ ✗
Details

Merge matching rules with !important properties separated by another rule

If two rules use the same selectors, they can be merged. Even with another rule between them. In this case both matching rules and the separating rule use the same property, and all use !important. If the an element has both a class of a and b applied, it will recieve tan. This requires the merged .a rule to occur after the .b rule.

.a {
  color: red !important;
}
.b {
  color: gold !important;
}
.a {
  color: tan !important;
}

Expected

.b{color:gold!important}.a{color:tan!important}

Outputs

clean-css ✓

.b{color:gold!important}.a{color:tan!important}

csskit ✗

.a{color:red!important}.b{color:gold!important}.a{color:tan!important}

csslop ✓

.b{color:gold!important}.a{color:tan!important}

cssnano ✗

.a{color:red!important}.b{color:gold!important}.a{color:tan!important}

csso ✓

.b{color:gold!important}.a{color:tan!important}

esbuild ✗

.a{color:red!important}.b{color:gold!important}.a{color:tan!important}

lightningcss ✓

.b{color:gold!important}.a{color:tan!important}

sass ✗

.a{color:red !important}.b{color:gold !important}.a{color:tan !important}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0025 ✓ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Merge 3 separate groups, keeping correct order

In this example, .x with color and margin can be merged, because there are no other rules between them with a margin that could potentially override .x if it's margin was moved up and merged with the first instance. After that the second .x can be removed leaving two .y and two .z. This process repeats with .y, then finally with .z.

.x { color: red; }
.y { color: tan; }
.z { color: gold; }
.x { margin: 1px; }
.y { margin: 2px; }
.z { margin: 3px; }

Expected

.x{color:red;margin:1px}.y{color:tan;margin:2px}.z{color:gold;margin:3px}

Also accepted

.x{margin:1px;color:red}.y{margin:2px;color:tan}.z{margin:3px;color:gold}

Outputs

clean-css ✓

.x{color:red;margin:1px}.y{color:tan;margin:2px}.z{color:gold;margin:3px}

csskit ✗

.x{color:red}.y{color:tan}.z{color:gold}.x{margin:1px}.y{margin:2px}.z{margin:3px}

csslop ✓

.x{color:red;margin:1px}.y{color:tan;margin:2px}.z{color:gold;margin:3px}

cssnano ✓

.x{color:red;margin:1px}.y{color:tan;margin:2px}.z{color:gold;margin:3px}

csso ✗

.x{color:red}.y{color:tan}.z{color:gold}.x{margin:1px}.y{margin:2px}.z{margin:3px}

esbuild ✗

.x{color:red}.y{color:tan}.z{color:gold}.x{margin:1px}.y{margin:2px}.z{margin:3px}

lightningcss ✗

.x{color:red}.y{color:tan}.z{color:gold}.x{margin:1px}.y{margin:2px}.z{margin:3px}

sass ✗

.x{color:red}.y{color:tan}.z{color:gold}.x{margin:1px}.y{margin:2px}.z{margin:3px}
1ms
3ms
1ms
1ms
1ms
1ms
1ms
1ms
0026 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Merge complexly overlapping separate groups, keeping correct order

In this example, .x has two rules, however moving the margin up could potentially break specificity if z and x applied to the same element. Similarly moving the color down is blocked by .y. However, you can safely move the .y color down to merge with margin. After doing this, .x is now free to move the color down to merge with margin in the later .x rule.

.x { color: red; }
.y { color: tan; }
.z { margin: 0; }
.x { margin: 1px; }
.y { margin: 2px; }

Expected

.z{margin:0}.x{color:red;margin:1px}.y{color:tan;margin:2px}

Also accepted

.z{margin:0}.x{margin:1px;color:red}.y{margin:2px;color:tan}

Outputs

clean-css ✗

.x{color:red}.z{margin:0}.x{margin:1px}.y{color:tan;margin:2px}

csskit ✗

.x{color:red}.y{color:tan}.z{margin:0}.x{margin:1px}.y{margin:2px}

csslop ✓

.z{margin:0}.x{color:red;margin:1px}.y{color:tan;margin:2px}

cssnano ✓

.z{margin:0}.x{color:red;margin:1px}.y{color:tan;margin:2px}

csso ✗

.x{color:red}.y{color:tan}.z{margin:0}.x{margin:1px}.y{margin:2px}

esbuild ✗

.x{color:red}.y{color:tan}.z{margin:0}.x{margin:1px}.y{margin:2px}

lightningcss ✗

.x{color:red}.y{color:tan}.z{margin:0}.x{margin:1px}.y{margin:2px}

sass ✗

.x{color:red}.y{color:tan}.z{margin:0}.x{margin:1px}.y{margin:2px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0027 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Renest rules after merging matching media queries

These two media queries match, so they can be merged. The rules in the queries can then be merged and have nesting applied.

@media (width < 700px) {
  .a .b {
    width: 100%
  }
}
@media (width < 700px) {
  .a .c {
    width: 100%
  }
}

Expected

@media(width<700px){.a{.b,.c{width:100%}}}

Outputs

clean-css ✗

@media (width < 700px){.a .b,.a .c{width:100%}}

csskit ✗

@media(width<700px){.a .b{width:100%}}@media(width<700px){.a .c{width:100%}}

csslop ✓

@media(width<700px){.a{.b,.c{width:100%}}}

cssnano ✗

@media(width<700px){.a .b,.a .c{width:100%}}

csso ✗

esbuild ✗

@media(width<700px){.a .b{width:100%}}@media(width<700px){.a .c{width:100%}}

lightningcss ✗

@media (width<700px){.a .b,.a .c{width:100%}}

sass ✗

@media(width < 700px){.a .b{width:100%}}@media(width < 700px){.a .c{width:100%}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0028 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Combine common properties across nearly-identical rules

If adjacent rules have matching properties with none missing, then their selectors can be combined on the first rule. Then any properties in the subsequent rules that have matching values can be eliminated.

button {
  border-width: 1px;
  border-radius: 6px;
  margin-right: 6px;
  margin-bottom: 6px;
  padding: 10px;
  color: tan;
  font-family: inherit;
  font-size: inherit;
  outline: 0;
}
input {
  border-width: 2px;
  border-radius: 6px;
  margin-right: 6px;
  margin-bottom: 6px;
  padding: 10px;
  color: tan;
  font-family: inherit;
  font-size: inherit;
  outline: 0;
}
select {
  border-width: 3px;
  border-radius: 6px;
  margin-right: 6px;
  margin-bottom: 6px;
  padding: 10px;
  color: tan;
  font-family: inherit;
  font-size: inherit;
  outline: 0;
}

Expected

button,input,select{border-width:1px;border-radius:6px;margin-right:6px;margin-bottom:6px;padding:10px;color:tan;font-family:inherit;font-size:inherit;outline:0}input{border-width:2px}select{border-width:3px}

Outputs

clean-css ✗

button{border-width:1px;border-radius:6px;margin-right:6px;margin-bottom:6px;padding:10px;color:tan;font-family:inherit;font-size:inherit;outline:0}input{border-width:2px;border-radius:6px;margin-right:6px;margin-bottom:6px;padding:10px;color:tan;font-family:inherit;font-size:inherit;outline:0}select{border-width:3px;border-radius:6px;margin-right:6px;margin-bottom:6px;padding:10px;color:tan;font-family:inherit;font-size:inherit;outline:0}

csskit ✗

button{border-width:1px;border-radius:6px;margin-right:6px;margin-bottom:6px;padding:10px;color:tan;font-family:inherit;font-size:inherit;outline:0}input{border-width:2px;border-radius:6px;margin-right:6px;margin-bottom:6px;padding:10px;color:tan;font-family:inherit;font-size:inherit;outline:0}select{border-width:3px;border-radius:6px;margin-right:6px;margin-bottom:6px;padding:10px;color:tan;font-family:inherit;font-size:inherit;outline:0}

csslop ✓

button,input,select{border-width:1px;border-radius:6px;margin-right:6px;margin-bottom:6px;padding:10px;color:tan;font-family:inherit;font-size:inherit;outline:0}input{border-width:2px}select{border-width:3px}

cssnano ✗

button{border-width:1px}button,input,select{border-radius:6px;margin-right:6px;margin-bottom:6px;padding:10px;color:tan;font-family:inherit;font-size:inherit;outline:0}input{border-width:2px}select{border-width:3px}

csso ✗

button,input,select{border-width:1px;border-radius:6px;margin-right:6px;margin-bottom:6px;padding:10px;color:tan;font-family:inherit;font-size:inherit;outline:0}input,select{border-width:2px}select{border-width:3px}

esbuild ✗

button{border-width:1px;border-radius:6px;margin-right:6px;margin-bottom:6px;padding:10px;color:tan;font-family:inherit;font-size:inherit;outline:0}input{border-width:2px;border-radius:6px;margin-right:6px;margin-bottom:6px;padding:10px;color:tan;font-family:inherit;font-size:inherit;outline:0}select{border-width:3px;border-radius:6px;margin-right:6px;margin-bottom:6px;padding:10px;color:tan;font-family:inherit;font-size:inherit;outline:0}

lightningcss ✗

button{color:tan;font-family:inherit;font-size:inherit;border-width:1px;border-radius:6px;outline:0;margin-bottom:6px;margin-right:6px;padding:10px}input{color:tan;font-family:inherit;font-size:inherit;border-width:2px;border-radius:6px;outline:0;margin-bottom:6px;margin-right:6px;padding:10px}select{color:tan;font-family:inherit;font-size:inherit;border-width:3px;border-radius:6px;outline:0;margin-bottom:6px;margin-right:6px;padding:10px}

sass ✗

button{border-width:1px;border-radius:6px;margin-right:6px;margin-bottom:6px;padding:10px;color:tan;font-family:inherit;font-size:inherit;outline:0}input{border-width:2px;border-radius:6px;margin-right:6px;margin-bottom:6px;padding:10px;color:tan;font-family:inherit;font-size:inherit;outline:0}select{border-width:3px;border-radius:6px;margin-right:6px;margin-bottom:6px;padding:10px;color:tan;font-family:inherit;font-size:inherit;outline:0}
1ms
1ms
1ms
3ms
1ms
1ms
1ms
1ms
0029 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Skip combining common properties across rules when it results in a larger size

If adjacent rules have matching properties with none missing, then their selectors can be combined on the first rule. Then any properties in the subsequent rules that have matching values can be eliminated. However, in some cases (particularly those with longer selectors, or with very few properties with matching values) this can result in a larger output, which should be avoided.

.a-very-long-and-detailed-example-selector {
  color: tan;
  padding: 1px;
}
.a-verbose-example-selector-that-is-much-longer-than-average {
  color: tan;
  padding: 2px;
}

Expected

.a-very-long-and-detailed-example-selector{color:tan;padding:1px}.a-verbose-example-selector-that-is-much-longer-than-average{color:tan;padding:2px}

Outputs

clean-css ✓

.a-very-long-and-detailed-example-selector{color:tan;padding:1px}.a-verbose-example-selector-that-is-much-longer-than-average{color:tan;padding:2px}

csskit ✓

.a-very-long-and-detailed-example-selector{color:tan;padding:1px}.a-verbose-example-selector-that-is-much-longer-than-average{color:tan;padding:2px}

csslop ✓

.a-very-long-and-detailed-example-selector{color:tan;padding:1px}.a-verbose-example-selector-that-is-much-longer-than-average{color:tan;padding:2px}

cssnano ✓

.a-very-long-and-detailed-example-selector{color:tan;padding:1px}.a-verbose-example-selector-that-is-much-longer-than-average{color:tan;padding:2px}

csso ✓

.a-very-long-and-detailed-example-selector{color:tan;padding:1px}.a-verbose-example-selector-that-is-much-longer-than-average{color:tan;padding:2px}

esbuild ✓

.a-very-long-and-detailed-example-selector{color:tan;padding:1px}.a-verbose-example-selector-that-is-much-longer-than-average{color:tan;padding:2px}

lightningcss ✓

.a-very-long-and-detailed-example-selector{color:tan;padding:1px}.a-verbose-example-selector-that-is-much-longer-than-average{color:tan;padding:2px}

sass ✓

.a-very-long-and-detailed-example-selector{color:tan;padding:1px}.a-verbose-example-selector-that-is-much-longer-than-average{color:tan;padding:2px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0030 ✗ ✗ ✓ ✓ ✓ ✗ ✓ ✗
Details

Merge rules with case-insensitive attribute selectors in :where

These rules have identical property/values pairs, and can be combined. They also both feature complex selectors involing :where and case-insensitive (i) attribute selectors.

:where([aria-hidden=false i][hidden]) {
  display: block;
}
:where([aria-hidden=false i][hidden]:not(:focus)) {
  display: block;
}

Expected

:where([aria-hidden=false i][hidden]),:where([aria-hidden=false i][hidden]:not(:focus)){display:block}

Outputs

clean-css ✗

:where([aria-hidden=false i][hidden]){display:block}:where([aria-hidden=false i][hidden]:not(:focus)){display:block}

csskit ✗

:where([aria-hidden=false i][hidden]){display:block}:where([aria-hidden=false i][hidden]:not(:focus)){display:block}

csslop ✓

:where([aria-hidden=false i][hidden]),:where([aria-hidden=false i][hidden]:not(:focus)){display:block}

cssnano ✓

:where([aria-hidden=false i][hidden]),:where([aria-hidden=false i][hidden]:not(:focus)){display:block}

csso ✓

:where([aria-hidden=false i][hidden]),:where([aria-hidden=false i][hidden]:not(:focus)){display:block}

esbuild ✗

:where([aria-hidden=false i][hidden]){display:block}:where([aria-hidden=false i][hidden]:not(:focus)){display:block}

lightningcss ✓

:where([aria-hidden=false i][hidden]),:where([aria-hidden=false i][hidden]:not(:focus)){display:block}

sass ✗

:where([aria-hidden=false i][hidden]){display:block}:where([aria-hidden=false i][hidden]:not(:focus)){display:block}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0031 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Merge rules and media queries separated by each other

In this example, the first media query does not have anything that would override the following rule, so it is safe to move the rule above the query. This then groups the two rules and two queries to be adjacent to each other. The media query conditions are identical, and can therefor be merged.

a {
  margin: 0;
}
@media (width < 640px) {
  a {
    margin: 1px;
  }
}
b {
  padding: 0;
}
@media (width < 640px) {
  b {
    padding: 1px;
  }
}

Expected

a{margin:0}b{padding:0}@media(width<640px){a{margin:1px}b{padding:1px}}

Outputs

clean-css ✗

a{margin:0}b{padding:0}@media (width < 640px){a{margin:1px}b{padding:1px}}

csskit ✗

a{margin:0}@media(width<640px){a{margin:1px}}b{padding:0}@media(width<640px){b{padding:1px}}

csslop ✓

a{margin:0}b{padding:0}@media(width<640px){a{margin:1px}b{padding:1px}}

cssnano ✓

a{margin:0}b{padding:0}@media(width<640px){a{margin:1px}b{padding:1px}}

csso ✗

a{margin:0}b{padding:0}

esbuild ✗

a{margin:0}@media(width<640px){a{margin:1px}}b{padding:0}@media(width<640px){b{padding:1px}}

lightningcss ✗

a{margin:0}@media (width<640px){a{margin:1px}}b{padding:0}@media (width<640px){b{padding:1px}}

sass ✗

a{margin:0}@media(width < 640px){a{margin:1px}}b{padding:0}@media(width < 640px){b{padding:1px}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0032 ✗ ✗ ✓ ✓ ✓ ✗ ✗ ✗
Details

Merge rules with properties of the same color but differing representations

In this test, the color property is in both rules, and has the same value (red) but in different representations (rgb function and capitalized hex). A minifier should resolve these color representations to their shortest version (the keyword red in this case), then merge the selectors on the first rule, removing the property from the second rule for the shortest possible outcome.

Note, that this should take into account the selector length and total number of property/value pairs, as it may be shorter to not merge. See: merging/0029 "Skip combining common properties across rules when it results in a larger size".

a {
  color: rgb(255, 0, 0);
}
b {
  color: #F00;
  font-style: italic;
}

Expected

a,b{color:red}b{font-style:italic}

Outputs

clean-css ✗

a{color:red}b{color:red;font-style:italic}

csskit ✗

a{color:red}b{color:red;font-style:italic}

csslop ✓

a,b{color:red}b{font-style:italic}

cssnano ✓

a,b{color:red}b{font-style:italic}

csso ✓

a,b{color:red}b{font-style:italic}

esbuild ✗

a{color:red}b{color:red;font-style:italic}

lightningcss ✗

a{color:red}b{color:red;font-style:italic}

sass ✗

a{color:red}b{color:red;font-style:italic}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0033 ✗ ✗ ✓ ✓ ✓ ✗ ✗ ✗
Details

Merge common properties of adjacent rules

In this example there are two rules that have width:1px. They can be merged into one rule, however the color:red must remain in a separate rule. Because there are no specificity changes, the merged rule can go before or after the other rule. This rule should be conditionally applied, as longer class names or larger amounts of properties may be longer when merged, See: merging\0029 "Skip combining common properties across rules when larger".

a {
  color: red;
  width: 1px;
}
b {
  width: 1px;
}

Expected

a{color:red}a,b{width:1px}

Also accepted

a,b{width:1px}a{color:red}

Outputs

clean-css ✗

a{color:red;width:1px}b{width:1px}

csskit ✗

a{color:red;width:1px}b{width:1px}

csslop ✓

a{color:red}a,b{width:1px}

cssnano ✓

a{color:red}a,b{width:1px}

csso ✓

a{color:red}a,b{width:1px}

esbuild ✗

a{color:red;width:1px}b{width:1px}

lightningcss ✗

a{color:red;width:1px}b{width:1px}

sass ✗

a{color:red;width:1px}b{width:1px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0034 ✓ ✗ ✓ ✓ ✓ ✓ ✓ ✗
Details

Merge identical rules inside media query separated by a comment

Remove the comment, then combine the identical rules.

@media screen {
  a {
    color: red;
  }
  /* comment */
  b {
    color: red;
  }
}

Expected

@media screen{a,b{color:red}}

Outputs

clean-css ✓

@media screen{a,b{color:red}}

csskit ✗

@media screen{a{color:red}b{color:red}}

csslop ✓

@media screen{a,b{color:red}}

cssnano ✓

@media screen{a,b{color:red}}

csso ✓

@media screen{a,b{color:red}}

esbuild ✓

@media screen{a,b{color:red}}

lightningcss ✓

@media screen{a,b{color:red}}

sass ✗

@media screen{a{color:red}b{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0035 ✓ ✗ ✓ ✓ ✓ ✗ ✓ ✗
Details

Merge identical @media separated by a comment and an empty @media

Remove the comment and empty media query, then merge the remaining media queries.

@media screen {
  a {
    color: red;
  }
}
/* comment */
@media print {
}
@media screen {
  b {
    margin: 0;
  }
}

Expected

@media screen{a{color:red}b{margin:0}}

Outputs

clean-css ✓

@media screen{a{color:red}b{margin:0}}

csskit ✗

@media screen{a{color:red}}@media screen{b{margin:0}}

csslop ✓

@media screen{a{color:red}b{margin:0}}

cssnano ✓

@media screen{a{color:red}b{margin:0}}

csso ✓

@media screen{a{color:red}b{margin:0}}

esbuild ✗

@media screen{a{color:red}}@media screen{b{margin:0}}

lightningcss ✓

@media screen{a{color:red}b{margin:0}}

sass ✗

@media screen{a{color:red}}@media screen{b{margin:0}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0036 ✓ ✗ ✓ ✓ ✓ ✗ ✓ ✗
Details

Merge identical @media separated by an empty @supports

Remove the empty @supports then merge the remaining media queries.

@media screen {
  a {
    color: red;
  }
}
@supports (display: grid) {
}
@media screen {
  b {
    margin: 0;
  }
}

Expected

@media screen{a{color:red}b{margin:0}}

Outputs

clean-css ✓

@media screen{a{color:red}b{margin:0}}

csskit ✗

@media screen{a{color:red}}@media screen{b{margin:0}}

csslop ✓

@media screen{a{color:red}b{margin:0}}

cssnano ✓

@media screen{a{color:red}b{margin:0}}

csso ✓

@media screen{a{color:red}b{margin:0}}

esbuild ✗

@media screen{a{color:red}}@media screen{b{margin:0}}

lightningcss ✓

@media screen{a{color:red}b{margin:0}}

sass ✗

@media screen{a{color:red}}@media screen{b{margin:0}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0037 ✓ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Merge media queries separated by non-intersecting rule

There are 3 media queries with the same condition. One rule separates the second and third media queries. Although this rule's selector (.c) is used in a rule in the following media query, the properties in it are not affected by any of the queries. This means they can all be safely merged, and the .c rule can be placed before or after them.

@media(width>=1px) { .a { margin: 1px; } }
@media(width>=1px) { .b { margin: 2px; } }
.c { padding: 0; }
@media(width>=1px) { .c { margin: 3px; } }

Expected

@media(width>=1px){.a{margin:1px}.b{margin:2px}.c{margin:3px}}.c{padding:0}

Also accepted

.c{padding:0}@media(width>=1px){.a{margin:1px}.b{margin:2px}.c{margin:3px}}

Outputs

clean-css ✓

.c{padding:0}@media(width>=1px){.a{margin:1px}.b{margin:2px}.c{margin:3px}}

csskit ✗

@media(width>=1px){.a{margin:1px}}@media(width>=1px){.b{margin:2px}}.c{padding:0}@media(width>=1px){.c{margin:3px}}

csslop ✓

@media(width>=1px){.a{margin:1px}.b{margin:2px}.c{margin:3px}}.c{padding:0}

cssnano ✓

@media(width>=1px){.a{margin:1px}.b{margin:2px}.c{margin:3px}}.c{padding:0}

csso ✗

.c{padding:0}

esbuild ✗

@media(width>=1px){.a{margin:1px}}@media(width>=1px){.b{margin:2px}}.c{padding:0}@media(width>=1px){.c{margin:3px}}

lightningcss ✗

@media (width>=1px){.a{margin:1px}.b{margin:2px}}.c{padding:0}@media (width>=1px){.c{margin:3px}}

sass ✗

@media(width >= 1px){.a{margin:1px}}@media(width >= 1px){.b{margin:2px}}.c{padding:0}@media(width >= 1px){.c{margin:3px}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0038 ✗ ✗ ✓ ✓ ✗ ✗ ✗ ✗
Details

Merge unrelated media queries and rules intersecting each other

There are 3 media queries with the same condition. Two rules, (.x, .y) separate them. The selectors and properties used in the separating rules are not included in any of the media queries, making it safe to reorder them so the rules and media queries can be adjacent. Once re-ordered the identical .x and .y rules can be merged, and the matching media queries can be as well. The merged rules can go above or below the merged media query.

@media(min-width>1px){.a{margin:1px}}
.x{padding:0}
@media(min-width>1px){.b{margin:2px}}
.y{padding:0}
@media(min-width>1px){.c{margin:3px}}

Expected

@media(min-width>1px){.a{margin:1px}.b{margin:2px}.c{margin:3px}}.x,.y{padding:0}

Also accepted

.x,.y{padding:0}@media(min-width>1px){.a{margin:1px}.b{margin:2px}.c{margin:3px}}

Outputs

clean-css ✗

.x{padding:0}.y{padding:0}@media(min-width>1px){.a{margin:1px}.b{margin:2px}.c{margin:3px}}

csskit ✗

@media(min-width>1px){.a{margin:1px}}.x{padding:0}@media(min-width>1px){.b{margin:2px}}.y{padding:0}@media(min-width>1px){.c{margin:3px}}

csslop ✓

@media(min-width>1px){.a{margin:1px}.b{margin:2px}.c{margin:3px}}.x,.y{padding:0}

cssnano ✓

@media(min-width>1px){.a{margin:1px}.b{margin:2px}.c{margin:3px}}.x,.y{padding:0}

csso ✗

.x,.y{padding:0}

esbuild ✗

@media(min-width>1px){.a{margin:1px}}.x{padding:0}@media(min-width>1px){.b{margin:2px}}.y{padding:0}@media(min-width>1px){.c{margin:3px}}

lightningcss ✗

@media (min-width>1px){.a{margin:1px}}.x{padding:0}@media (min-width>1px){.b{margin:2px}}.y{padding:0}@media (min-width>1px){.c{margin:3px}}

sass ✗

@media(min-width > 1px){.a{margin:1px}}.x{padding:0}@media(min-width > 1px){.b{margin:2px}}.y{padding:0}@media(min-width > 1px){.c{margin:3px}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 24 / 38 11 / 38 38 / 38 30 / 38 22 / 38 12 / 38 20 / 38 7 / 38
Percent 63.15% 28.94% 100% 78.94% 57.89% 31.57% 52.63% 18.42%
Duration 5ms 10ms 12ms 36ms 6ms 19ms 1ms 17ms

nesting #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✗ ✓ ✓ ✓ ✗ ✓ ✗ ✗
Details

Basic nesting whitespace removal

A nested style rule inside a parent rule should be minified in place, preserving the nesting structure while removing whitespace.

.foo {
  color: red;
  .bar {
    margin: 0;
  }
}

Expected

.foo{color:red;.bar{margin:0}}

Outputs

clean-css ✗

.foo{color:red}

csskit ✓

.foo{color:red;.bar{margin:0}}

csslop ✓

.foo{color:red;.bar{margin:0}}

cssnano ✓

.foo{color:red;.bar{margin:0}}

csso ✗

.foo{color:red}

esbuild ✓

.foo{color:red;.bar{margin:0}}

lightningcss ✗

.foo{color:red;& .bar{margin:0}}

sass ✗

.foo{color:red}.foo .bar{margin:0}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✗ ✓ ✓ ✓ ✗ ✓ ✓ ✗
Details

Nested & selector with pseudo-class

&:hover inside a parent rule must be preserved as-is. The & refers to the parent selector and appending :hover creates a compound match.

a {
  color: red;
  &:hover {
    margin: 0;
  }
}

Expected

a{color:red;&:hover{margin:0}}

Outputs

clean-css ✗

a{color:red}

csskit ✓

a{color:red;&:hover{margin:0}}

csslop ✓

a{color:red;&:hover{margin:0}}

cssnano ✓

a{color:red;&:hover{margin:0}}

csso ✗

a{color:red}

esbuild ✓

a{color:red;&:hover{margin:0}}

lightningcss ✓

a{color:red;&:hover{margin:0}}

sass ✗

a{color:red}a:hover{margin:0}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✗ ✓ ✓ ✓ ✗ ✓ ✓ ✗
Details

Nested & with compound class selector

&.bar refines the parent selector, matching elements that match both .foo and .bar. The compound form must be preserved during minification.

.foo {
  color: red;
  &.bar {
    margin: 0;
  }
}

Expected

.foo{color:red;&.bar{margin:0}}

Outputs

clean-css ✗

.foo{color:red}

csskit ✓

.foo{color:red;&.bar{margin:0}}

csslop ✓

.foo{color:red;&.bar{margin:0}}

cssnano ✓

.foo{color:red;&.bar{margin:0}}

csso ✗

.foo{color:red}

esbuild ✓

.foo{color:red;&.bar{margin:0}}

lightningcss ✓

.foo{color:red;&.bar{margin:0}}

sass ✗

.foo{color:red}.foo.bar{margin:0}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✗ ✓ ✓ ✗ ✗ ✓ ✗ ✗
Details

Nested child combinator with implicit &

> .bar inside a parent rule uses a relative selector (implicit &). The child combinator form without an explicit & must be preserved.

.foo {
  color: red;
  > .bar {
    margin: 0;
  }
}

Expected

.foo{color:red;>.bar{margin:0}}

Outputs

clean-css ✗

.foo{color:red}

csskit ✓

.foo{color:red;>.bar{margin:0}}

csslop ✓

.foo{color:red;>.bar{margin:0}}

cssnano ✗

.foo{color:red;> .bar{margin:0}}

csso ✗

.foo{color:red}

esbuild ✓

.foo{color:red;>.bar{margin:0}}

lightningcss ✗

.foo{color:red;&>.bar{margin:0}}

sass ✗

.foo{color:red}.foo>.bar{margin:0}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✗ ✓ ✓ ✗ ✗ ✓ ✗ ✗
Details

Multi-level nesting

Three levels of nesting (figure > figcaption > p) must all be preserved and minified correctly without flattening.

figure {
  margin: 0;
  > figcaption {
    color: red;
    > p {
      font-size: .9rem;
    }
  }
}

Expected

figure{margin:0;>figcaption{color:red;>p{font-size:.9rem}}}

Outputs

clean-css ✗

figure{margin:0}

csskit ✓

figure{margin:0;>figcaption{color:red;>p{font-size:.9rem}}}

csslop ✓

figure{margin:0;>figcaption{color:red;>p{font-size:.9rem}}}

cssnano ✗

figure{margin:0;> figcaption{color:red;> p{font-size:.9rem}}}

csso ✗

figure{margin:0}

esbuild ✓

figure{margin:0;>figcaption{color:red;>p{font-size:.9rem}}}

lightningcss ✗

figure{margin:0;&>figcaption{color:red;&>p{font-size:.9rem}}}

sass ✗

figure{margin:0}figure>figcaption{color:red}figure>figcaption>p{font-size:.9rem}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✗ ✓ ✓ ✓ ✗ ✓ ✗ ✗
Details

Nested @media inside a style rule

A conditional @media rule nested inside a style rule should be minified in place. The space after @media can be removed when the condition starts with (.

.foo {
  display: grid;
  @media (width >= 768px) {
    grid-auto-flow: column;
  }
}

Expected

.foo{display:grid;@media(width>=768px){grid-auto-flow:column}}

Outputs

clean-css ✗

.foo{display:grid}

csskit ✓

.foo{display:grid;@media(width>=768px){grid-auto-flow:column}}

csslop ✓

.foo{display:grid;@media(width>=768px){grid-auto-flow:column}}

cssnano ✓

.foo{display:grid;@media(width>=768px){grid-auto-flow:column}}

csso ✗

.foo{display:grid}

esbuild ✓

.foo{display:grid;@media(width>=768px){grid-auto-flow:column}}

lightningcss ✗

.foo{display:grid;@media (width>=768px){grid-auto-flow:column}}

sass ✗

.foo{display:grid}@media(width >= 768px){.foo{grid-auto-flow:column}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0007 ✗ ✗ ✓ ✗ ✗ ✓ ✗ ✗
Details

Redundant & removal

& .bar is equivalent to .bar in a nesting context because a nested selector without & implies a descendant relationship. The explicit & is redundant and can be removed.

.foo {
  color: red;
  & .bar {
    margin: 0;
  }
}

Expected

.foo{color:red;.bar{margin:0}}

Outputs

clean-css ✗

.foo{color:red}

csskit ✗

.foo{color:red;&.bar{margin:0}}

csslop ✓

.foo{color:red;.bar{margin:0}}

cssnano ✗

.foo{color:red;& .bar{margin:0}}

csso ✗

.foo{color:red}

esbuild ✓

.foo{color:red;.bar{margin:0}}

lightningcss ✗

.foo{color:red;& .bar{margin:0}}

sass ✗

.foo{color:red}.foo .bar{margin:0}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0008 ✗ ✓ ✓ ✓ ✗ ✓ ✓ ERROR
Details

Doubled & selector

&& equals .foo.foo, doubling specificity. Must not collapse to a single &.

.foo {
  color: red;
  && {
    font-size: 16px;
  }
}

Expected

.foo{color:red;&&{font-size:16px}}

Outputs

clean-css ✗

.foo{color:red}

csskit ✓

.foo{color:red;&&{font-size:16px}}

csslop ✓

.foo{color:red;&&{font-size:16px}}

cssnano ✓

.foo{color:red;&&{font-size:16px}}

csso ✗

.foo{color:red}

esbuild ✓

.foo{color:red;&&{font-size:16px}}

lightningcss ✓

.foo{color:red;&&{font-size:16px}}

sass ✗

"&" may only used at the beginning of a compound selector.
  ╷
3 │   && {
  │    ^
  ╵
  - 3:4  root stylesheet
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0009 ✗ ✗ ✓ ✓ ✗ ✓ ✓ ✗
Details

& in non-initial position

.parent & matches .parent .foo -- the & is not at the start of the selector. This form must be preserved; it cannot be simplified.

.foo {
  color: red;
  .parent & {
    margin: 0;
  }
}

Expected

.foo{color:red;.parent &{margin:0}}

Outputs

clean-css ✗

.foo{color:red}

csskit ✗

.foo{color:red;.parent&{margin:0}}

csslop ✓

.foo{color:red;.parent &{margin:0}}

cssnano ✓

.foo{color:red;.parent &{margin:0}}

csso ✗

.foo{color:red}

esbuild ✓

.foo{color:red;.parent &{margin:0}}

lightningcss ✓

.foo{color:red;.parent &{margin:0}}

sass ✗

.foo{color:red}.parent .foo{margin:0}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0010 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Introduce nesting to shorten repeated parent selectors

Three flat rules sharing .nav as parent combine into a single nested rule, eliminating repeated selector text.

.nav {
  display: flex;
}
.nav a {
  color: red;
}
.nav a:hover {
  margin: 0;
}

Expected

.nav{display:flex;a{color:red;&:hover{margin:0}}}

Outputs

clean-css ✗

.nav{display:flex}.nav a{color:red}.nav a:hover{margin:0}

csskit ✗

.nav{display:flex}.nav a{color:red}.nav a:hover{margin:0}

csslop ✓

.nav{display:flex;a{color:red;&:hover{margin:0}}}

cssnano ✗

.nav{display:flex}.nav a{color:red}.nav a:hover{margin:0}

csso ✗

.nav{display:flex}.nav a{color:red}.nav a:hover{margin:0}

esbuild ✗

.nav{display:flex}.nav a{color:red}.nav a:hover{margin:0}

lightningcss ✗

.nav{display:flex}.nav a{color:red}.nav a:hover{margin:0}

sass ✗

.nav{display:flex}.nav a{color:red}.nav a:hover{margin:0}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0011 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Introduce nesting for pseudo-class

a { ... } a:hover { ... } is shorter when nested as a{...;&:hover{...}}, eliminating the repeated a selector.

a {
  color: red;
}
a:hover {
  margin: 0;
}

Expected

a{color:red;&:hover{margin:0}}

Outputs

clean-css ✗

a{color:red}a:hover{margin:0}

csskit ✗

a{color:red}a:hover{margin:0}

csslop ✓

a{color:red;&:hover{margin:0}}

cssnano ✗

a{color:red}a:hover{margin:0}

csso ✗

a{color:red}a:hover{margin:0}

esbuild ✗

a{color:red}a:hover{margin:0}

lightningcss ✗

a{color:red}a:hover{margin:0}

sass ✗

a{color:red}a:hover{margin:0}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0012 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Introduce nesting for child combinator

.card { ... } .card > .title { ... } is shorter when nested using a relative child selector: .card{...;>.title{...}}.

.card {
  padding: 1rem;
}
.card > .title {
  color: red;
}

Expected

.card{padding:1rem;>.title{color:red}}

Outputs

clean-css ✗

.card{padding:1rem}.card>.title{color:red}

csskit ✗

.card{padding:1rem}.card>.title{color:red}

csslop ✓

.card{padding:1rem;>.title{color:red}}

cssnano ✗

.card{padding:1rem}.card>.title{color:red}

csso ✗

.card{padding:1rem}.card>.title{color:red}

esbuild ✗

.card{padding:1rem}.card>.title{color:red}

lightningcss ✗

.card{padding:1rem}.card>.title{color:red}

sass ✗

.card{padding:1rem}.card>.title{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0013 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✓
Details

Flatten descendant nesting with empty parent

When a parent rule has no declarations of its own, the nested child can be flattened into a single descendant selector. a { b { color: red } } becomes a b{color:red}, eliminating the empty wrapper.

a {
  b {
    color: red;
  }
}

Expected

a b{color:red}

Outputs

clean-css ✗

csskit ✗

a{b{color:red}}

csslop ✓

a b{color:red}

cssnano ✗

a{b{color:red}}

csso ✗

esbuild ✗

a{b{color:red}}

lightningcss ✗

a{& b{color:red}}

sass ✓

a b{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0014 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✓
Details

Flatten child combinator nesting with empty parent

a { > b { color: red } } can be flattened to a>b{color:red} when the parent has no own declarations. The relative child selector resolves to a direct child combinator.

a {
  > b {
    color: red;
  }
}

Expected

a>b{color:red}

Outputs

clean-css ✗

csskit ✗

a{>b{color:red}}

csslop ✓

a>b{color:red}

cssnano ✗

a{> b{color:red}}

csso ✗

esbuild ✗

a{>b{color:red}}

lightningcss ✗

a{&>b{color:red}}

sass ✓

a>b{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0015 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✓
Details

Flatten next-sibling combinator nesting with empty parent

a { + b { color: red } } can be flattened to a+b{color:red}. The relative next-sibling selector resolves to the adjacent sibling combinator when the parent wrapper has no declarations.

a {
  + b {
    color: red;
  }
}

Expected

a+b{color:red}

Outputs

clean-css ✗

csskit ✗

a{+b{color:red}}

csslop ✓

a+b{color:red}

cssnano ✗

a{+ b{color:red}}

csso ✗

esbuild ✗

a{+b{color:red}}

lightningcss ✗

a{&+b{color:red}}

sass ✓

a+b{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0016 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✓
Details

Flatten subsequent-sibling combinator nesting with empty parent

a { ~ b { color: red } } can be flattened to a~b{color:red}. The relative subsequent-sibling selector resolves to the general sibling combinator when the parent has no own declarations.

a {
  ~ b {
    color: red;
  }
}

Expected

a~b{color:red}

Outputs

clean-css ✗

csskit ✗

a{~b{color:red}}

csslop ✓

a~b{color:red}

cssnano ✗

a{~ b{color:red}}

csso ✗

esbuild ✗

a{~b{color:red}}

lightningcss ✗

a{&~b{color:red}}

sass ✓

a~b{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0017 ✗ ✓ ✓ ✗ ✗ ✓ ✗ ✗
Details

Nested rules with mixed combinators stay nested

When a parent has no own declarations but multiple nested children, keeping the nesting is shorter than flattening because the parent selector only appears once instead of being repeated for each child rule.

nav {
  a {
    color: red;
  }
  > .icon {
    width: 1rem;
  }
  + footer {
    margin: 0;
  }
}

Expected

nav{a{color:red}>.icon{width:1rem}+footer{margin:0}}

Outputs

clean-css ✗

csskit ✓

nav{a{color:red}>.icon{width:1rem}+footer{margin:0}}

csslop ✓

nav{a{color:red}>.icon{width:1rem}+footer{margin:0}}

cssnano ✗

nav{a{color:red}> .icon{width:1rem}+ footer{margin:0}}

csso ✗

esbuild ✓

nav{a{color:red}>.icon{width:1rem}+footer{margin:0}}

lightningcss ✗

nav{& a{color:red}&>.icon{width:1rem}&+footer{margin:0}}

sass ✗

nav a{color:red}nav>.icon{width:1rem}nav+footer{margin:0}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0018 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✓
Details

Flatten &:pseudo from empty parent

a { &:hover { color: red } } can be flattened to a:hover{color:red} when the parent has no own declarations. The & resolves to the parent selector, producing the compound a:hover.

a {
  &:hover {
    color: red;
  }
}

Expected

a:hover{color:red}

Outputs

clean-css ✗

csskit ✗

a{&:hover{color:red}}

csslop ✓

a:hover{color:red}

cssnano ✗

a{&:hover{color:red}}

csso ✗

esbuild ✗

a{&:hover{color:red}}

lightningcss ✗

a{&:hover{color:red}}

sass ✓

a:hover{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0019 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Duplicate nested rules should dedup and flatten

Two identical .bar rules nested inside .foo should collapse to one, then flatten to .foo .bar{...} since there are no other rules in the parent.

.foo {
  .bar {
    color: red;
    font-size: 1rem;
  }
  .bar {
    color: red;
    font-size: 1rem;
  }
}

Expected

.foo .bar{color:red;font-size:1rem}

Outputs

clean-css ✗

.foo{font-size:1rem}.bar{color:red;font-size:1rem}

csskit ✗

.foo{.bar{color:red;font-size:1rem}.bar{color:red;font-size:1rem}}

csslop ✓

.foo .bar{color:red;font-size:1rem}

cssnano ✗

.foo{.bar{color:red;font-size:1rem}}

csso ✗

esbuild ✗

.foo{.bar{color:red;font-size:1rem}}

lightningcss ✗

.foo{& .bar{color:red;font-size:1rem}}

sass ✗

.foo .bar{color:red;font-size:1rem}.foo .bar{color:red;font-size:1rem}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0020 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Introduce nesting to shorten repeated class selectors

This test validates simple repeated selectors with matching parent classes and different child classes get nested during minificaiton to reduce the duplication of the parent class in the selector.

.foo .a {
  margin: 1px;
}
.foo .b {
  margin: 2px;
}
.foo .c {
  margin: 3px;
}
.foo .d {
  margin: 4px;
}

Expected

.foo{.a{margin:1px}.b{margin:2px}.c{margin:3px}.d{margin:4px}}

Outputs

clean-css ✗

.foo .a{margin:1px}.foo .b{margin:2px}.foo .c{margin:3px}.foo .d{margin:4px}

csskit ✗

.foo .a{margin:1px}.foo .b{margin:2px}.foo .c{margin:3px}.foo .d{margin:4px}

csslop ✓

.foo{.a{margin:1px}.b{margin:2px}.c{margin:3px}.d{margin:4px}}

cssnano ✗

.foo .a{margin:1px}.foo .b{margin:2px}.foo .c{margin:3px}.foo .d{margin:4px}

csso ✗

.foo .a{margin:1px}.foo .b{margin:2px}.foo .c{margin:3px}.foo .d{margin:4px}

esbuild ✗

.foo .a{margin:1px}.foo .b{margin:2px}.foo .c{margin:3px}.foo .d{margin:4px}

lightningcss ✗

.foo .a{margin:1px}.foo .b{margin:2px}.foo .c{margin:3px}.foo .d{margin:4px}

sass ✗

.foo .a{margin:1px}.foo .b{margin:2px}.foo .c{margin:3px}.foo .d{margin:4px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0021 ✗ ✗ ✓ ✓ ✗ ✓ ✗ ✗
Details

Merge nested children with the same rules and specificity

Comma-separated nested selectors are treated the same as :is(), meaning they can only be combined when their specificity level is the same.

.a {
  .b.c { color: red; }
  .d.e, .f.g { color: red; }
}

Expected

.a{.b.c,.d.e,.f.g{color:red}}

Outputs

clean-css ✗

.d.e,.f.g{color:red}

csskit ✗

.a{.b.c{color:red}.d.e,.f.g{color:red}}

csslop ✓

.a{.b.c,.d.e,.f.g{color:red}}

cssnano ✓

.a{.b.c,.d.e,.f.g{color:red}}

csso ✗

esbuild ✓

.a{.b.c,.d.e,.f.g{color:red}}

lightningcss ✗

.a{& .b.c,& .d.e,& .f.g{color:red}}

sass ✗

.a .b.c{color:red}.a .d.e,.a .f.g{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0022 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

Do not merge nested child selectors with different specificity

Comma-separated nested selectors are treated the same as :is(), meaning selectors can only be combined when their specificity level is the same to avoid changing the authored specificity.

.d {
  .e { color: tan; }
  #f { color: tan; }
}

Expected

.d{.e{color:tan}#f{color:tan}}

Outputs

clean-css ✗

#f{color:tan}

csskit ✓

.d{.e{color:tan}#f{color:tan}}

csslop ✓

.d{.e{color:tan}#f{color:tan}}

cssnano ✗

.d{#f,.e{color:tan}}

csso ✗

esbuild ✗

.d{.e,#f{color:tan}}

lightningcss ✗

.d{& .e,& #f{color:tan}}

sass ✗

.d .e{color:tan}.d #f{color:tan}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0023 ✗ ✗ ✓ ✗ ✗ ✓ ✗ ✗
Details

Merge nested children with the same rules and specificity (IDs)

Comma-separated nested selectors are treated the same as :is(), meaning they can only be combined when their specificity level is the same.

In this test, an unnested equivalent would look like a :is(#b.c),a :is(.d.e,#f.g){color:red}. Notice how the :is() produces a specifity of 1-1-0 in both cases, allowing them to be merged to .a :is(#b.c,.d.e,#f.g){color:red}, which when re-nested is shorter .a{#b.c,.d.e,#f.g{color:red}}.

.a {
  #b.c { color: red; }
  .d.e, #f.g { color: red; }
}

Expected

.a{#b.c,.d.e,#f.g{color:red}}

Outputs

clean-css ✗

#f.g,.d.e{color:red}

csskit ✗

.a{#b.c{color:red}.d.e,#f.g{color:red}}

csslop ✓

.a{#b.c,.d.e,#f.g{color:red}}

cssnano ✗

.a{#b.c,#f.g,.d.e{color:red}}

csso ✗

esbuild ✓

.a{#b.c,.d.e,#f.g{color:red}}

lightningcss ✗

.a{& #b.c,& .d.e,& #f.g{color:red}}

sass ✗

.a #b.c{color:red}.a .d.e,.a #f.g{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0024 ✗ ✗ ✓ ✓ ✗ ✗ ✓ ✗
Details

Merge nested child :before/:after pseudo-elements with same rules

The :before and :after pseudo-elements have the same level of specificity. If no other selectors are included for their rules that have a different specificity level, and the rule declarations are identical, they can be merged.

.foo {
  color: red;
  &::after { content: ""; }
  &::before { content: ""; }
}

Expected

.foo{color:red;&:after,&:before{content:""}}

Outputs

clean-css ✗

.foo{color:red}

csskit ✗

.foo{color:red;&::after{content:""}&::before{content:""}}

csslop ✓

.foo{color:red;&:after,&:before{content:""}}

cssnano ✓

.foo{color:red;&:after,&:before{content:""}}

csso ✗

.foo{color:red}

esbuild ✗

.foo{color:red;&:after{content:""}&:before{content:""}}

lightningcss ✓

.foo{color:red;&:after,&:before{content:""}}

sass ✗

.foo{color:red}.foo::after{content:""}.foo::before{content:""}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0025 ✗ ✗ ✓ ✓ ✗ ✗ ✓ ✗
Details

Merge matching nested attribute selectors and :not()

The nested selectors [disabled] and :not(:active) both have the same 0-1-0 specificity. Since they also have an identical rule declaration, they can be merged.

input {
  &:not(:active) { opacity: .5; }
  &[disabled] { opacity: .5; }
}

Expected

input{&:not(:active),&[disabled]{opacity:.5}}

Outputs

clean-css ✗

csskit ✗

input{&:not(:active){opacity:.5}&[disabled]{opacity:.5}}

csslop ✓

input{&:not(:active),&[disabled]{opacity:.5}}

cssnano ✓

input{&:not(:active),&[disabled]{opacity:.5}}

csso ✗

esbuild ✗

input{&:not(:active){opacity:.5}&[disabled]{opacity:.5}}

lightningcss ✓

input{&:not(:active),&[disabled]{opacity:.5}}

sass ✗

input:not(:active){opacity:.5}input[disabled]{opacity:.5}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0026 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✓
Details

Un-nest unnecessarily nested pseudo-classes with empty parent

If there is only one nested selector and it is a pseudo-class, with no other styles applied to the parent, un-nest it.

a {
  &:hover {
    color: red;
  }
}

Expected

a:hover{color:red}

Outputs

clean-css ✗

csskit ✗

a{&:hover{color:red}}

csslop ✓

a:hover{color:red}

cssnano ✗

a{&:hover{color:red}}

csso ✗

esbuild ✗

a{&:hover{color:red}}

lightningcss ✗

a{&:hover{color:red}}

sass ✓

a:hover{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0027 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✓
Details

Un-nest unnecessarily nested classes with empty parent

If there is only one nested selector and it is a class, with no other styles applied to the parent, un-nest it.

.foo {
  &.bar {
    color: red;
  }
}

Expected

.foo.bar{color:red}

Outputs

clean-css ✗

csskit ✗

.foo{&.bar{color:red}}

csslop ✓

.foo.bar{color:red}

cssnano ✗

.foo{&.bar{color:red}}

csso ✗

esbuild ✗

.foo{&.bar{color:red}}

lightningcss ✗

.foo{&.bar{color:red}}

sass ✓

.foo.bar{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0028 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Nest general siblings

If an adjacent rule uses the same selector followed by an adjacent sibling, nest them together.

.a {
  color: red;
}
.a ~ .b {
  color: tan;
}

Expected

.a{color:red;~.b{color:tan}}

Outputs

clean-css ✗

.a{color:red}.a~.b{color:tan}

csskit ✗

.a{color:red}.a~.b{color:tan}

csslop ✓

.a{color:red;~.b{color:tan}}

cssnano ✗

.a{color:red}.a~.b{color:tan}

csso ✗

.a{color:red}.a~.b{color:tan}

esbuild ✗

.a{color:red}.a~.b{color:tan}

lightningcss ✗

.a{color:red}.a~.b{color:tan}

sass ✗

.a{color:red}.a~.b{color:tan}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0029 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Remove redundant & from nested selectors

If a nested selector begins with an ampersand followed by a space, both characters can be removed.

.foo {
  color: red;
  & p {
    margin: 0;
  }
  & #bar {
    padding: 0;
  }
  & * {
    border: 0;
  }
}

Expected

.foo{color:red;p{margin:0}#bar{padding:0}*{border:0}}

Outputs

clean-css ✗

.foo{color:red}& #bar{padding:0}& *{border:0}

csskit ✗

.foo{color:red;&p{margin:0}&#bar{padding:0}&*{border:0}}

csslop ✓

.foo{color:red;p{margin:0}#bar{padding:0}*{border:0}}

cssnano ✗

.foo{color:red;& p{margin:0}& #bar{padding:0}& *{border:0}}

csso ✗

.foo{color:red}

esbuild ✗

.foo{color:red;& p{margin:0}#bar{padding:0}& *{border:0}}

lightningcss ✗

.foo{color:red;& p{margin:0}& #bar{padding:0}& *{border:0}}

sass ✗

.foo{color:red}.foo p{margin:0}.foo #bar{padding:0}.foo *{border:0}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0030 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Merge nested and un-nested rules that are otherwise identical

If a selector has a descendant with a rule declaration that is identical to a rule of the same descendant but nested, merge the two if adjacent.

.foo {
  color: #000;
  .bar {
    color: red;
  }
}
.foo .bar {
  color: red;
}

Expected

.foo{color:#000;.bar{color:red}}

Outputs

clean-css ✗

.foo{color:#000}

csskit ✗

.foo{color:#000;.bar{color:red}}.foo .bar{color:red}

csslop ✓

.foo{color:#000;.bar{color:red}}

cssnano ✗

.foo{color:#000;.bar{color:red}}.foo .bar{color:red}

csso ✗

.foo{color:#000}.foo .bar{color:red}

esbuild ✗

.foo{color:#000;.bar{color:red}}.foo .bar{color:red}

lightningcss ✗

.foo{color:#000;& .bar{color:red}}.foo .bar{color:red}

sass ✗

.foo{color:#000}.foo .bar{color:red}.foo .bar{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0031 ✗ ✓ ✓ ✓ ✗ ✓ ✗ ✗
Details

Do not merge matching nested/un-nested rules with different specificty

Multiple selectors on the same level of a nested structure will be treated like :is, deferring to the highest specificity.

Example: #a,.b{.c{color:red}} is equivalent to :is(#a,.b) .c{color:red}. It is NOT equivalent to #a .c,.b .c{color:red}, which would result in a different level of specificity, as :is will always use the highest specificity found across all selectors inside it.

#a, .b {
  .c {
    color: tan;
  }
}
.b .c {
  color: tan;
}

Expected

#a,.b{.c{color:tan}}.b .c{color:tan}

Outputs

clean-css ✗

csskit ✓

#a,.b{.c{color:tan}}.b .c{color:tan}

csslop ✓

#a,.b{.c{color:tan}}.b .c{color:tan}

cssnano ✓

#a,.b{.c{color:tan}}.b .c{color:tan}

csso ✗

.b .c{color:tan}

esbuild ✓

#a,.b{.c{color:tan}}.b .c{color:tan}

lightningcss ✗

#a,.b{& .c{color:tan}}.b .c{color:tan}

sass ✗

#a .c,.b .c{color:tan}.b .c{color:tan}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0032 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Remove useless :is from selector nesting

Comma-separated selectors in rules with nesting are treated as though the selectors are wrapped in an :is, resulting in shared specificity, using the more specific of all the selectors. In this test, the :is() contains an ID and a class, with another class outside of it, which will recieve whatever the result of the :is() evaluation anyways, making it pointless to include.

The #a,.b,.c in the test is equivalent to :is(#a,.b.c), which is equivalent to :is(:is(#a,.b),.c).

:is(#a, .b), .c {
  .d {
    color: red;
  }
}

Expected

#a,.b,.c{.d{color:red}}

Outputs

clean-css ✗

csskit ✗

:is(#a,.b),.c{.d{color:red}}

csslop ✓

#a,.b,.c{.d{color:red}}

cssnano ✗

.c,:is(#a,.b){.d{color:red}}

csso ✗

esbuild ✗

:is(#a,.b),.c{.d{color:red}}

lightningcss ✗

:is(#a,.b),.c{& .d{color:red}}

sass ✗

:is(#a,.b) .d,.c .d{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0033 ✗ ✓ ✓ ✓ ✗ ✓ ✗ ✗
Details

Do not remove :is when it contains potentially unsupported selectors

If a new CSS feature is used in a selector and the browser does not recognize it the entire rule will be ignored, even if there are other valid selectors attached to the rule (#a:foo,.b{color:red}). However, if the selectors are wrapped in an :is function then only the unrecognized selector is ignored, the rest of the selectors still apply the rule (:is(#a:foo,.b){color:red}).

.a, :is(#b:unsupported, .c) {
  .d, :is(.e:foo, .f) {
    color: red;
  }
}

Expected

.a,:is(#b:unsupported,.c){.d,:is(.e:foo,.f){color:red}}

Outputs

clean-css ✗

csskit ✓

.a,:is(#b:unsupported,.c){.d,:is(.e:foo,.f){color:red}}

csslop ✓

.a,:is(#b:unsupported,.c){.d,:is(.e:foo,.f){color:red}}

cssnano ✓

.a,:is(#b:unsupported,.c){.d,:is(.e:foo,.f){color:red}}

csso ✗

esbuild ✓

.a,:is(#b:unsupported,.c){.d,:is(.e:foo,.f){color:red}}

lightningcss ✗

.a,:is(#b:unsupported,.c){& .d,& :is(.e:foo,.f){color:red}}

sass ✗

.a .d,.a :is(.e:foo,.f),:is(#b:unsupported,.c) .d,:is(#b:unsupported,.c) :is(.e:foo,.f){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0034 ✗ ✓ ✓ ✓ ✗ ✓ ✗ ✗
Details

Retain nesting when child has multiple selectors

When a child selector in a nested group is a comma separated list, it will always be shorter to keep the selectors nested.

.a {
  .b,
  .c {
    color: red;
  }
}

Expected

.a{.b,.c{color:red}}

Outputs

clean-css ✗

csskit ✓

.a{.b,.c{color:red}}

csslop ✓

.a{.b,.c{color:red}}

cssnano ✓

.a{.b,.c{color:red}}

csso ✗

esbuild ✓

.a{.b,.c{color:red}}

lightningcss ✗

.a{& .b,& .c{color:red}}

sass ✗

.a .b,.a .c{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0035 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✓
Details

Flatten multi-level nesting of single selectors

If a child in a nested selector is not comma separated, it can be merged with the parent, if it is also not comma separated, removing the extra curly braces.

.foo {
  .bar {
    input {
      &:active {
        &:hover {
          color: red;
        }
      }
    }
  }
}

Expected

.foo .bar input:active:hover{color:red}

Also accepted

.foo .bar input:hover:active{color:red}

Outputs

clean-css ✗

csskit ✗

.foo{.bar{input{&:active{&:hover{color:red}}}}}

csslop ✓

.foo .bar input:active:hover{color:red}

cssnano ✗

.foo{.bar{input{&:active{&:hover{color:red}}}}}

csso ✗

esbuild ✗

.foo{.bar{input{&:active{&:hover{color:red}}}}}

lightningcss ✗

.foo{& .bar{& input{&:active{&:hover{color:red}}}}}

sass ✓

.foo .bar input:active:hover{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0036 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Normalize descendant whitespace before introducing nesting

There are 2 spaces in the second selector. These should be normalized to 1 before nesting. Or both removed during nesting.

.a {
  color: red;
}
.a  .b {
  color: tan;
}

Expected

.a{color:red;.b{color:tan}}

Outputs

clean-css ✗

.a{color:red}.a .b{color:tan}

csskit ✗

.a{color:red}.a .b{color:tan}

csslop ✓

.a{color:red;.b{color:tan}}

cssnano ✗

.a{color:red}.a .b{color:tan}

csso ✗

.a{color:red}.a .b{color:tan}

esbuild ✗

.a{color:red}.a .b{color:tan}

lightningcss ✗

.a{color:red}.a .b{color:tan}

sass ✗

.a{color:red}.a .b{color:tan}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0037 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Merge identical rules with children, keep distinct properties in separate rule

In this example, the .a .x rule can be nested under .a, and the .b .x rule can be nested under .b. This results in 2 identical rules, with the exception of one distinct property in .b that can be moved to its own rule.

.a {
  color: red;
}
.a .x {
  color: tan;
}
.b {
  color: red;
  padding: 1px;
}
.b .x {
  color: tan;
}

Expected

.a,.b{color:red;.x{color:tan}}.b{padding:1px}

Outputs

clean-css ✗

.a{color:red}.a .x{color:tan}.b{color:red;padding:1px}.b .x{color:tan}

csskit ✗

.a{color:red}.a .x{color:tan}.b{color:red;padding:1px}.b .x{color:tan}

csslop ✓

.a,.b{color:red;.x{color:tan}}.b{padding:1px}

cssnano ✗

.a{color:red}.a .x{color:tan}.b{color:red;padding:1px}.b .x{color:tan}

csso ✗

.a,.b{color:red}.a .x,.b .x{color:tan}.b{padding:1px}

esbuild ✗

.a{color:red}.a .x{color:tan}.b{color:red;padding:1px}.b .x{color:tan}

lightningcss ✗

.a{color:red}.a .x{color:tan}.b{color:red;padding:1px}.b .x{color:tan}

sass ✗

.a{color:red}.a .x{color:tan}.b{color:red;padding:1px}.b .x{color:tan}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0038 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Nesting repeated selector shorthand to &&

The && in this example is equivalent to .foo.foo. This is the inverse of nesting/0008 and relates to nesting/0039.

.foo {
  color: red;
  &.foo {
    font-size: 16px;
  }
}

Expected

.foo{color:red;&&{font-size:16px}}

Outputs

clean-css ✗

.foo{color:red}

csskit ✗

.foo{color:red;&.foo{font-size:16px}}

csslop ✓

.foo{color:red;&&{font-size:16px}}

cssnano ✗

.foo{color:red;&.foo{font-size:16px}}

csso ✗

.foo{color:red}

esbuild ✗

.foo{color:red;&.foo{font-size:16px}}

lightningcss ✗

.foo{color:red;&.foo{font-size:16px}}

sass ✗

.foo{color:red}.foo.foo{font-size:16px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0039 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Nesting repeated selector shorthand to &&&

The &&& in this example is equivalent to .foo.foo.foo. This is the inverse of nesting/0008, and relates to nesting/0038.

.foo {
  color: red;
  &.foo.foo {
    font-size: 16px;
  }
}

Expected

.foo{color:red;&&&{font-size:16px}}

Outputs

clean-css ✗

.foo{color:red}

csskit ✗

.foo{color:red;&.foo.foo{font-size:16px}}

csslop ✓

.foo{color:red;&&&{font-size:16px}}

cssnano ✗

.foo{color:red;&.foo.foo{font-size:16px}}

csso ✗

.foo{color:red}

esbuild ✗

.foo{color:red;&.foo.foo{font-size:16px}}

lightningcss ✗

.foo{color:red;&.foo.foo{font-size:16px}}

sass ✗

.foo{color:red}.foo.foo.foo{font-size:16px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0040 ✗ ✗ ✓ ✗ ✗ ✓ ✗ ✗
Details

Flatten unnecessary nesting

In this example, there is a nested rule with only & as the selector, making properties held within apply to the parent selector. This means those properties can be unnested.

a {
  margin-bottom: 1px;
  & {
    margin-right: 1px;
  }
}

Expected

a{margin-bottom:1px;margin-right:1px}

Outputs

clean-css ✗

a{margin-bottom:1px}

csskit ✗

a{margin-bottom:1px;&{margin-right:1px}}

csslop ✓

a{margin-bottom:1px;margin-right:1px}

cssnano ✗

a{margin-bottom:1px;&{margin-right:1px}}

csso ✗

a{margin-bottom:1px}

esbuild ✓

a{margin-bottom:1px;margin-right:1px}

lightningcss ✗

a{margin-bottom:1px;&{margin-right:1px}}

sass ✗

a{margin-bottom:1px}a{margin-right:1px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0041 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Nest selectors on a rule that only differ in the middle

In this example there are two selectors used on a rule, they are each 3 levels deep and both start and end with the same targets. By re-nesting just the parts that differ we represent the selectors in fewer characters.

.menu .item:hover .sub-menu,
.menu .item:focus .sub-menu {
  display: block;
}

Expected

.menu .item{&:hover,&:focus{.sub-menu{display:block}}}

Outputs

clean-css ✗

.menu .item:focus .sub-menu,.menu .item:hover .sub-menu{display:block}

csskit ✗

.menu .item:hover .sub-menu,.menu .item:focus .sub-menu{display:block}

csslop ✓

.menu .item{&:hover,&:focus{.sub-menu{display:block}}}

cssnano ✗

.menu :is(.item:focus,.item:hover) .sub-menu{display:block}

csso ✗

.menu .item:focus .sub-menu,.menu .item:hover .sub-menu{display:block}

esbuild ✗

.menu .item:hover .sub-menu,.menu .item:focus .sub-menu{display:block}

lightningcss ✗

.menu .item:hover .sub-menu,.menu .item:focus .sub-menu{display:block}

sass ✗

.menu .item:hover .sub-menu,.menu .item:focus .sub-menu{display:block}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0042 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Merge consecutive nesting wrappers with the same parent selector

This validates that the similarities between .a .c and .a:hover .c are nested by the minifier, as well as being merged and nested with .a .b for the shortest possible selector.

.a .b {
  color: red;
}
.a .c {
  color: tan;
}
.a:hover .c {
  color: tan;
}

Expected

.a{.b{color:red}.c,&:hover .c{color:tan}}

Outputs

clean-css ✗

.a .b{color:red}.a .c,.a:hover .c{color:tan}

csskit ✗

.a .b{color:red}.a .c{color:tan}.a:hover .c{color:tan}

csslop ✓

.a{.b{color:red}.c,&:hover .c{color:tan}}

cssnano ✗

.a .b{color:red}.a .c,.a:hover .c{color:tan}

csso ✗

.a .b{color:red}.a .c,.a:hover .c{color:tan}

esbuild ✗

.a .b{color:red}.a .c,.a:hover .c{color:tan}

lightningcss ✗

.a .b{color:red}.a .c,.a:hover .c{color:tan}

sass ✗

.a .b{color:red}.a .c{color:tan}.a:hover .c{color:tan}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0043 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Nest pseudo-elements that start with double colon

In this example, we use the pseudo-elements ::-webkit-inner-spin-button and ::-webkit-outer-spin-button which start with two colons. They have the same selector prefix, which means they can be nested under it.

[type=number]::-webkit-inner-spin-button,
[type=number]::-webkit-outer-spin-button {
  cursor: pointer;
}

Expected

[type=number]{&::-webkit-inner-spin-button,&::-webkit-outer-spin-button{cursor:pointer}}

Outputs

clean-css ✗

[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{cursor:pointer}

csskit ✗

[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{cursor:pointer}

csslop ✓

[type=number]{&::-webkit-inner-spin-button,&::-webkit-outer-spin-button{cursor:pointer}}

cssnano ✗

[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{cursor:pointer}

csso ✗

[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{cursor:pointer}

esbuild ✗

[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{cursor:pointer}

lightningcss ✗

[type=number]::-webkit-inner-spin-button{cursor:pointer}[type=number]::-webkit-outer-spin-button{cursor:pointer}

sass ✗

[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{cursor:pointer}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0044 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Nest child selectors (including parent styles)

In this example, the code can all be grouped together under the parent selector a. The parent selector's styles should be included in the newly nested rule.

a {
  color: red;
}
a b,
a p {
  margin: 0;
}

Expected

a{color:red;b,p{margin:0}}

Outputs

clean-css ✗

a{color:red}a b,a p{margin:0}

csskit ✗

a{color:red}a b,a p{margin:0}

csslop ✓

a{color:red;b,p{margin:0}}

cssnano ✗

a{color:red}a b,a p{margin:0}

csso ✗

a{color:red}a b,a p{margin:0}

esbuild ✗

a{color:red}a b,a p{margin:0}

lightningcss ✗

a{color:red}a b,a p{margin:0}

sass ✗

a{color:red}a b,a p{margin:0}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0045 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Nest child selectors with combinator (including parent styles)

In this example, the code can all be grouped together under the parent selector a. The parent selector's styles should be included in the newly nested rule, and the direct descendent selector (>) should be included in the nesting.

a {
  color: red;
}
a > b,
a > i {
  margin: 0;
}
a p {
  padding: 0;
}

Expected

a{color:red;>b,>i{margin:0}p{padding:0}}

Outputs

clean-css ✗

a{color:red}a>b,a>i{margin:0}a p{padding:0}

csskit ✗

a{color:red}a>b,a>i{margin:0}a p{padding:0}

csslop ✓

a{color:red;>b,>i{margin:0}p{padding:0}}

cssnano ✗

a{color:red}a>b,a>i{margin:0}a p{padding:0}

csso ✗

a{color:red}a>b,a>i{margin:0}a p{padding:0}

esbuild ✗

a{color:red}a>b,a>i{margin:0}a p{padding:0}

lightningcss ✗

a{color:red}a>b,a>i{margin:0}a p{padding:0}

sass ✗

a{color:red}a>b,a>i{margin:0}a p{padding:0}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0046 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Nest selector lists into an existing non-adjacent parent

Every selector in a .y, a .z shares the parent a, which already exists earlier in the stylesheet. Between these two points in the code no other rules apply the same property at the same or higher specificity. This means a minifier may move the nested rule up to the first a rule. There are also no rules with the same property at the same or higher specificity after the first a rule, meaning a minifier could move the first a rule after the b rule in this example. The list should be nested under the existing a rule rather. A second a wrapper should not be created.

a {
  padding: 1px;
}
b {
  color: tan;
}
a .y,
a .z {
  color: red;
}

Expected

a{padding:1px;.y,.z{color:red}}b{color:tan}

Also accepted

b{color:tan}a{padding:1px;.y,.z{color:red}}

Outputs

clean-css ✗

a{padding:1px}b{color:tan}a .y,a .z{color:red}

csskit ✗

a{padding:1px}b{color:tan}a .y,a .z{color:red}

csslop ✓

a{padding:1px;.y,.z{color:red}}b{color:tan}

cssnano ✗

a{padding:1px}b{color:tan}a .y,a .z{color:red}

csso ✗

a{padding:1px}b{color:tan}a .y,a .z{color:red}

esbuild ✗

a{padding:1px}b{color:tan}a .y,a .z{color:red}

lightningcss ✗

a{padding:1px}b{color:tan}a .y,a .z{color:red}

sass ✗

a{padding:1px}b{color:tan}a .y,a .z{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0047 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Sub-rules at each level of multi-level nesting

The shortest version of this test requires multiple levels of nesting, and multiple sub-rules at each level. All rules should be nested under the parent .a. The top level of .a will include .b .c and .d. Within .b .c there should be nested i,p and q.

.a .b .c i,
.a .b .c p {
  color: red;
}
.a .b .c q {
  padding: 8px;
}
.a .d {
  color: tan;
}

Expected

.a{.b .c{i,p{color:red}q{padding:8px}}.d{color:tan}}

Outputs

clean-css ✗

.a .b .c i,.a .b .c p{color:red}.a .b .c q{padding:8px}.a .d{color:tan}

csskit ✗

.a .b .c i,.a .b .c p{color:red}.a .b .c q{padding:8px}.a .d{color:tan}

csslop ✓

.a{.b .c{i,p{color:red}q{padding:8px}}.d{color:tan}}

cssnano ✗

.a .b .c :is(i,p){color:red}.a .b .c q{padding:8px}.a .d{color:tan}

csso ✗

.a .b .c i,.a .b .c p{color:red}.a .b .c q{padding:8px}.a .d{color:tan}

esbuild ✗

.a .b .c i,.a .b .c p{color:red}.a .b .c q{padding:8px}.a .d{color:tan}

lightningcss ✗

.a .b .c i,.a .b .c p{color:red}.a .b .c q{padding:8px}.a .d{color:tan}

sass ✗

.a .b .c i,.a .b .c p{color:red}.a .b .c q{padding:8px}.a .d{color:tan}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0048 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Multi-level nesting with rule merging

In this example, we group all rules under the parent .a, then add a sub-group for .b .c .d, with it's own sub-sub-group for i,p. We also merge the identical rules of .e,.f under .a.

.a .b .c .d i,
.a .b .c .d p {
  color: tan;
}
.a .e {
  color: red;
}
.a .f {
  color: red;
}

Expected

.a{.b .c .d{i,p{color:tan}}.e,.f{color:red}}

Outputs

clean-css ✗

.a .b .c .d i,.a .b .c .d p{color:tan}.a .e,.a .f{color:red}

csskit ✗

.a .b .c .d i,.a .b .c .d p{color:tan}.a .e{color:red}.a .f{color:red}

csslop ✓

.a{.b .c .d{i,p{color:tan}}.e,.f{color:red}}

cssnano ✗

.a .b .c .d :is(i,p){color:tan}.a .e,.a .f{color:red}

csso ✗

.a .b .c .d i,.a .b .c .d p{color:tan}.a .e,.a .f{color:red}

esbuild ✗

.a .b .c .d i,.a .b .c .d p{color:tan}.a .e,.a .f{color:red}

lightningcss ✗

.a .b .c .d i,.a .b .c .d p{color:tan}.a .e,.a .f{color:red}

sass ✗

.a .b .c .d i,.a .b .c .d p{color:tan}.a .e{color:red}.a .f{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0049 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Nest adjacent rules separated by a comment

In this example, a minifier should remove the comment, then nest the two rules that share a common ancestor in their selectors.

a b {
  color: red;
}
/* comment */
a p {
  color: tan
}

Expected

a{b{color:red}p{color:tan}}

Outputs

clean-css ✗

a b{color:red}a p{color:tan}

csskit ✗

a b{color:red}a p{color:tan}

csslop ✓

a{b{color:red}p{color:tan}}

cssnano ✗

a b{color:red}a p{color:tan}

csso ✗

a b{color:red}a p{color:tan}

esbuild ✗

a b{color:red}a p{color:tan}

lightningcss ✗

a b{color:red}a p{color:tan}

sass ✗

a b{color:red}a p{color:tan}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0050 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Flat descendant rule followed by same-parent rule containing a &-list

The first rule here is nested, but could be flattened. It is then followed by a rule that could be nested with the shared parent selector of the first rule, and contains an & selector.

a b {
  &:focus-visible {
    color: red;
  }
}
a {
  &, ul {
    color: tan;
  }
}

Expected

a{b:focus-visible{color:red}&,ul{color:tan}}

Outputs

clean-css ✗

csskit ✗

a b{&:focus-visible{color:red}}a{&,ul{color:tan}}

csslop ✓

a{b:focus-visible{color:red}&,ul{color:tan}}

cssnano ✗

a b{&:focus-visible{color:red}}a{&,ul{color:tan}}

csso ✗

esbuild ✗

a b{&:focus-visible{color:red}}a{&,ul{color:tan}}

lightningcss ✗

a b{&:focus-visible{color:red}}a{&,& ul{color:tan}}

sass ✗

a b:focus-visible{color:red}a,a ul{color:tan}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0051 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Reorder non-intersecting rules so adjacent rules can be nested

In this example the first and third rule share a parent selector, as does the second and fourth rule. Because the second and third rules do not effect the same properties, they can be re-ordered. This allows the first and third to become adjacent, and the second and fourth as well. They can then be nested under their shared parent selector.

a b {
  color: red;
}
.foo p {
  color: tan;
}
a .foo {
  margin: 0;
}
.foo:hover {
  padding: 0;
}

Expected

a{b{color:red}.foo{margin:0}}.foo{p{color:tan}&:hover{padding:0}}

Outputs

clean-css ✗

a b{color:red}.foo p{color:tan}a .foo{margin:0}.foo:hover{padding:0}

csskit ✗

a b{color:red}.foo p{color:tan}a .foo{margin:0}.foo:hover{padding:0}

csslop ✓

a{b{color:red}.foo{margin:0}}.foo{p{color:tan}&:hover{padding:0}}

cssnano ✗

a b{color:red}.foo p{color:tan}a .foo{margin:0}.foo:hover{padding:0}

csso ✗

a b{color:red}.foo p{color:tan}a .foo{margin:0}.foo:hover{padding:0}

esbuild ✗

a b{color:red}.foo p{color:tan}a .foo{margin:0}.foo:hover{padding:0}

lightningcss ✗

a b{color:red}.foo p{color:tan}a .foo{margin:0}.foo:hover{padding:0}

sass ✗

a b{color:red}.foo p{color:tan}a .foo{margin:0}.foo:hover{padding:0}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0052 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Renest a plain selector with its nested children

In this example, all three rules share the same parent (a), and can be nested under it. The first and second rules also share a common ancestor (:hover) and can be nested under it.

a:hover b {
  color: red;
}
a:hover p {
  color: tan;
}
a {
  margin: 0;
}

Expected

a{margin:0;&:hover{b{color:red}p{color:tan}}}

Outputs

clean-css ✗

a:hover b{color:red}a:hover p{color:tan}a{margin:0}

csskit ✗

a:hover b{color:red}a:hover p{color:tan}a{margin:0}

csslop ✓

a{margin:0;&:hover{b{color:red}p{color:tan}}}

cssnano ✗

a:hover b{color:red}a:hover p{color:tan}a{margin:0}

csso ✗

a:hover b{color:red}a:hover p{color:tan}a{margin:0}

esbuild ✗

a:hover b{color:red}a:hover p{color:tan}a{margin:0}

lightningcss ✗

a:hover b{color:red}a:hover p{color:tan}a{margin:0}

sass ✗

a:hover b{color:red}a:hover p{color:tan}a{margin:0}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0053 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Apply 3 levels of nesting with the plain rule in the middle

All 3 rules share the same parent .a. The middle rule is only .a, so it should be moved to the top and the others nested under it. Once nested, the child rules also contain a shared parent of &:hover, and once again, one of them has no descendants, meaning its rules must come first, and the last rule becomes nested within it using the selectors .b,.c. This creates 3 levels of nesting, including properties at each level.

.a:hover {
  opacity: 1;
}
.a {
  opacity: 0.7;
}
.a:hover .b,
.a:hover .c {
  color: red;
}

Expected

.a{opacity:.7;&:hover{opacity:1;.b,.c{color:red}}}

Outputs

clean-css ✗

.a:hover{opacity:1}.a{opacity:.7}.a:hover .b,.a:hover .c{color:red}

csskit ✗

.a:hover{opacity:1}.a{opacity:.7}.a:hover .b,.a:hover .c{color:red}

csslop ✓

.a{opacity:.7;&:hover{opacity:1;.b,.c{color:red}}}

cssnano ✗

.a:hover{opacity:1}.a{opacity:.7}.a:hover :is(.b,.c){color:red}

csso ✗

.a:hover{opacity:1}.a{opacity:.7}.a:hover .b,.a:hover .c{color:red}

esbuild ✗

.a:hover{opacity:1}.a{opacity:.7}.a:hover .b,.a:hover .c{color:red}

lightningcss ✗

.a:hover{opacity:1}.a{opacity:.7}.a:hover .b,.a:hover .c{color:red}

sass ✗

.a:hover{opacity:1}.a{opacity:.7}.a:hover .b,.a:hover .c{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 0 / 53 12 / 53 53 / 53 12 / 53 0 / 53 16 / 53 6 / 53 8 / 53
Percent 0% 22.64% 100% 22.64% 0% 30.18% 11.32% 15.09%
Duration 4ms 3ms 11ms 43ms 7ms 24ms 1ms 23ms

page #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

@page whitespace removal

Basic whitespace removal in a @page rule. The space between @page and { can be removed, and internal whitespace is minified as usual.

@page {
  margin: 1in;
}

Expected

@page{margin:1in}

Outputs

clean-css ✓

@page{margin:1in}

csskit ✓

@page{margin:1in}

csslop ✓

@page{margin:1in}

cssnano ✓

@page{margin:1in}

csso ✓

@page{margin:1in}

esbuild ✓

@page{margin:1in}

lightningcss ✓

@page{margin:1in}

sass ✓

@page{margin:1in}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✗ ✓ ✓ ✗ ✗ ✗ ✓ ✗
Details

Named @page pseudo-class

@page :first targets the first page. Whitespace between the pseudo-class and the opening brace can be removed.

@page :first {
  margin: 2in;
}

Expected

@page:first{margin:2in}

Outputs

clean-css ✗

@page :first{margin:2in}

csskit ✓

@page:first{margin:2in}

csslop ✓

@page:first{margin:2in}

cssnano ✗

@page :first{margin:2in}

csso ✗

@page :first{margin:2in}

esbuild ✗

@page :first{margin:2in}

lightningcss ✓

@page:first{margin:2in}

sass ✗

@page :first{margin:2in}
1ms
3ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✓ ✓ ✓ ✓ ✓ ✓ ✗ ✗
Details

Empty @page removal

An empty @page {} rule with no declarations can be removed entirely.

@page {
}

Expected

Outputs

clean-css ✓

csskit ✓

csslop ✓

cssnano ✓

csso ✓

esbuild ✓

lightningcss ✗

@page{}

sass ✗

@page{}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

@page margin at-rules

@page can contain margin at-rules like @top-center. Whitespace is removed inside both the outer and nested at-rule blocks.

@page {
  @top-center {
    content: "Title";
  }
}

Expected

@page{@top-center{content:"Title"}}

Outputs

clean-css ✓

@page{@top-center{content:"Title"}}

csskit ✓

@page{@top-center{content:"Title"}}

csslop ✓

@page{@top-center{content:"Title"}}

cssnano ✓

@page{@top-center{content:"Title"}}

csso ✓

@page{@top-center{content:"Title"}}

esbuild ✓

@page{@top-center{content:"Title"}}

lightningcss ✓

@page{@top-center{content:"Title"}}

sass ✓

@page{@top-center{content:"Title"}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 3 / 4 4 / 4 4 / 4 3 / 4 3 / 4 3 / 4 3 / 4 2 / 4
Percent 75% 100% 100% 75% 75% 75% 75% 50%
Duration 1ms 4ms 1ms 2ms 1ms 2ms 1ms 1ms

property #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✓ ✓ ✓ ✓ ✓ ✗ ✓ ✓
Details

@property whitespace removal

Remove whitespace inside @property while preserving the descriptor values. The syntax string and initial-value must not be altered.

@property --brand-color {
  syntax: "<color>";
  inherits: false;
  initial-value: #000;
}

Expected

@property --brand-color{syntax:"<color>";inherits:false;initial-value:#000}

Outputs

clean-css ✓

@property --brand-color{syntax:"<color>";inherits:false;initial-value:#000}

csskit ✓

@property --brand-color{syntax:"<color>";inherits:false;initial-value:#000}

csslop ✓

@property --brand-color{syntax:"<color>";inherits:false;initial-value:#000}

cssnano ✓

@property --brand-color{syntax:"<color>";inherits:false;initial-value:#000}

csso ✓

@property --brand-color{syntax:"<color>";inherits:false;initial-value:#000}

esbuild ✗

@property --brand-color{syntax: "<color>"; inherits: false; initial-value: #000;}

lightningcss ✓

@property --brand-color{syntax:"<color>";inherits:false;initial-value:#000}

sass ✓

@property --brand-color{syntax:"<color>";inherits:false;initial-value:#000}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Omit default inherits: true

The inherits descriptor defaults to true. When present with meaningful syntax and initial-value, it can be safely omitted.

See:

@property --size {
  syntax: "<length>";
  inherits: true;
  initial-value: 16px;
}

Expected

@property --size{syntax:"<length>";initial-value:16px}

Outputs

clean-css ✗

@property --size{syntax:"<length>";inherits:true;initial-value:16px}

csskit ✗

@property --size{syntax:"<length>";inherits:true;initial-value:16px}

csslop ✓

@property --size{syntax:"<length>";initial-value:16px}

cssnano ✗

@property --size{syntax:"<length>";inherits:true;initial-value:16px}

csso ✗

@property --size{syntax:"<length>";inherits:true;initial-value:16px}

esbuild ✗

@property --size{syntax: "<length>"; inherits: true; initial-value: 16px;}

lightningcss ✗

@property --size{syntax:"<length>";inherits:true;initial-value:16px}

sass ✗

@property --size{syntax:"<length>";inherits:true;initial-value:16px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✓ ✓ ✓ ✓ ✓ ✗ ✗ ✓
Details

Remove comments inside @property

Comments inside of @property can be removed.

@property --foo {
  /* syntax: "*"; */
  initial-value: red;
}

Expected

@property --foo{initial-value:red}

Outputs

clean-css ✓

@property --foo{initial-value:red}

csskit ✓

@property --foo{initial-value:red}

csslop ✓

@property --foo{initial-value:red}

cssnano ✓

@property --foo{initial-value:red}

csso ✓

@property --foo{initial-value:red}

esbuild ✗

@property --foo{initial-value: red;}

lightningcss ✗

sass ✓

@property --foo{initial-value:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✓ ✓ ✓ ✓ ✓ ✗ ✓ ✗
Details

Remove comment-only @property rule

A rule with only a comment and no descriptors is equivalent to an unregistered property and can be safely removed.

See:

@property --foo {
  /*text*/
}

Expected

Outputs

clean-css ✓

csskit ✓

csslop ✓

cssnano ✓

csso ✓

esbuild ✗

@property --foo{}

lightningcss ✓

sass ✗

@property --foo{}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Remove no-op @property rules

syntax defaults to "*", inherits defaults to true, and initial-value defaults to guaranteed-invalid. These three registrations use only default values and are equivalent to unregistered custom properties, so they can be safely removed.

@property --foo {
  inherits: true;
}

@property --bar {
  syntax: "*";
}

@property --baz {
  syntax: "*";
  inherits: true;
}

Expected

Outputs

clean-css ✗

@property --foo{inherits:true}@property --bar{syntax:"*"}@property --baz{syntax:"*";inherits:true}

csskit ✗

@property --foo{inherits:true}@property --bar{syntax:"*"}@property --baz{syntax:"*";inherits:true}

csslop ✓

cssnano ✗

@property --foo{inherits:true}@property --bar{syntax:"*"}@property --baz{syntax:"*";inherits:true}

csso ✗

@property --foo{inherits:true}@property --bar{syntax:"*"}@property --baz{syntax:"*";inherits:true}

esbuild ✗

@property --foo{inherits: true;}@property --bar{syntax: "*";}@property --baz{syntax: "*"; inherits: true;}

lightningcss ✗

@property --baz{syntax:"*";inherits:true}

sass ✗

@property --foo{inherits:true}@property --bar{syntax:"*"}@property --baz{syntax:"*";inherits:true}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Omit default syntax: "*"

The syntax descriptor defaults to "*" (universal syntax), so explicit syntax: "*" can be safely omitted. Non-default descriptors like inherits: false and initial-value are preserved when meaningful.

@property --foo {
  syntax: "*";
  inherits: false;
}

@property --bar {
  syntax: "*";
  initial-value: red;
}

@property --baz {
  syntax: "*";
  inherits: false;
  initial-value: red;
}

Expected

@property --foo{inherits:false}@property --bar{initial-value:red}@property --baz{inherits:false;initial-value:red}

Outputs

clean-css ✗

@property --foo{syntax:"*";inherits:false}@property --bar{syntax:"*";initial-value:red}@property --baz{syntax:"*";inherits:false;initial-value:red}

csskit ✗

@property --foo{syntax:"*";inherits:false}@property --bar{syntax:"*";initial-value:red}@property --baz{syntax:"*";inherits:false;initial-value:red}

csslop ✓

@property --foo{inherits:false}@property --bar{initial-value:red}@property --baz{inherits:false;initial-value:red}

cssnano ✗

@property --foo{syntax:"*";inherits:false}@property --bar{syntax:"*";initial-value:red}@property --baz{syntax:"*";inherits:false;initial-value:red}

csso ✗

@property --foo{syntax:"*";inherits:false}@property --bar{syntax:"*";initial-value:red}@property --baz{syntax:"*";inherits:false;initial-value:red}

esbuild ✗

@property --foo{syntax: "*"; inherits: false;}@property --bar{syntax: "*"; initial-value: red;}@property --baz{syntax: "*"; inherits: false; initial-value: red;}

lightningcss ✗

@property --foo{syntax:"*";inherits:false}@property --baz{syntax:"*";inherits:false;initial-value:red}

sass ✗

@property --foo{syntax:"*";inherits:false}@property --bar{syntax:"*";initial-value:red}@property --baz{syntax:"*";inherits:false;initial-value:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0007 ✗ ✗ ✓ ✗ ✗ ✗ ✓ ✗
Details

Remove whitespace around syntax values in @property

An @property rule can have multiple values set for the syntax descriptor, separated by a pipe symbol (|). Whitespace adjacent to the pipe can be removed.

@property --foo {
  syntax: "<length> | <percentage>";
  inherits: false;
  initial-value: 16px;
}

Expected

@property --foo{syntax:"<length>|<percentage>";inherits:false;initial-value:16px}

Outputs

clean-css ✗

@property --foo{syntax:"<length> | <percentage>";inherits:false;initial-value:16px}

csskit ✗

@property --foo{syntax:"<length> | <percentage>";inherits:false;initial-value:16px}

csslop ✓

@property --foo{syntax:"<length>|<percentage>";inherits:false;initial-value:16px}

cssnano ✗

@property --foo{syntax:"<length> | <percentage>";inherits:false;initial-value:16px}

csso ✗

@property --foo{syntax:"<length> | <percentage>";inherits:false;initial-value:16px}

esbuild ✗

@property --foo{syntax: "<length> | <percentage>"; inherits: false; initial-value: 16px;}

lightningcss ✓

@property --foo{syntax:"<length>|<percentage>";inherits:false;initial-value:16px}

sass ✗

@property --foo{syntax:"<length> | <percentage>";inherits:false;initial-value:16px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0008 ✗ ✗ ✓ ✓ ✗ ✗ ✓ ✗
Details

Custom property value can be minified with @property constraint

When @property declares syntax: "<color>", the value is parsed as a color at parse time. The serialization is well-defined, so rgb(0 0 0) can be safely minified to #000.

@property --brand-color {
  syntax: "<color>";
  inherits: false;
  initial-value: #000;
}
a {
  --brand-color: rgb(0 0 0);
}

Expected

@property --brand-color{syntax:"<color>";inherits:false;initial-value:#000}a{--brand-color:#000}

Outputs

clean-css ✗

@property --brand-color{syntax:"<color>";inherits:false;initial-value:#000}a{--brand-color:rgb(0 0 0)}

csskit ✗

@property --brand-color{syntax:"<color>";inherits:false;initial-value:#000}a{--brand-color:rgb(0 0 0)}

csslop ✓

@property --brand-color{syntax:"<color>";inherits:false;initial-value:#000}a{--brand-color:#000}

cssnano ✓

@property --brand-color{syntax:"<color>";inherits:false;initial-value:#000}a{--brand-color:#000}

csso ✗

@property --brand-color{syntax:"<color>";inherits:false;initial-value:#000}a{--brand-color:rgb(0 0 0)}

esbuild ✗

@property --brand-color{syntax: "<color>"; inherits: false; initial-value: #000;}a{--brand-color: rgb(0 0 0)}

lightningcss ✓

@property --brand-color{syntax:"<color>";inherits:false;initial-value:#000}a{--brand-color:#000}

sass ✗

@property --brand-color{syntax:"<color>";inherits:false;initial-value:#000}a{--brand-color: rgb(0 0 0)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0009 ✓ ✓ ✓ ✓ ✓ ✗ ✗ ✗
Details

Registered <integer> custom properties must keep number type

--x is registered with <integer> syntax, so 100.0, which has a <number> type, is invalid and --x takes its initial value of 0. Rewriting it to 100 would make the value valid and change behaviour. 1e2 keeps the <number> type, so it's also acceptable.

@property --x {
  syntax: "<integer>";
  inherits: false;
  initial-value: 0;
}
a {
  --x: 100.0;
}

Expected

@property --x{syntax:"<integer>";inherits:false;initial-value:0}a{--x:100.0}

Also accepted

@property --x{syntax:"<integer>";inherits:false;initial-value:0}a{--x:1e2}

Outputs

clean-css ✓

@property --x{syntax:"<integer>";inherits:false;initial-value:0}a{--x:100.0}

csskit ✓

@property --x{syntax:"<integer>";inherits:false;initial-value:0}a{--x:1e2}

csslop ✓

@property --x{syntax:"<integer>";inherits:false;initial-value:0}a{--x:100.0}

cssnano ✓

@property --x{syntax:"<integer>";inherits:false;initial-value:0}a{--x:100.0}

csso ✓

@property --x{syntax:"<integer>";inherits:false;initial-value:0}a{--x:100.0}

esbuild ✗

@property --x{syntax: "<integer>"; inherits: false; initial-value: 0;}a{--x: 100}

lightningcss ✗

@property --x{syntax:"<integer>";inherits:false;initial-value:0}a{--x:100}

sass ✗

@property --x{syntax:"<integer>";inherits:false;initial-value:0}a{--x: 100.0}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 4 / 9 4 / 9 9 / 9 5 / 9 4 / 9 0 / 9 4 / 9 2 / 9
Percent 44.44% 44.44% 100% 55.55% 44.44% 0% 44.44% 22.22%
Duration 1ms 1ms 1ms 7ms 1ms 4ms 1ms 2ms

scope #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✗ ✓ ✓ ✗ ✗ ✓ ✓ ✗
Details

@scope whitespace removal

Basic whitespace removal in @scope. The space between @scope and the opening parenthesis can be removed.

@scope (.card) {
  .title {
    color: red;
  }
}

Expected

@scope(.card){.title{color:red}}

Outputs

clean-css ✗

csskit ✓

@scope(.card){.title{color:red}}

csslop ✓

@scope(.card){.title{color:red}}

cssnano ✗

@scope (.card){.title{color:red}}

csso ✗

@scope (.card){.title{color:red}}

esbuild ✓

@scope(.card){.title{color:red}}

lightningcss ✓

@scope(.card){.title{color:red}}

sass ✗

@scope (.card){.title{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✗ ✓ ✓ ✗ ✗ ✓ ✗ ✗
Details

@scope with proximity limit

@scope (.card) to (.card .content) uses a scope limit. Whitespace around the parentheses can be removed but the space between to and ( must be preserved to avoid to( being tokenized as a function token.

@scope (.card) to (.card .content) {
  a {
    color: red;
  }
}

Expected

@scope(.card)to (.card .content){a{color:red}}

Outputs

clean-css ✗

csskit ✓

@scope(.card)to (.card .content){a{color:red}}

csslop ✓

@scope(.card)to (.card .content){a{color:red}}

cssnano ✗

@scope (.card) to (.card .content){a{color:red}}

csso ✗

@scope (.card) to (.card .content){a{color:red}}

esbuild ✓

@scope(.card)to (.card .content){a{color:red}}

lightningcss ✗

@scope(.card) to (.card .content){a{color:red}}

sass ✗

@scope (.card) to (.card .content){a{color:red}}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✓ ✓ ✓ ✓ ✓ ✗ ✗ ✗
Details

Empty @scope removal

An empty @scope block with no rules can be removed entirely.

@scope (.card) {
}

Expected

Outputs

clean-css ✓

csskit ✓

csslop ✓

cssnano ✓

csso ✓

esbuild ✗

@scope(.card){}

lightningcss ✗

@scope(.card){}

sass ✗

@scope (.card){}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 1 / 3 3 / 3 3 / 3 1 / 3 1 / 3 2 / 3 1 / 3 0 / 3
Percent 33.33% 100% 100% 33.33% 33.33% 66.66% 33.33% 0%
Duration 1ms 1ms 1ms 3ms 1ms 1ms 1ms 1ms

selectors #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✓ ✗ ✓ ✓ ✗ ✓ ✓ ✗
Details

nth-child 2n+1 to odd

2n+1 is the definition of odd. The keyword form is shorter.

a:nth-child(2n + 1) {
  color: red;
}

Expected

a:nth-child(odd){color:red}

Outputs

clean-css ✓

a:nth-child(odd){color:red}

csskit ✗

a:nth-child(2n+ 1){color:red}

csslop ✓

a:nth-child(odd){color:red}

cssnano ✓

a:nth-child(odd){color:red}

csso ✗

a:nth-child(2n+1){color:red}

esbuild ✓

a:nth-child(odd){color:red}

lightningcss ✓

a:nth-child(odd){color:red}

sass ✗

a:nth-child(2n+1){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✗ ✗ ✓ ✗ ✗ ✓ ✓ ✗
Details

nth-child redundant +0 removal

2n+0 simplifies to 2n. The +0 offset is redundant.

a:nth-child(2n + 0) {
  color: red;
}

Expected

a:nth-child(2n){color:red}

Outputs

clean-css ✗

a:nth-child(2n+0){color:red}

csskit ✗

a:nth-child(2n+ 0){color:red}

csslop ✓

a:nth-child(2n){color:red}

cssnano ✗

a:nth-child(2n+0){color:red}

csso ✗

a:nth-child(2n+0){color:red}

esbuild ✓

a:nth-child(2n){color:red}

lightningcss ✓

a:nth-child(2n){color:red}

sass ✗

a:nth-child(2n+0){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✗ ✓ ✓ ✓ ✓ ✓ ✓ ✗
Details

nth-child positive sign removal

+5 is the same as 5. The redundant positive sign should be stripped.

a:nth-child(+5) {
  color: red;
}

Expected

a:nth-child(5){color:red}

Outputs

clean-css ✗

a:nth-child(+5){color:red}

csskit ✓

a:nth-child(5){color:red}

csslop ✓

a:nth-child(5){color:red}

cssnano ✓

a:nth-child(5){color:red}

csso ✓

a:nth-child(5){color:red}

esbuild ✓

a:nth-child(5){color:red}

lightningcss ✓

a:nth-child(5){color:red}

sass ✗

a:nth-child(+5){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✗ ✗ ✓ ✗ ✗ ✓ ✓ ✗
Details

nth-child zero-step simplification

0n+3 simplifies to just 3. The zero-step term is redundant.

a:nth-child(0n + 3) {
  color: red;
}

Expected

a:nth-child(3){color:red}

Outputs

clean-css ✗

a:nth-child(0n+3){color:red}

csskit ✗

a:nth-child(0n+ 3){color:red}

csslop ✓

a:nth-child(3){color:red}

cssnano ✗

a:nth-child(0n+3){color:red}

csso ✗

a:nth-child(0n+3){color:red}

esbuild ✓

a:nth-child(3){color:red}

lightningcss ✓

a:nth-child(3){color:red}

sass ✗

a:nth-child(0n+3){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

nth-child(2n) preserved

2n is already the shortest form. Unlike 2n+1 -> odd, there is no shorter keyword for 2n (even is the same length). Minifiers should preserve 2n as-is.

a:nth-child(2n) {
  color: red;
}

Expected

a:nth-child(2n){color:red}

Outputs

clean-css ✓

a:nth-child(2n){color:red}

csskit ✓

a:nth-child(2n){color:red}

csslop ✓

a:nth-child(2n){color:red}

cssnano ✓

a:nth-child(2n){color:red}

csso ✓

a:nth-child(2n){color:red}

esbuild ✓

a:nth-child(2n){color:red}

lightningcss ✓

a:nth-child(2n){color:red}

sass ✓

a:nth-child(2n){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✓ ✗ ✓ ✓ ✗ ✗ ✓ ✗
Details

nth-child(1) to first-child

:nth-child(1) is equivalent to :first-child, which is shorter.

a:nth-child(1) {
  color: red;
}

Expected

a:first-child{color:red}

Outputs

clean-css ✓

a:first-child{color:red}

csskit ✗

a:nth-child(1){color:red}

csslop ✓

a:first-child{color:red}

cssnano ✓

a:first-child{color:red}

csso ✗

a:nth-child(1){color:red}

esbuild ✗

a:nth-child(1){color:red}

lightningcss ✓

a:first-child{color:red}

sass ✗

a:nth-child(1){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0007 ✓ ✗ ✓ ✓ ✗ ✗ ✓ ✗
Details

nth-last-child(1) to last-child

:nth-last-child(1) is equivalent to :last-child, which is shorter.

a:nth-last-child(1) {
  color: red;
}

Expected

a:last-child{color:red}

Outputs

clean-css ✓

a:last-child{color:red}

csskit ✗

a:nth-last-child(1){color:red}

csslop ✓

a:last-child{color:red}

cssnano ✓

a:last-child{color:red}

csso ✗

a:nth-last-child(1){color:red}

esbuild ✗

a:nth-last-child(1){color:red}

lightningcss ✓

a:last-child{color:red}

sass ✗

a:nth-last-child(1){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0008 ✗ ✗ ✓ ✗ ✓ ✓ ✓ ✗
Details

:nth-child(1n) shorthand

:nth-child(1n) (equivalently :nth-child(n)) matches every child element. The pseudo-class could be removed entirely, going from a:nth-child(1n) to a, however, that would change the level of specificity for the selector, which could result in different styles being applied. For correctness, :nth-child(1n) should become :nth-child(n), because it is shorter, but retains the same specificity.

a:nth-child(1n) {
  color: red;
}

Expected

a:nth-child(n){color:red}

Validate

Outputs

clean-css ✗

a:nth-child(1n){color:red}

csskit ✗

a:nth-child(1n){color:red}

csslop ✓

a:nth-child(n){color:red}

cssnano ✗

a:nth-child(1n){color:red}

csso ✓

a:nth-child(n){color:red}

esbuild ✓

a:nth-child(n){color:red}

lightningcss ✓

a:nth-child(n){color:red}

sass ✗

a:nth-child(1n){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0009 ✓ ✗ ✓ ✓ ✗ ✗ ✓ ✗
Details

:nth-of-type(1) to :first-of-type

:nth-of-type(1) is equivalent to :first-of-type and the latter is shorter.

a:nth-of-type(1) {
  color: red;
}

Expected

a:first-of-type{color:red}

Outputs

clean-css ✓

a:first-of-type{color:red}

csskit ✗

a:nth-of-type(1){color:red}

csslop ✓

a:first-of-type{color:red}

cssnano ✓

a:first-of-type{color:red}

csso ✗

a:nth-of-type(1){color:red}

esbuild ✗

a:nth-of-type(1){color:red}

lightningcss ✓

a:first-of-type{color:red}

sass ✗

a:nth-of-type(1){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0010 ✓ ✗ ✓ ✓ ✗ ✗ ✓ ✗
Details

:nth-last-of-type(1) to :last-of-type

:nth-last-of-type(1) is equivalent to :last-of-type and the latter is shorter.

a:nth-last-of-type(1) {
  color: red;
}

Expected

a:last-of-type{color:red}

Outputs

clean-css ✓

a:last-of-type{color:red}

csskit ✗

a:nth-last-of-type(1){color:red}

csslop ✓

a:last-of-type{color:red}

cssnano ✓

a:last-of-type{color:red}

csso ✗

a:nth-last-of-type(1){color:red}

esbuild ✗

a:nth-last-of-type(1){color:red}

lightningcss ✓

a:last-of-type{color:red}

sass ✗

a:nth-last-of-type(1){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0011 ✗ ✗ ✓ ✓ ✗ ✓ ✓ ✗
Details

Double-colon to single-colon pseudo-element

::before can be shortened to :before for CSS2.1 pseudo-elements.

a::before {
  content: "x";
}

Expected

a:before{content:"x"}

Outputs

clean-css ✗

a::before{content:"x"}

csskit ✗

a::before{content:"x"}

csslop ✓

a:before{content:"x"}

cssnano ✓

a:before{content:"x"}

csso ✗

a::before{content:"x"}

esbuild ✓

a:before{content:"x"}

lightningcss ✓

a:before{content:"x"}

sass ✗

a::before{content:"x"}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0012 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Universal selector preservation

The * selector must be preserved as-is, not removed or altered.

* {
  margin: 0;
}

Expected

*{margin:0}

Outputs

clean-css ✓

*{margin:0}

csskit ✓

*{margin:0}

csslop ✓

*{margin:0}

cssnano ✓

*{margin:0}

csso ✓

*{margin:0}

esbuild ✓

*{margin:0}

lightningcss ✓

*{margin:0}

sass ✓

*{margin:0}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0013 ✓ ✗ ✓ ✓ ✓ ✗ ✓ ✗
Details

Redundant universal selector before ID

*#id is equivalent to #id. The universal selector is implied.

*#id {
  color: red;
}

Expected

#id{color:red}

Outputs

clean-css ✓

#id{color:red}

csskit ✗

*#id{color:red}

csslop ✓

#id{color:red}

cssnano ✓

#id{color:red}

csso ✓

#id{color:red}

esbuild ✗

*#id{color:red}

lightningcss ✓

#id{color:red}

sass ✗

*#id{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0014 ✓ ✗ ✓ ✓ ✓ ✓ ✓ ✓
Details

Attribute selector quote removal

Quotes around attribute values can be removed when the value is a valid identifier.

a[href="foo"] {
  color: red;
}

Expected

a[href=foo]{color:red}

Outputs

clean-css ✓

a[href=foo]{color:red}

csskit ✗

a[href="foo"]{color:red}

csslop ✓

a[href=foo]{color:red}

cssnano ✓

a[href=foo]{color:red}

csso ✓

a[href=foo]{color:red}

esbuild ✓

a[href=foo]{color:red}

lightningcss ✓

a[href=foo]{color:red}

sass ✓

a[href=foo]{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0015 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

::view-transition-group must keep double colon

::view-transition-group() is a modern pseudo-element and must NOT be shortened to a single colon. The :: -> : shortening is only valid for CSS2.1 pseudo-elements (::before, ::after, etc.).

::view-transition-group(header) {
  animation-duration: 0.3s;
}

Expected

::view-transition-group(header){animation-duration:.3s}

Outputs

clean-css ✓

::view-transition-group(header){animation-duration:.3s}

csskit ✓

::view-transition-group(header){animation-duration:.3s}

csslop ✓

::view-transition-group(header){animation-duration:.3s}

cssnano ✓

::view-transition-group(header){animation-duration:.3s}

csso ✓

::view-transition-group(header){animation-duration:.3s}

esbuild ✓

::view-transition-group(header){animation-duration:.3s}

lightningcss ✓

::view-transition-group(header){animation-duration:.3s}

sass ✓

::view-transition-group(header){animation-duration:.3s}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0016 ✗ ✗ ✓ ✗ ✗ ✗ ✓ ✗
Details

Escape singular space in attribute selector value

When an attribute selector's value contains a single space, the quotes can be removed and the space can be escaped to reduce character count.

[class="foo bar"] {
  color: red;
}

Expected

[class=foo\ bar]{color:red}

Outputs

clean-css ✗

[class="foo bar"]{color:red}

csskit ✗

[class="foo bar"]{color:red}

csslop ✓

[class=foo\ bar]{color:red}

cssnano ✗

[class="foo bar"]{color:red}

csso ✗

[class="foo bar"]{color:red}

esbuild ✗

[class="foo bar"]{color:red}

lightningcss ✓

[class=foo\ bar]{color:red}

sass ✗

[class="foo bar"]{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0017 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

Multiple spaces in attribute value remain quoted

When an attribute selector's value contains multiple spaces, the quotes surrounding them must remain in tact to be valid syntax. The spaces should not be escaped, because it is equal or fewer characters to keep them quoted.

[title="a b c d"] {
  color: red;
}

Expected

[title="a b c d"]{color:red}

Outputs

clean-css ✓

[title="a b c d"]{color:red}

csskit ✓

[title="a b c d"]{color:red}

csslop ✓

[title="a b c d"]{color:red}

cssnano ✓

[title="a b c d"]{color:red}

csso ✓

[title="a b c d"]{color:red}

esbuild ✓

[title="a b c d"]{color:red}

lightningcss ✓

[title="a b c d"]{color:red}

sass ✓

[title="a b c d"]{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0018 ✗ ✗ ✓ ✗ ✗ ✗ ✓ ✗
Details

Remove usesless :is()

If a :is() function only contains one element, and there is no comma-separated list of other selectors, then the :is offers no value and can be removed from the rule.

:is(.x) :is(:unknown) {
  color: red;
}

Expected

.x :unknown{color:red}

Outputs

clean-css ✗

:is(.x) :is(:unknown){color:red}

csskit ✗

:is(.x) :is(:unknown){color:red}

csslop ✓

.x :unknown{color:red}

cssnano ✗

:is(.x) :is(:unknown){color:red}

csso ✗

:is(.x) :is(:unknown){color:red}

esbuild ✗

:is(.x) :is(:unknown){color:red}

lightningcss ✓

.x :unknown{color:red}

sass ✗

:is(.x) :is(:unknown){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0019 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Remove usesless :is(), but retain useful :is()

When any part of a selector is not recognized by the browser, the entire rule gets ignored, unless the unrecognized portion is wrapped by a :is() function. Selectors that are clearly recognizable by the browser (class, id, :hover, etc) that are wrapped by an :is() without any other selectors can be unwrapped. However, if a browser could potentially not recognize a selector wrapped in an :is(), and there is a comma separated list of other selectors that would be effected by the rule being ignored if the :is was removed, then the wrapper must be retained to protect the rule.

:is(.x) :is(:unknown),
.y {
  color: red;
}

Expected

.x :is(:unknown),.y{color:red}

Outputs

clean-css ✗

.y,:is(.x) :is(:unknown){color:red}

csskit ✗

:is(.x) :is(:unknown),.y{color:red}

csslop ✓

.x :is(:unknown),.y{color:red}

cssnano ✗

.y,:is(.x) :is(:unknown){color:red}

csso ✗

.y,:is(.x) :is(:unknown){color:red}

esbuild ✗

:is(.x) :is(:unknown),.y{color:red}

lightningcss ✗

.x :unknown,.y{color:red}

sass ✗

:is(.x) :is(:unknown),.y{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0020 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Remove usesless :is() around pseudo-classes

If an :is() wraps well-known pseudo-classes (:hover, :required, etc), it can safely be removed. The selectors have the same level of specificity. and there is no risk of the browser ignoring the rule because the selectors are common.

:is(:hover, :visited) {
  color: red;
}

Expected

:hover,:visited{color:red}

Outputs

clean-css ✗

:is(:hover,:visited){color:red}

csskit ✗

:is(:hover,:visited){color:red}

csslop ✓

:hover,:visited{color:red}

cssnano ✗

:is(:hover,:visited){color:red}

csso ✗

:is(:hover,:visited){color:red}

esbuild ✗

:is(:hover,:visited){color:red}

lightningcss ✗

:is(:hover,:visited){color:red}

sass ✗

:is(:hover,:visited){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0021 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

An+B numbers must not use scientific notation

The An+B microsyntax only accepts integers, so 1000n+1000000 cannot be written as 1e3n+1e6. 1e3n is a dimension with a non-integer type and invalidates the selector.

a:nth-child(1000n+1000000) {
  color: red;
}
b:nth-child(1000000) {
  color: tan;
}

Expected

a:nth-child(1000n+1000000){color:red}b:nth-child(1000000){color:tan}

Outputs

clean-css ✓

a:nth-child(1000n+1000000){color:red}b:nth-child(1000000){color:tan}

csskit ✓

a:nth-child(1000n+1000000){color:red}b:nth-child(1000000){color:tan}

csslop ✓

a:nth-child(1000n+1000000){color:red}b:nth-child(1000000){color:tan}

cssnano ✓

a:nth-child(1000n+1000000){color:red}b:nth-child(1000000){color:tan}

csso ✓

a:nth-child(1000n+1000000){color:red}b:nth-child(1000000){color:tan}

esbuild ✓

a:nth-child(1000n+1000000){color:red}b:nth-child(1000000){color:tan}

lightningcss ✓

a:nth-child(1000n+1000000){color:red}b:nth-child(1000000){color:tan}

sass ✓

a:nth-child(1000n+1000000){color:red}b:nth-child(1000000){color:tan}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 12 / 21 6 / 21 21 / 21 14 / 21 9 / 21 12 / 21 19 / 21 6 / 21
Percent 57.14% 28.57% 100% 66.66% 42.85% 57.14% 90.47% 28.57%
Duration 1ms 1ms 3ms 17ms 1ms 9ms 1ms 6ms

selectors-advanced #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

:is() decomposition with equal-specificity selectors

:is(a, b) can be decomposed to a,b when all selectors are widely supported and share the same specificity. This is safe because :is() takes the highest specificity of its arguments, which equals each individual selector here.

:is( a , b ) {
  color: red;
}

Expected

a,b{color:red}

Outputs

clean-css ✗

:is( a ,b ){color:red}

csskit ✗

:is(a,b){color:red}

csslop ✓

a,b{color:red}

cssnano ✗

:is(a,b){color:red}

csso ✗

:is(a,b){color:red}

esbuild ✗

:is(a,b){color:red}

lightningcss ✗

:is(a,b){color:red}

sass ✗

:is(a,b){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

:is() must not decompose with mixed specificity

:is(#a, .b) cannot be decomposed to #a,.b because :is() takes the highest specificity of its arguments. Both .b and #a match with (1,0,0) inside :is(), but decomposed .b would only have (0,1,0).

:is(#a, .b) {
  color: red;
}

Expected

:is(#a,.b){color:red}

Outputs

clean-css ✓

:is(#a,.b){color:red}

csskit ✓

:is(#a,.b){color:red}

csslop ✓

:is(#a,.b){color:red}

cssnano ✓

:is(#a,.b){color:red}

csso ✓

:is(#a,.b){color:red}

esbuild ✓

:is(#a,.b){color:red}

lightningcss ✓

:is(#a,.b){color:red}

sass ✓

:is(#a,.b){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✗ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

:has() whitespace removal

Whitespace inside :has() around combinators can be removed, same as regular selector lists.

a:has(> b) {
  color: red;
}

Expected

a:has(>b){color:red}

Outputs

clean-css ✗

a:has(> b){color:red}

csskit ✓

a:has(>b){color:red}

csslop ✓

a:has(>b){color:red}

cssnano ✓

a:has(>b){color:red}

csso ✓

a:has(>b){color:red}

esbuild ✓

a:has(>b){color:red}

lightningcss ✓

a:has(>b){color:red}

sass ✓

a:has(>b){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

:where() whitespace removal

Whitespace inside :where() around the selector list commas can be removed. :where() itself must not be replaced with :is() as they differ in specificity (:where() is zero-specificity).

:where(.foo, .bar) {
  color: red;
}

Expected

:where(.foo,.bar){color:red}

Outputs

clean-css ✓

:where(.foo,.bar){color:red}

csskit ✓

:where(.foo,.bar){color:red}

csslop ✓

:where(.foo,.bar){color:red}

cssnano ✓

:where(.foo,.bar){color:red}

csso ✓

:where(.foo,.bar){color:red}

esbuild ✓

:where(.foo,.bar){color:red}

lightningcss ✓

:where(.foo,.bar){color:red}

sass ✓

:where(.foo,.bar){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

input:not(:invalid) to input:valid

On form elements :valid and :invalid are a complete partition -- every input is one or the other. So input:not(:invalid) can be replaced with the shorter input:valid. This only holds when the type selector restricts to elements that participate in constraint validation (input, textarea, button, etc). It does not apply to classes that could be applied to multiple element types. For example, div:not(:invalid) selects all divs, however div:valid selects none.

button:not(:invalid),
fieldset:not(:invalid),
form:not(:invalid),
input:not(:invalid),
select:not(:invalid),
textarea:not(:invalid),
div:not(:invalid),
custom-element:not(:invalid),
.foo:not(:invalid) {
  color: red;
}

Expected

button:valid,fieldset:valid,form:valid,input:valid,select:valid,textarea:valid,div:not(:invalid),custom-element:not(:invalid),.foo:not(:invalid){color:red}

Outputs

clean-css ✗

.foo:not(:invalid),button:not(:invalid),custom-element:not(:invalid),div:not(:invalid),fieldset:not(:invalid),form:not(:invalid),input:not(:invalid),select:not(:invalid),textarea:not(:invalid){color:red}

csskit ✗

button:not(:invalid),fieldset:not(:invalid),form:not(:invalid),input:not(:invalid),select:not(:invalid),textarea:not(:invalid),div:not(:invalid),custom-element:not(:invalid),.foo:not(:invalid){color:red}

csslop ✓

button:valid,fieldset:valid,form:valid,input:valid,select:valid,textarea:valid,div:not(:invalid),custom-element:not(:invalid),.foo:not(:invalid){color:red}

cssnano ✗

.foo:not(:invalid),button:not(:invalid),custom-element:not(:invalid),div:not(:invalid),fieldset:not(:invalid),form:not(:invalid),input:not(:invalid),select:not(:invalid),textarea:not(:invalid){color:red}

csso ✗

.foo:not(:invalid),button:not(:invalid),custom-element:not(:invalid),div:not(:invalid),fieldset:not(:invalid),form:not(:invalid),input:not(:invalid),select:not(:invalid),textarea:not(:invalid){color:red}

esbuild ✗

button:not(:invalid),fieldset:not(:invalid),form:not(:invalid),input:not(:invalid),select:not(:invalid),textarea:not(:invalid),div:not(:invalid),custom-element:not(:invalid),.foo:not(:invalid){color:red}

lightningcss ✗

button:not(:invalid),fieldset:not(:invalid),form:not(:invalid),input:not(:invalid),select:not(:invalid),textarea:not(:invalid),div:not(:invalid),custom-element:not(:invalid),.foo:not(:invalid){color:red}

sass ✗

button:not(:invalid),fieldset:not(:invalid),form:not(:invalid),input:not(:invalid),select:not(:invalid),textarea:not(:invalid),div:not(:invalid),custom-element:not(:invalid),.foo:not(:invalid){color:red}
1ms
3ms
1ms
2ms
1ms
1ms
1ms
1ms
0006 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

:not(:dir(ltr)) to :dir(rtl)

Every element has exactly one directionality -- ltr or rtl. The two values are a complete partition, so :not(:dir(ltr)) is equivalent to :dir(rtl).

a:not(:dir(ltr)) {
  color: red;
}

Expected

a:dir(rtl){color:red}

Outputs

clean-css ✗

a:not(:dir(ltr)){color:red}

csskit ✗

a:not(:dir(ltr)){color:red}

csslop ✓

a:dir(rtl){color:red}

cssnano ✗

a:not(:dir(ltr)){color:red}

csso ✗

a:not(:dir(ltr)){color:red}

esbuild ✗

a:not(:dir(ltr)){color:red}

lightningcss ✗

a:not(:dir(ltr)){color:red}

sass ✗

a:not(:dir(ltr)){color:red}
1ms
1ms
1ms
2ms
1ms
1ms
1ms
1ms
0007 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Double :not() cancellation

:not(:not(X)) is logically equivalent to X. The double negation can be removed, producing a shorter selector.

a:not(:not(.active)) {
  color: red;
}

Expected

a.active{color:red}

Outputs

clean-css ✗

a:not(:not(.active)){color:red}

csskit ✗

a:not(:not(.active)){color:red}

csslop ✓

a.active{color:red}

cssnano ✗

a:not(:not(.active)){color:red}

csso ✗

a:not(:not(.active)){color:red}

esbuild ✗

a:not(:not(.active)){color:red}

lightningcss ✗

a:not(:not(.active)){color:red}

sass ✗

a:not(:not(.active)){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0008 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

input:not(:enabled) to input:disabled

On form-associated elements :enabled and :disabled are a complete partition. input:not(:enabled) can be replaced with the shorter input:disabled.

input:not(:enabled) {
  color: red;
}

Expected

input:disabled{color:red}

Outputs

clean-css ✗

input:not(:enabled){color:red}

csskit ✗

input:not(:enabled){color:red}

csslop ✓

input:disabled{color:red}

cssnano ✗

input:not(:enabled){color:red}

csso ✗

input:not(:enabled){color:red}

esbuild ✗

input:not(:enabled){color:red}

lightningcss ✗

input:not(:enabled){color:red}

sass ✗

input:not(:enabled){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0009 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

input:not(:required) to input:optional

On form-associated elements :required and :optional are a complete partition. input:not(:required) can be replaced with input:optional.

input:not(:required) {
  color: red;
}

Expected

input:optional{color:red}

Outputs

clean-css ✗

input:not(:required){color:red}

csskit ✗

input:not(:required){color:red}

csslop ✓

input:optional{color:red}

cssnano ✗

input:not(:required){color:red}

csso ✗

input:not(:required){color:red}

esbuild ✗

input:not(:required){color:red}

lightningcss ✗

input:not(:required){color:red}

sass ✗

input:not(:required){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0010 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

a:not(:link) to a:visited

On hyperlink elements (<a>, <area>, <link> with href) :link and :visited are a complete partition. a:not(:link) can be replaced with the shorter a:visited. However, this should not apply to non-hyperlink elements (<div>, <h1>, etc), and should not apply to non-tag selectors, for example, a class could be applied to both <a class="x"> and <div class="x">. HREF attribute selectors should only receive this minification if they have a qualifying element of a, area, or link.

a:not(:link),
area:not(:link),
link:not(:link),
.foo:not(:link),
h1:not(:link),
[href]:not(:link),
[href="/foo.html#bar"]:not(:link),
a[href]:not(:link),
area[href="/foo.html#bar"]:not(:link),
:where(:not(:link)),
a:where(:not(:link)) {
  color: red;
}

Expected

a:visited,area:visited,link:visited,.foo:not(:link),h1:not(:link),[href]:not(:link),[href="/foo.html#bar"]:not(:link),a[href]:visited,area[href="/foo.html#bar"]:visited,:where(:not(:link)),a:where(:visited){color:red}

Outputs

clean-css ✗

.foo:not(:link),:where(:not(:link)),[href="/foo.html#bar"]:not(:link),[href]:not(:link),a:not(:link),a:where(:not(:link)),a[href]:not(:link),area:not(:link),area[href="/foo.html#bar"]:not(:link),h1:not(:link),link:not(:link){color:red}

csskit ✗

a:not(:link),area:not(:link),link:not(:link),.foo:not(:link),h1:not(:link),[href]:not(:link),[href="/foo.html#bar"]:not(:link),a[href]:not(:link),area[href="/foo.html#bar"]:not(:link),:where(:not(:link)),a:where(:not(:link)){color:red}

csslop ✓

a:visited,area:visited,link:visited,.foo:not(:link),h1:not(:link),[href]:not(:link),[href="/foo.html#bar"]:not(:link),a[href]:visited,area[href="/foo.html#bar"]:visited,:where(:not(:link)),a:where(:visited){color:red}

cssnano ✗

.foo:not(:link),:where(:not(:link)),[href="/foo.html#bar"]:not(:link),[href]:not(:link),a:not(:link),a:where(:not(:link)),a[href]:not(:link),area:not(:link),area[href="/foo.html#bar"]:not(:link),h1:not(:link),link:not(:link){color:red}

csso ✗

.foo:not(:link),:where(:not(:link)),[href="/foo.html#bar"]:not(:link),[href]:not(:link),a:not(:link),a:where(:not(:link)),a[href]:not(:link),area:not(:link),area[href="/foo.html#bar"]:not(:link),h1:not(:link),link:not(:link){color:red}

esbuild ✗

a:not(:link),area:not(:link),link:not(:link),.foo:not(:link),h1:not(:link),[href]:not(:link),[href="/foo.html#bar"]:not(:link),a[href]:not(:link),area[href="/foo.html#bar"]:not(:link),:where(:not(:link)),a:where(:not(:link)){color:red}

lightningcss ✗

a:not(:link),area:not(:link),link:not(:link),.foo:not(:link),h1:not(:link),[href]:not(:link),[href="/foo.html#bar"]:not(:link),a[href]:not(:link),area[href="/foo.html#bar"]:not(:link),:where(:not(:link)),a:where(:not(:link)){color:red}

sass ✗

a:not(:link),area:not(:link),link:not(:link),.foo:not(:link),h1:not(:link),[href]:not(:link),[href="/foo.html#bar"]:not(:link),a[href]:not(:link),area[href="/foo.html#bar"]:not(:link),:where(:not(:link)),a:where(:not(:link)){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0011 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

:is(:link, :visited) to :any-link

:any-link is equivalent to :is(:link, :visited) and is shorter. It matches any element that is a hyperlink source anchor (unvisited or visited).

:is(:link, :visited) {
  color: red;
}

Expected

:any-link{color:red}

Outputs

clean-css ✗

:is(:link,:visited){color:red}

csskit ✗

:is(:link,:visited){color:red}

csslop ✓

:any-link{color:red}

cssnano ✗

:is(:link,:visited){color:red}

csso ✗

:is(:link,:visited){color:red}

esbuild ✗

:is(:link,:visited){color:red}

lightningcss ✗

:is(:link,:visited){color:red}

sass ✗

:is(:link,:visited){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0012 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

:is() scoped :not(:required) to :optional

When :is() restricts to form-associated elements, :required and :optional are a complete partition. :is(textarea, input):not(:required) can be replaced with :is(textarea, input):optional.

:is(textarea, input):not(:required) {
  color: red;
}

Expected

:is(textarea,input):optional{color:red}

Outputs

clean-css ✗

:is(textarea,input):not(:required){color:red}

csskit ✗

:is(textarea,input):not(:required){color:red}

csslop ✓

:is(textarea,input):optional{color:red}

cssnano ✗

:is(textarea,input):not(:required){color:red}

csso ✗

:is(textarea,input):not(:required){color:red}

esbuild ✗

:is(textarea,input):not(:required){color:red}

lightningcss ✗

:is(textarea,input):not(:required){color:red}

sass ✗

:is(textarea,input):not(:required){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0013 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

h1-h6 is not changed to :heading

h1,h2,h3,h4,h5,h6 can be replaced with :heading per CSS Selectors Level 5. The :heading pseudo-class matches any element with a heading level. However, its specificity is that of a class (0 1 0). Replacing the H1-H6 tags that have a lower specificity (0 0 1), with :heading may override styles that come later in the CSSOM, including other files or inserted styles from browser extensions. For correctness, a minifier should not perform this optimization.

To achieve the same level of specificity with :heading you would need to lower its specificity with :where, then wrap it in an :is with one of the heading tags, so it receives the same level as it: :is(h1,:where(:heading)), which works, but is longer than just using h1,h2,h3,h4,h5,h6.

h1, h2, h3, h4, h5, h6 {
  color: red;
}

Expected

h1,h2,h3,h4,h5,h6{color:red}

Validate

Outputs

clean-css ✓

h1,h2,h3,h4,h5,h6{color:red}

csskit ✓

h1,h2,h3,h4,h5,h6{color:red}

csslop ✓

h1,h2,h3,h4,h5,h6{color:red}

cssnano ✓

h1,h2,h3,h4,h5,h6{color:red}

csso ✓

h1,h2,h3,h4,h5,h6{color:red}

esbuild ✓

h1,h2,h3,h4,h5,h6{color:red}

lightningcss ✓

h1,h2,h3,h4,h5,h6{color:red}

sass ✓

h1,h2,h3,h4,h5,h6{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0014 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Sorting :is() selectors

Selector minification in :is can be complex. To keep expectations consistent the order should be alphabetized. This also increases the liklihood of text repetition, giving better compression in gzip/brotli.

:is(h2, a, h1, .foo, :visited, p, .example, .bar) {
  color: red;
}

Expected

:is(.bar,.example,.foo,:visited,a,h1,h2,p){color:red}

Outputs

clean-css ✗

:is(h2,a,h1,.foo,:visited,p,.example,.bar){color:red}

csskit ✗

:is(h2,a,h1,.foo,:visited,p,.example,.bar){color:red}

csslop ✓

:is(.bar,.example,.foo,:visited,a,h1,h2,p){color:red}

cssnano ✗

:is(h2,a,h1,.foo,:visited,p,.example,.bar){color:red}

csso ✗

:is(h2,a,h1,.foo,:visited,p,.example,.bar){color:red}

esbuild ✗

:is(h2,a,h1,.foo,:visited,p,.example,.bar){color:red}

lightningcss ✗

:is(h2,a,h1,.foo,:visited,p,.example,.bar){color:red}

sass ✗

:is(h2,a,h1,.foo,:visited,p,.example,.bar){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0015 ✗ ✗ ✓ ✓ ✗ ✓ ✗ ✗
Details

De-dupe selectors in :is()

Duplicate selectors in :is() serve no purpose and can be safely removed.

:is(.foo, .foo, h1, h1) {
  color: red;
}

Expected

:is(.foo,h1){color:red}

Outputs

clean-css ✗

:is(.foo,.foo,h1,h1){color:red}

csskit ✗

:is(.foo,.foo,h1,h1){color:red}

csslop ✓

:is(.foo,h1){color:red}

cssnano ✓

:is(.foo,h1){color:red}

csso ✗

:is(.foo,.foo,h1,h1){color:red}

esbuild ✓

:is(.foo,h1){color:red}

lightningcss ✗

:is(.foo,.foo,h1,h1){color:red}

sass ✗

:is(.foo,.foo,h1,h1){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0016 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Retaining correct specificity in :is

In 0011 (:is(:link, :visited) to :any-link), we can safely remove the :is because there are no other selectors inside it. But in this test, we must keep the :any-link inside the :is, because :is adopts the specificity of the most specific selector inside it.

/* :is has specificity of 010 */
:is(:link,:visited,:where(h1)){color:red}

/* :is has specificity of 000 */
:any-link,:is(:where(h1)){color:red}

/* :is has specificity of 010 */
:is(:any-link,:where(h1)){color:red}

The changing in specificity may effect the pixels painted to the screen. This test ensures correctness in the minification.

:is(:visited, :link, :where(.link)) {
  color: red;
}

Expected

:is(:any-link,:where(.link)){color:red}

Outputs

clean-css ✗

:is(:visited,:link,:where(.link)){color:red}

csskit ✗

:is(:visited,:link,:where(.link)){color:red}

csslop ✓

:is(:any-link,:where(.link)){color:red}

cssnano ✗

:is(:visited,:link,:where(.link)){color:red}

csso ✗

:is(:visited,:link,:where(.link)){color:red}

esbuild ✗

:is(:visited,:link,:where(.link)){color:red}

lightningcss ✗

:is(:visited,:link,:where(.link)){color:red}

sass ✗

:is(:visited,:link,:where(.link)){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0017 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Advanced :is() selector combination

This test combines the following :is-related tests:

  • selectors-advanced/0011 - :is(:link, :visited) to :any-link
  • selectors-advanced/0014 - Sorting :is() selectors
  • selectors-advanced/0015 - De-dupe selectors in :is()
  • selectors-advanced/0016 - Retaining correct specificity in :is

:is(h2, :link, h1, :visited, h1, :any-link, div) {
  color: red;
}

Expected

:is(:any-link,div,h1,h2){color:red}

Outputs

clean-css ✗

:is(h2,:link,h1,:visited,h1,:any-link,div){color:red}

csskit ✗

:is(h2,:link,h1,:visited,h1,:any-link,div){color:red}

csslop ✓

:is(:any-link,div,h1,h2){color:red}

cssnano ✗

:is(h2,:link,h1,:visited,:any-link,div){color:red}

csso ✗

:is(h2,:link,h1,:visited,h1,:any-link,div){color:red}

esbuild ✗

:is(h2,:link,h1,:visited,:any-link,div){color:red}

lightningcss ✗

:is(h2,:link,h1,:visited,h1,:any-link,div){color:red}

sass ✗

:is(h2,:link,h1,:visited,h1,:any-link,div){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0018 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

:where() compound merge

Adjacent :where(A):where(B) with single selectors merges to :where(AB). Saves exactly 8 chars (one :where() wrapper). :where() contributes zero specificity either way, and A and B must both match simultaneously.

:where(.foo):where([bar]) {
  color: red;
}

Expected

:where(.foo[bar]){color:red}

Outputs

clean-css ✗

:where(.foo):where([bar]){color:red}

csskit ✗

:where(.foo):where([bar]){color:red}

csslop ✓

:where(.foo[bar]){color:red}

cssnano ✗

:where(.foo):where([bar]){color:red}

csso ✗

:where(.foo):where([bar]){color:red}

esbuild ✗

:where(.foo):where([bar]){color:red}

lightningcss ✗

:where(.foo):where([bar]){color:red}

sass ✗

:where(.foo):where([bar]){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0019 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

:where() merge when shorter

:where(A):where(B,C) merges to :where(AB,AC) when the cartesian product is shorter. Here the saved :where() wrapper (8 chars) outweighs the cost of duplicating A across 2 selectors. The break even point is the product of the combined selectors needs to be less than 8.

:where(.foo):where(.bar, .baz) {
  color: red;
}

Expected

:where(.foo.bar,.foo.baz){color:red}

Outputs

clean-css ✗

:where(.foo):where(.bar,.baz){color:red}

csskit ✗

:where(.foo):where(.bar,.baz){color:red}

csslop ✓

:where(.foo.bar,.foo.baz){color:red}

cssnano ✗

:where(.foo):where(.bar,.baz){color:red}

csso ✗

:where(.foo):where(.bar,.baz){color:red}

esbuild ✗

:where(.foo):where(.bar,.baz){color:red}

lightningcss ✗

:where(.foo):where(.bar,.baz){color:red}

sass ✗

:where(.foo):where(.bar,.baz){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0020 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

:where() don't merge when longer

:where(.foo):where(.a,.b,.c,.d) should NOT be merged: the cartesian product :where(.foo.a,.foo.b,.foo.c,.foo.d) is 35 chars vs 31 chars unmerged. Merging always saves 8 chars of wrapper overhead but costs extra chars from duplicating the first selector; here 4*(4-1)=12 > 8 so keep it is more efficient to keep them separate.

:where(.foo):where(.a, .b, .c, .d) {
  color: red;
}

Expected

:where(.foo):where(.a,.b,.c,.d){color:red}

Outputs

clean-css ✓

:where(.foo):where(.a,.b,.c,.d){color:red}

csskit ✓

:where(.foo):where(.a,.b,.c,.d){color:red}

csslop ✓

:where(.foo):where(.a,.b,.c,.d){color:red}

cssnano ✓

:where(.foo):where(.a,.b,.c,.d){color:red}

csso ✓

:where(.foo):where(.a,.b,.c,.d){color:red}

esbuild ✓

:where(.foo):where(.a,.b,.c,.d){color:red}

lightningcss ✓

:where(.foo):where(.a,.b,.c,.d){color:red}

sass ✓

:where(.foo):where(.a,.b,.c,.d){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0021 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

:where() merge with type selector reordering

:where(:hover):where(a) merges to :where(a:hover), not :where(:hover a). A type selector must come first in a compound selector. Naive string concatenation might produce :where(:hover a) which is a complex selector (descendant combinator) with different semantics.

:where(:hover):where(a) {
  color: red;
}

Expected

:where(a:hover){color:red}

Outputs

clean-css ✗

:where(:hover):where(a){color:red}

csskit ✗

:where(:hover):where(a){color:red}

csslop ✓

:where(a:hover){color:red}

cssnano ✗

:where(:hover):where(a){color:red}

csso ✗

:where(:hover):where(a){color:red}

esbuild ✗

:where(:hover):where(a){color:red}

lightningcss ✗

:where(:hover):where(a){color:red}

sass ✗

:where(:hover):where(a){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0022 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
Details

:where() with conflicting type selectors - no merge

:where(div):where(span) cannot be merged: a compound selector cannot contain two type selectors. The selector already matches nothing (no element is both div and span), but the correct output is to leave it unmerged rather than produce invalid CSS.

:where(div):where(span) {
  color: red;
}

Expected

:where(div):where(span){color:red}

Outputs

clean-css ✓

:where(div):where(span){color:red}

csskit ✓

:where(div):where(span){color:red}

csslop ✓

:where(div):where(span){color:red}

cssnano ✓

:where(div):where(span){color:red}

csso ✓

:where(div):where(span){color:red}

esbuild ✓

:where(div):where(span){color:red}

lightningcss ✓

:where(div):where(span){color:red}

sass ✓

:where(div):where(span){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0023 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Remove :is after de-duping selectors

Repeated selectors in a :is() can be removed. If all selectors have the same level of specificity, and are known to be browser-safe, the :is() can be removed too.

:is(div, span, div, span) {
  color: red;
}
:is(.bar, .foo, .bar, .foo) {
  color: tan;
}

Expected

div,span{color:red}.bar,.foo{color:tan}

Outputs

clean-css ✗

:is(div,span,div,span){color:red}:is(.bar,.foo,.bar,.foo){color:tan}

csskit ✗

:is(div,span,div,span){color:red}:is(.bar,.foo,.bar,.foo){color:tan}

csslop ✓

div,span{color:red}.bar,.foo{color:tan}

cssnano ✗

:is(div,span){color:red}:is(.bar,.foo){color:tan}

csso ✗

:is(div,span,div,span){color:red}:is(.bar,.foo,.bar,.foo){color:tan}

esbuild ✗

:is(div,span){color:red}:is(.bar,.foo){color:tan}

lightningcss ✗

:is(div,span,div,span){color:red}:is(.bar,.foo,.bar,.foo){color:tan}

sass ✗

:is(div,span,div,span){color:red}:is(.bar,.foo,.bar,.foo){color:tan}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0024 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Remove :is after de-duping selectors with custom tags

Repeated selectors in a :is() can be removed. If all selectors have the same level of specificity, and are known to be browser-safe, the :is() can be removed too.

:is(
  custom-component,
  custom-component,
  div,
  div
) {
  color: red;
}

Expected

custom-component,div{color:red}

Outputs

clean-css ✗

:is(
custom-component,custom-component,div,div
){color:red}

csskit ✗

:is(custom-component,custom-component,div,div){color:red}

csslop ✓

custom-component,div{color:red}

cssnano ✗

:is(custom-component,div){color:red}

csso ✗

:is(custom-component,custom-component,div,div){color:red}

esbuild ✗

:is(custom-component,div){color:red}

lightningcss ✗

:is(custom-component,custom-component,div,div){color:red}

sass ✗

:is(custom-component,custom-component,div,div){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0025 ✗ ✗ ✓ ✓ ✗ ✓ ✗ ✗
Details

Retain :is after de-duping selectors if not all selectors are browser-safe

Repeated selectors in a :is() can be removed. If a selector is not recognized as being browser-safe the :is() must not be removed, as all selectors for the rule would then be ignored by the browser.

:is(
  :foo,
  :foo,
  :hover,
  :hover
) {
  color: red;
}

Expected

:is(:foo,:hover){color:red}

Outputs

clean-css ✗

:is(
:foo,:foo,:hover,:hover
){color:red}

csskit ✗

:is(:foo,:foo,:hover,:hover){color:red}

csslop ✓

:is(:foo,:hover){color:red}

cssnano ✓

:is(:foo,:hover){color:red}

csso ✗

:is(:foo,:foo,:hover,:hover){color:red}

esbuild ✓

:is(:foo,:hover){color:red}

lightningcss ✗

:is(:foo,:foo,:hover,:hover){color:red}

sass ✗

:is(:foo,:foo,:hover,:hover){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0026 ✗ ✗ ✓ ✗ ✓ ✗ ✗ ✗
Details

Remove selector from list in rule when it is fully overridden later

If a selector is in a group of selectors on a rule, and all properties in that rule are overridden for that selector later, it is safe to remove it from the earlier list.

h1,
h2,
h3,
.foo {
  color: red;
}
h2 {
  color: tan;
}
.foo {
  color: #123;
  padding: 1px;
}

Expected

h1,h3{color:red}h2{color:tan}.foo{color:#123;padding:1px}

Outputs

clean-css ✗

.foo,h1,h2,h3{color:red}h2{color:tan}.foo{color:#123;padding:1px}

csskit ✗

h1,h2,h3,.foo{color:red}h2{color:tan}.foo{color:#123;padding:1px}

csslop ✓

h1,h3{color:red}h2{color:tan}.foo{color:#123;padding:1px}

cssnano ✗

.foo,h1,h2,h3{color:red}h2{color:tan}.foo{color:#123;padding:1px}

csso ✓

h1,h3{color:red}h2{color:tan}.foo{color:#123;padding:1px}

esbuild ✗

h1,h2,h3,.foo{color:red}h2{color:tan}.foo{color:#123;padding:1px}

lightningcss ✗

h1,h2,h3,.foo{color:red}h2{color:tan}.foo{color:#123;padding:1px}

sass ✗

h1,h2,h3,.foo{color:red}h2{color:tan}.foo{color:#123;padding:1px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0027 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ERROR
Details

Discard invalid selectors using double pipes

A pipe in a selector can be used for namespacing. However, two pipes are invalid syntax and will cause the entire rule to be ignored by the browser. If the two rules in this example are merged, then both will be ignored by the browser (unless wrapped in :is()). Since the double pipes rule will be ignored, it is safe to remove it during minification. The url() wrapper in the @namespace can be removed as well, if the quotation marks around the URL are retained. A space is not required between the name and quoated URL.

References:

@namespace svg url("http://www.w3.org/2000/svg");

svg|a {
  color: red;
}

svg||a {
  color: red;
}

Expected

@namespace svg"http://www.w3.org/2000/svg";svg|a{color:red}

Outputs

clean-css ✗

@namespace svg url("http://www.w3.org/2000/svg");svg|a,svg||a{color:red}

csskit ✗

@namespace svg"http://www.w3.org/2000/svg";svg|a{color:red}svg||a{color:red}

csslop ✓

@namespace svg"http://www.w3.org/2000/svg";svg|a{color:red}

cssnano ✗

@namespace svg "http://www.w3.org/2000/svg";svg|a{color:red}svg||a{color:red}

csso ✗

@namespace svg url(http://www.w3.org/2000/svg);svg|a{color:red}

esbuild ✗

@namespace svg url(http://www.w3.org/2000/svg);svg|a{color:red}svg||a{color:red}

lightningcss ✗

@namespace svg "http://www.w3.org/2000/svg";svg|a{color:red}

sass ✗

Expected identifier.
  ╷
7 │ svg||a {
  │     ^
  ╵
  - 7:5  root stylesheet
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0028 ✗ ✗ ✓ ✗ ✗ ✗ ✓ ERROR
Details

Discard rules with unescaped spaces in attribute selector

If a selector is an attribute selector with a space that is not quoted and it is not escaped, it is considered invalid by the browser and the entire rule is ignored. A minifier should not merge these rules, as that would cause both to be ignored. Since the second rule in this example is ignored by the browser it is safe to remove it completely.

[href] {
  color: red;
}
[a b] {
  color: red;
}

Expected

[href]{color:red}

Outputs

clean-css ✗

[ab],[href]{color:red}

csskit ✗

[href]{color:red}[a b]{color:red}

csslop ✓

[href]{color:red}

cssnano ✗

[href]{color:red}[a b]{color:red}

csso ✗

[href]{color:red}[a b]{color:red}

esbuild ✗

[href]{color:red}[a b]{color:red}

lightningcss ✓

[href]{color:red}

sass ✗

Expected "]".
  ╷
4 │ [a b] {
  │    ^
  ╵
  - 4:4  root stylesheet
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0029 ✗ ✗ ✓ ✗ ✓ ✗ ✓ ERROR
Details

Discard selectors that end in colon

A selector that ends in a colon is invalid and ignored by the browser. If a minifier merges these rules (a,a: hover{color:red}) it will cause both to be ignored by the browser. Leaving them separate is safe, however it is also safe to remove the ignored rule completely.

a {
  color: red;
}
a: hover {
  color: red;
}

Expected

a{color:red}

Outputs

clean-css ✗

a{color:red}a: hover{color:red}

csskit ✗

a{color:red}a:hover{color:red}

csslop ✓

a{color:red}

cssnano ✗

a{color:red}a: hover{color:red}

csso ✓

a{color:red}

esbuild ✗

a{color:red}a: hover{color:red}

lightningcss ✓

a{color:red}

sass ✗

Expected identifier.
  ╷
4 │ a: hover {
  │   ^
  ╵
  - 4:3  root stylesheet
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0030 ✗ ✗ ✓ ✗ ✗ ✗ ✗ ✗
Details

Combine nested selectors with parent using &

In this example, we want the wrapping element (.foo) to receive the same styles as its children. We can nest all the children under the parent and then add a & selector to apply the same styles to the parent as well.

.foo,
.foo blockquote,
.foo code,
.foo em,
.foo h1,
.foo pre {
  color: red;
}

Expected

.foo{&,blockquote,code,em,h1,pre{color:red}}

Outputs

clean-css ✗

.foo,.foo blockquote,.foo code,.foo em,.foo h1,.foo pre{color:red}

csskit ✗

.foo,.foo blockquote,.foo code,.foo em,.foo h1,.foo pre{color:red}

csslop ✓

.foo{&,blockquote,code,em,h1,pre{color:red}}

cssnano ✗

.foo,.foo :is(blockquote,code,em,h1,pre){color:red}

csso ✗

.foo,.foo blockquote,.foo code,.foo em,.foo h1,.foo pre{color:red}

esbuild ✗

.foo,.foo blockquote,.foo code,.foo em,.foo h1,.foo pre{color:red}

lightningcss ✗

.foo,.foo blockquote,.foo code,.foo em,.foo h1,.foo pre{color:red}

sass ✗

.foo,.foo blockquote,.foo code,.foo em,.foo h1,.foo pre{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0031 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✗
Details

Selectors with escaped special characters

This test has some Tailwind-inspired selectors with escapes in them. A minifier should not remove the escapes, or misinterpret the special characters and try to set up nesting.

.hover\:outline-whiteInverted\/90:hover {
  outline-color: #ffffffe6;
}
.hover\:outline-whiteInverted\/95:hover {
  outline-color: #fffffff2;
}

Expected

.hover\:outline-whiteInverted\/90:hover{outline-color:#ffffffe6}.hover\:outline-whiteInverted\/95:hover{outline-color:#fffffff2}

Validate

Outputs

clean-css ✓

.hover\:outline-whiteInverted\/90:hover{outline-color:#ffffffe6}.hover\:outline-whiteInverted\/95:hover{outline-color:#fffffff2}

csskit ✓

.hover\:outline-whiteInverted\/90:hover{outline-color:#ffffffe6}.hover\:outline-whiteInverted\/95:hover{outline-color:#fffffff2}

csslop ✓

.hover\:outline-whiteInverted\/90:hover{outline-color:#ffffffe6}.hover\:outline-whiteInverted\/95:hover{outline-color:#fffffff2}

cssnano ✓

.hover\:outline-whiteInverted\/90:hover{outline-color:#ffffffe6}.hover\:outline-whiteInverted\/95:hover{outline-color:#fffffff2}

csso ✓

.hover\:outline-whiteInverted\/90:hover{outline-color:#ffffffe6}.hover\:outline-whiteInverted\/95:hover{outline-color:#fffffff2}

esbuild ✓

.hover\:outline-whiteInverted\/90:hover{outline-color:#ffffffe6}.hover\:outline-whiteInverted\/95:hover{outline-color:#fffffff2}

lightningcss ✓

.hover\:outline-whiteInverted\/90:hover{outline-color:#ffffffe6}.hover\:outline-whiteInverted\/95:hover{outline-color:#fffffff2}

sass ✗

.hover\:outline-whiteInverted\/90:hover{outline-color:rgba(255,255,255,.9019607843)}.hover\:outline-whiteInverted\/95:hover{outline-color:rgba(255,255,255,.9490196078)}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0032 ✓ ✗ ✓ ✓ ✓ ✓ ✓ ✓
Details

Single-value attribute selector with case-insensitively

In this example the attribute selector has a value that does not contain spaces. Making the quotes optional. The value is also followed by i to indicate it is case-insensitive. Since the value is not in quotes, a space must precede i.

[aria-hidden="false" i] {
  display: block;
}

Expected

[aria-hidden=false i]{display:block}

Outputs

clean-css ✓

[aria-hidden=false i]{display:block}

csskit ✗

[aria-hidden="false"i]{display:block}

csslop ✓

[aria-hidden=false i]{display:block}

cssnano ✓

[aria-hidden=false i]{display:block}

csso ✓

[aria-hidden=false i]{display:block}

esbuild ✓

[aria-hidden=false i]{display:block}

lightningcss ✓

[aria-hidden=false i]{display:block}

sass ✓

[aria-hidden=false i]{display:block}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0033 ✓ ✓ ✓ ✗ ✓ ✗ ✗ ✓
Details

Attribute selector with case-insensitive value containing spaces

In this example the attribute selector has a value that contains multiple spaces. Though you could escape each space, it is shorter to keep the value in quotes. The value is followed by i to indicate it is case-insensitive. Since the value is in quotes, a space before the i is not needed.

[title="lorem ipsum dolar sit amet" i] {
  color: red;
}

Expected

[title="lorem ipsum dolar sit amet"i]{color:red}

Outputs

clean-css ✓

[title="lorem ipsum dolar sit amet"i]{color:red}

csskit ✓

[title="lorem ipsum dolar sit amet"i]{color:red}

csslop ✓

[title="lorem ipsum dolar sit amet"i]{color:red}

cssnano ✗

[title="lorem ipsum dolar sit amet" i]{color:red}

csso ✓

[title="lorem ipsum dolar sit amet"i]{color:red}

esbuild ✗

[title="lorem ipsum dolar sit amet" i]{color:red}

lightningcss ✗

[title="lorem ipsum dolar sit amet" i]{color:red}

sass ✓

[title="lorem ipsum dolar sit amet"i]{color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0034 ✗ ✗ ✓ ✗ ERROR ✗ ✗ ERROR
Details

Remove nth-child rules without arguments

The pseudo-class :nth-child expects at least one argument. If it is not given any arguments, then it is considered an invalid selector and the entire rule will be ignored (unless the selector is wrapped with :is()).

li {
  color: red;
}
.a, li:nth-child {
    color: tan;
}
.b, li:nth-child() {
    color: green;
}

Expected

li{color:red}

Outputs

clean-css ✗

li{color:red}.a,li:nth-child{color:tan}.b,li:nth-child(){color:green}

csskit ✗

li{color:red}.a,li:nth-child{color:tan}.b,li:nth-child(){color:green}

csslop ✓

li{color:red}

cssnano ✗

li{color:red}.a,li:nth-child{color:tan}.b, li:nth-child(){color:green}

csso ✗

Cannot read properties of null (reading 'first')

esbuild ✗

li{color:red}.a,li:nth-child{color:tan}.b,li:nth-child(){color:green}

lightningcss ✗

li{color:red}.a{color:tan}li:nth-child{color:tan}

sass ✗

Expected "n".
  ╷
7 │ .b, li:nth-child() {
  │                  ^
  ╵
  - 7:18  root stylesheet
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0035 ✓ ✗ ✓ ✓ ✗ ✓ ✓ ✗
Details

Replace even with 2n in nth-child()

The value of 2n naturally selects only even numbers making it equivalent to the even keyword in nth-child.

li:nth-child(even) {
  color: red;
}

Expected

li:nth-child(2n){color:red}

Outputs

clean-css ✓

li:nth-child(2n){color:red}

csskit ✗

li:nth-child(even){color:red}

csslop ✓

li:nth-child(2n){color:red}

cssnano ✓

li:nth-child(2n){color:red}

csso ✗

li:nth-child(even){color:red}

esbuild ✓

li:nth-child(2n){color:red}

lightningcss ✓

li:nth-child(2n){color:red}

sass ✗

li:nth-child(even){color:red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
Subtotal 9 / 35 8 / 35 35 / 35 11 / 35 11 / 35 11 / 35 11 / 35 8 / 35
Percent 25.71% 22.85% 100% 31.42% 31.42% 31.42% 31.42% 22.85%
Duration 3ms 4ms 4ms 33ms 3ms 16ms 1ms 14ms

shorthand-values #

testclean-csscsskitcsslopcssnanocssoesbuildlightningcsssass
0001 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✗
Details

margin 4-to-1 collapse

margin: 10px 10px 10px 10px collapses to margin:10px when all four values are identical.

a {
  margin: 10px 10px 10px 10px;
}

Expected

a{margin:10px}

Outputs

clean-css ✓

a{margin:10px}

csskit ✓

a{margin:10px}

csslop ✓

a{margin:10px}

cssnano ✓

a{margin:10px}

csso ✓

a{margin:10px}

esbuild ✓

a{margin:10px}

lightningcss ✓

a{margin:10px}

sass ✗

a{margin:10px 10px 10px 10px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0002 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✗
Details

margin 4-to-2 collapse

margin: 10px 20px 10px 20px collapses to margin:10px 20px when top/bottom and left/right pairs match.

a {
  margin: 10px 20px 10px 20px;
}

Expected

a{margin:10px 20px}

Outputs

clean-css ✓

a{margin:10px 20px}

csskit ✓

a{margin:10px 20px}

csslop ✓

a{margin:10px 20px}

cssnano ✓

a{margin:10px 20px}

csso ✓

a{margin:10px 20px}

esbuild ✓

a{margin:10px 20px}

lightningcss ✓

a{margin:10px 20px}

sass ✗

a{margin:10px 20px 10px 20px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0003 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✗
Details

margin 4-to-3 collapse

margin: 10px 20px 30px 20px collapses to margin:10px 20px 30px when left equals right.

a {
  margin: 10px 20px 30px 20px;
}

Expected

a{margin:10px 20px 30px}

Outputs

clean-css ✓

a{margin:10px 20px 30px}

csskit ✓

a{margin:10px 20px 30px}

csslop ✓

a{margin:10px 20px 30px}

cssnano ✓

a{margin:10px 20px 30px}

csso ✓

a{margin:10px 20px 30px}

esbuild ✓

a{margin:10px 20px 30px}

lightningcss ✓

a{margin:10px 20px 30px}

sass ✗

a{margin:10px 20px 30px 20px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0004 ✓ ✗ ✓ ✗ ✓ ✗ ✓ ✗
Details

background:none to background:0 0

background: none and background: 0 0 are equivalent. Both reset all background longhands to initial values -- 0 0 is parsed as background-position and all omitted longhands (including background-image) reset to their initial values. 0 0 is one byte shorter.

a {
  background: none;
}

Expected

a{background:0 0}

Outputs

clean-css ✓

a{background:0 0}

csskit ✗

a{background:none}

csslop ✓

a{background:0 0}

cssnano ✗

a{background:none}

csso ✓

a{background:0 0}

esbuild ✗

a{background:none}

lightningcss ✓

a{background:0 0}

sass ✗

a{background:none}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0005 ✗ ✓ ✓ ✗ ✗ ✗ ✗ ✗
Details

Color shortening and space removal before hash

border: 1px solid #000000 shortens the hex color to #000 and removes the space before # since # unambiguously starts a hash token -- no whitespace is needed to separate it from the preceding keyword.

a {
  border: 1px solid #000000;
}

Expected

a{border:1px solid#000}

Outputs

clean-css ✗

a{border:1px solid #000}

csskit ✓

a{border:1px solid#000}

csslop ✓

a{border:1px solid#000}

cssnano ✗

a{border:1px solid #000}

csso ✗

a{border:1px solid #000}

esbuild ✗

a{border:1px solid #000000}

lightningcss ✗

a{border:1px solid #000}

sass ✗

a{border:1px solid #000}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0006 ✗ ✓ ✓ ✓ ✗ ✓ ✓ ✗
Details

inset shorthand collapse + zero-unit strip

inset: 0px 0px 0px 0px collapses to inset:0. Combines 4-to-1 shorthand collapse with zero-unit stripping. The inset property follows the same pattern as margin/padding.

a {
  inset: 0px 0px 0px 0px;
}

Expected

a{inset:0}

Outputs

clean-css ✗

a{inset:0px 0px 0px 0px}

csskit ✓

a{inset:0}

csslop ✓

a{inset:0}

cssnano ✓

a{inset:0}

csso ✗

a{inset:0 0 0 0}

esbuild ✓

a{inset:0}

lightningcss ✓

a{inset:0}

sass ✗

a{inset:0px 0px 0px 0px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0007 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✗
Details

padding 4-value to 1-value collapse

padding: 10px 10px 10px 10px collapses to padding: 10px when all four values are identical.

a {
  padding: 10px 10px 10px 10px;
}

Expected

a{padding:10px}

Outputs

clean-css ✓

a{padding:10px}

csskit ✓

a{padding:10px}

csslop ✓

a{padding:10px}

cssnano ✓

a{padding:10px}

csso ✓

a{padding:10px}

esbuild ✓

a{padding:10px}

lightningcss ✓

a{padding:10px}

sass ✗

a{padding:10px 10px 10px 10px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0008 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✗
Details

padding 4-to-2 value collapse

When top equals bottom and right equals left, padding collapses from 4 values to 2.

a {
  padding: 5px 10px 5px 10px;
}

Expected

a{padding:5px 10px}

Outputs

clean-css ✓

a{padding:5px 10px}

csskit ✓

a{padding:5px 10px}

csslop ✓

a{padding:5px 10px}

cssnano ✓

a{padding:5px 10px}

csso ✓

a{padding:5px 10px}

esbuild ✓

a{padding:5px 10px}

lightningcss ✓

a{padding:5px 10px}

sass ✗

a{padding:5px 10px 5px 10px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0009 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✗
Details

padding 4-to-3 value collapse

When left equals right, the 4th value can be dropped. Top/bottom differ so 3 values remain.

a {
  padding: 5px 10px 15px 10px;
}

Expected

a{padding:5px 10px 15px}

Outputs

clean-css ✓

a{padding:5px 10px 15px}

csskit ✓

a{padding:5px 10px 15px}

csslop ✓

a{padding:5px 10px 15px}

cssnano ✓

a{padding:5px 10px 15px}

csso ✓

a{padding:5px 10px 15px}

esbuild ✓

a{padding:5px 10px 15px}

lightningcss ✓

a{padding:5px 10px 15px}

sass ✗

a{padding:5px 10px 15px 10px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0010 ✓ ✓ ✓ ✓ ✗ ✓ ✓ ✗
Details

border-radius 4-to-2 value collapse

border-radius follows the same top-right-bottom-left collapsing rules as margin/padding.

a {
  border-radius: 5px 10px 5px 10px;
}

Expected

a{border-radius:5px 10px}

Outputs

clean-css ✓

a{border-radius:5px 10px}

csskit ✓

a{border-radius:5px 10px}

csslop ✓

a{border-radius:5px 10px}

cssnano ✓

a{border-radius:5px 10px}

csso ✗

a{border-radius:5px 10px 5px 10px}

esbuild ✓

a{border-radius:5px 10px}

lightningcss ✓

a{border-radius:5px 10px}

sass ✗

a{border-radius:5px 10px 5px 10px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0011 ✓ ✓ ✓ ✓ ✗ ✓ ✓ ✗
Details

border-radius slash syntax collapse

When both horizontal and vertical radii have identical values across all 4 corners, each side collapses to 1 value. The / separator must be preserved.

a {
  border-radius: 10px 10px 10px 10px / 5px 5px 5px 5px;
}

Expected

a{border-radius:10px/5px}

Outputs

clean-css ✓

a{border-radius:10px/5px}

csskit ✓

a{border-radius:10px/5px}

csslop ✓

a{border-radius:10px/5px}

cssnano ✓

a{border-radius:10px/5px}

csso ✗

a{border-radius:10px 10px 10px 10px/5px 5px 5px 5px}

esbuild ✓

a{border-radius:10px/5px}

lightningcss ✓

a{border-radius:10px/5px}

sass ✗

a{border-radius:10px 10px 10px 10px/5px 5px 5px 5px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0012 ✗ ✓ ✓ ✓ ✗ ✓ ✓ ✗
Details

Inset 4-to-2 value collapse

The inset shorthand follows the same collapsing rules as margin/padding.

a {
  inset: 10px 20px 10px 20px;
}

Expected

a{inset:10px 20px}

Outputs

clean-css ✗

a{inset:10px 20px 10px 20px}

csskit ✓

a{inset:10px 20px}

csslop ✓

a{inset:10px 20px}

cssnano ✓

a{inset:10px 20px}

csso ✗

a{inset:10px 20px 10px 20px}

esbuild ✓

a{inset:10px 20px}

lightningcss ✓

a{inset:10px 20px}

sass ✗

a{inset:10px 20px 10px 20px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0013 ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✗
Details

Margin 2-to-1 value collapse

When both values in a 2-value margin are identical, collapse to a single value.

a {
  margin: 10px 10px;
}

Expected

a{margin:10px}

Outputs

clean-css ✓

a{margin:10px}

csskit ✓

a{margin:10px}

csslop ✓

a{margin:10px}

cssnano ✓

a{margin:10px}

csso ✓

a{margin:10px}

esbuild ✓

a{margin:10px}

lightningcss ✓

a{margin:10px}

sass ✗

a{margin:10px 10px}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0014 ✓ ✗ ✓ ✓ ✗ ✗ ✓ ✗
Details

Border default width omission

medium is the default border-width value and can be omitted from the border shorthand.

a {
  border: medium solid red;
}

Expected

a{border:solid red}

Outputs

clean-css ✓

a{border:solid red}

csskit ✗

a{border:medium solid red}

csslop ✓

a{border:solid red}

cssnano ✓

a{border:solid red}

csso ✗

a{border:medium solid red}

esbuild ✗

a{border:medium solid red}

lightningcss ✓

a{border:solid red}

sass ✗

a{border:medium solid red}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0015 ✗ ✗ ✓ ✗ ✗ ✗ ✓ ✗
Details

Background shorthand default omission

Default background-position (0% 0%), background-repeat (repeat), and background-attachment (scroll) can be omitted from the background shorthand.

a {
  background: red url(bg.png) 0% 0% repeat scroll;
}

Expected

a{background:red url(bg.png)}

Outputs

clean-css ✗

a{background:url(bg.png) red}

csskit ✗

a{background:url(bg.png)0% 0% repeat scroll red}

csslop ✓

a{background:red url(bg.png)}

cssnano ✗

a{background:red url(bg.png) 0 0 repeat scroll}

csso ✗

a{background:red url(bg.png)0 0}

esbuild ✗

a{background:red url(bg.png) 0% 0% repeat scroll}

lightningcss ✓

a{background:red url(bg.png)}

sass ✗

a{background:red url(bg.png) 0% 0% repeat scroll}
1ms
3ms
1ms
1ms
1ms
1ms
1ms
1ms
0016 ✓ ✗ ✓ ✗ ✓ ✗ ✓ ✗
Details

Font shorthand default value omission

normal is the default for both font-style and font-weight; both can be omitted from the font shorthand.

a {
  font: normal normal 16px/1.5 Arial, sans-serif;
}

Expected

a{font:16px/1.5 Arial,sans-serif}

Outputs

clean-css ✓

a{font:16px/1.5 Arial,sans-serif}

csskit ✗

a{font:normal normal 16px/1.5 Arial,sans-serif}

csslop ✓

a{font:16px/1.5 Arial,sans-serif}

cssnano ✗

a{font:normal normal 16px/1.5 Arial,sans-serif}

csso ✓

a{font:16px/1.5 Arial,sans-serif}

esbuild ✗

a{font: 16px/1.5 Arial,sans-serif}

lightningcss ✓

a{font:16px/1.5 Arial,sans-serif}

sass ✗

a{font:normal normal 16px/1.5 Arial,sans-serif}
1ms
1ms
1ms
1ms
1ms
1ms
1ms
1ms
0017 ✗ ✓ ✓ ✓ ✓ ✗ ✓ ✓
Details

Outline shorthand color optimization

Color values within shorthands like outline should still be optimized (#ff0000 -> red).

a {
  outline: 1px solid #ff0000;
}

Expected

a{outline