Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Color Level 4: Computation of colors using Lab notation</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/support/computed-testcommon.js"></script>
</head>
<body>
<div id="container">
<div id="target"></div>
</div>
<style>
#container {
color: rgb(255, 0, 0);
}
</style>
<script>
// lab()
test_computed_value("color", "lab(0 0 0)", "lab(0 0 0)");
test_computed_value("color", "lab(0 0 0 / 1)", "lab(0 0 0)");
test_computed_value("color", "lab(0 0 0 / 0.5)", "lab(0 0 0 / 0.5)");
test_computed_value("color", "lab(20 0 10/0.5)", "lab(20 0 10 / 0.5)");
test_computed_value("color", "lab(20 0 10/50%)", "lab(20 0 10 / 0.5)");
test_computed_value("color", "lab(400 0 10/50%)", "lab(100 0 10 / 0.5)");
test_computed_value("color", "lab(50 -160 160)", "lab(50 -160 160)");
test_computed_value("color", "lab(50 -200 200)", "lab(50 -200 200)");
test_computed_value("color", "lab(0 0 0 / -10%)", "lab(0 0 0 / 0)");
test_computed_value("color", "lab(0 0 0 / 110%)", "lab(0 0 0)");
test_computed_value("color", "lab(0 0 0 / 300%)", "lab(0 0 0)");
test_computed_value("color", "lab(-40 0 0)", "lab(0 0 0)");
test_computed_value("color", "lab(50 -20 0)", "lab(50 -20 0)");
test_computed_value("color", "lab(50 0 -20)", "lab(50 0 -20)");
test_computed_value("color", "lab(calc(50 * 3) calc(0.5 - 1) calc(1.5) / calc(-0.5 + 1))", "lab(100 -0.5 1.5 / 0.5)");
test_computed_value("color", "lab(calc(-50 * 3) calc(0.5 + 1) calc(-1.5) / calc(-0.5 * 2))", "lab(0 1.5 -1.5 / 0)");
test_computed_value("color", "lab(none none none / none)", "lab(none none none / none)");
test_computed_value("color", "lab(none none none)", "lab(none none none)");
test_computed_value("color", "lab(20 none none / none)", "lab(20 none none / none)");
test_computed_value("color", "lab(none none none / 0.5)", "lab(none none none / 0.5)");
test_computed_value("color", "lab(0 0 0 / none)", "lab(0 0 0 / none)");
test_computed_value("color", "lab(calc(NaN) 0 0)", "lab(0 0 0)");
test_computed_value("color", "lab(calc(0 / 0) 0 0)", "lab(0 0 0)");
// oklab()
test_computed_value("color", "oklab(0 0 0)", "oklab(0 0 0)");
test_computed_value("color", "oklab(0 0 0 / 1)", "oklab(0 0 0)");
test_computed_value("color", "oklab(0 0 0 / 0.5)", "oklab(0 0 0 / 0.5)");
test_computed_value("color", "oklab(0.2 0 0.1/0.5)", "oklab(0.2 0 0.1 / 0.5)");
test_computed_value("color", "oklab(0.2 0 0.1/50%)", "oklab(0.2 0 0.1 / 0.5)");
test_computed_value("color", "oklab(4 0 0.1/50%)", "oklab(1 0 0.1 / 0.5)");
test_computed_value("color", "oklab(0.5 -1.6 1.6)", "oklab(0.5 -1.6 1.6)");
test_computed_value("color", "oklab(0.5 -2 2)", "oklab(0.5 -2 2)");
test_computed_value("color", "oklab(0 0 0 / -10%)", "oklab(0 0 0 / 0)");
test_computed_value("color", "oklab(0 0 0 / 110%)", "oklab(0 0 0)");
test_computed_value("color", "oklab(0 0 0 / 300%)", "oklab(0 0 0)");
test_computed_value("color", "oklab(-0.4 0 0)", "oklab(0 0 0)");
test_computed_value("color", "oklab(0.5 -0.2 0)", "oklab(0.5 -0.2 0)");
test_computed_value("color", "oklab(0.5 0 -0.2)", "oklab(0.5 0 -0.2)");
test_computed_value("color", "oklab(calc(0.5 * 3) calc(0.5 - 1) calc(1.5) / calc(-0.5 + 1))", "oklab(1 -0.5 1.5 / 0.5)");
test_computed_value("color", "oklab(calc(-0.5 * 3) calc(0.5 + 1) calc(-1.5) / calc(-0.5 * 2))", "oklab(0 1.5 -1.5 / 0)");
test_computed_value("color", "oklab(none none none / none)", "oklab(none none none / none)");
test_computed_value("color", "oklab(none none none)", "oklab(none none none)");
test_computed_value("color", "oklab(0.2 none none / none)", "oklab(0.2 none none / none)");
test_computed_value("color", "oklab(none none none / 0.5)", "oklab(none none none / 0.5)");
test_computed_value("color", "oklab(0 0 0 / none)", "oklab(0 0 0 / none)");
// These tests validate the ranges of lab() vs. oklab() components
test_computed_value("color", "lab(20% -50% 90%/0.5)", "lab(20 -62.5 112.5 / 0.5)");
test_computed_value("color", "oklab(20% 70% -80%/0.5)", "oklab(0.2 0.28 -0.32 / 0.5)");
test_computed_value("color", "oklab(calc(NaN) 0 0)", "oklab(0 0 0)");
test_computed_value("color", "oklab(calc(0 / 0) 0 0)", "oklab(0 0 0)");
// lch()
test_computed_value("color", "lch(0 0 0deg)", "lch(0 0 0)");
test_computed_value("color", "lch(0 0 0deg / 1)", "lch(0 0 0)");
test_computed_value("color", "lch(0 0 0deg / 0.5)", "lch(0 0 0 / 0.5)");
test_computed_value("color", "lch(100 230 0deg / 0.5)", "lch(100 230 0 / 0.5)");
test_computed_value("color", "lch(20 50 20deg/0.5)", "lch(20 50 20 / 0.5)");
test_computed_value("color", "lch(20 50 20deg/50%)", "lch(20 50 20 / 0.5)");
test_computed_value("color", "lch(10 20 20deg / -10%)", "lch(10 20 20 / 0)");
test_computed_value("color", "lch(10 20 20deg / 110%)", "lch(10 20 20)");
test_computed_value("color", "lch(10 20 1.28rad)", "lch(10 20 73.3386)");
test_computed_value("color", "lch(10 20 380deg)", "lch(10 20 20)");
test_computed_value("color", "lch(10 20 -340deg)", "lch(10 20 20)");
test_computed_value("color", "lch(10 20 740deg)", "lch(10 20 20)");
test_computed_value("color", "lch(10 20 -700deg)", "lch(10 20 20)");
test_computed_value("color", "lch(-40 0 0)", "lch(0 0 0)");
test_computed_value("color", "lch(20 -20 0)", "lch(20 0 0)");
test_computed_value("color", "lch(0 0 0 / 0.5)", "lch(0 0 0 / 0.5)");
test_computed_value("color", "lch(10 20 20 / 110%)", "lch(10 20 20)");
test_computed_value("color", "lch(10 20 -700)", "lch(10 20 20)");
test_computed_value("color", "lch(calc(50 * 3) calc(0.5 - 1) calc(20deg * 2) / calc(-0.5 + 1))", "lch(100 0 40 / 0.5)");
test_computed_value("color", "lch(calc(-50 * 3) calc(0.5 + 1) calc(-20deg * 2) / calc(-0.5 * 2))", "lch(0 1.5 320 / 0)");
test_computed_value("color", "lch(none none none / none)", "lch(none none none / none)");
test_computed_value("color", "lch(none none none)", "lch(none none none)");
test_computed_value("color", "lch(20 none none / none)", "lch(20 none none / none)");
test_computed_value("color", "lch(none none none / 0.5)", "lch(none none none / 0.5)");
test_computed_value("color", "lch(0 0 0 / none)", "lch(0 0 0 / none)");
test_computed_value("color", "lch(calc(NaN) 0 0)", "lch(0 0 0)");
test_computed_value("color", "lch(calc(0 / 0) 0 0)", "lch(0 0 0)");
// oklch()
test_computed_value("color", "oklch(0 0 0deg)", "oklch(0 0 0)");
test_computed_value("color", "oklch(0 0 0deg / 1)", "oklch(0 0 0)");
test_computed_value("color", "oklch(0 0 0deg / 0.5)", "oklch(0 0 0 / 0.5)");
test_computed_value("color", "oklch(1 2.3 0deg / 0.5)", "oklch(1 2.3 0 / 0.5)");
test_computed_value("color", "oklch(0.2 0.5 20deg/0.5)", "oklch(0.2 0.5 20 / 0.5)");
test_computed_value("color", "oklch(0.2 0.5 20deg/50%)", "oklch(0.2 0.5 20 / 0.5)");
test_computed_value("color", "oklch(0.1 0.2 20deg / -10%)", "oklch(0.1 0.2 20 / 0)");
test_computed_value("color", "oklch(0.1 0.2 20deg / 110%)", "oklch(0.1 0.2 20)");
test_computed_value("color", "oklch(0.1 0.2 1.28rad)", "oklch(0.1 0.2 73.3386)");
test_computed_value("color", "oklch(0.1 0.2 380deg)", "oklch(0.1 0.2 20)");
test_computed_value("color", "oklch(0.1 0.2 -340deg)", "oklch(0.1 0.2 20)");
test_computed_value("color", "oklch(0.1 0.2 740deg)", "oklch(0.1 0.2 20)");
test_computed_value("color", "oklch(0.1 0.2 -700deg)", "oklch(0.1 0.2 20)");
test_computed_value("color", "oklch(-0.4 0 0)", "oklch(0 0 0)");
test_computed_value("color", "oklch(0.2 -0.2 0)", "oklch(0.2 0 0)");
test_computed_value("color", "oklch(0 0 0 / 0.5)", "oklch(0 0 0 / 0.5)");
test_computed_value("color", "oklch(0.1 0.2 20 / 110%)", "oklch(0.1 0.2 20)");
test_computed_value("color", "oklch(0.1 0.2 -700)", "oklch(0.1 0.2 20)");
test_computed_value("color", "oklch(calc(0.5 * 3) calc(0.5 - 1) calc(20deg * 2) / calc(-0.5 + 1))", "oklch(1 0 40 / 0.5)");
test_computed_value("color", "oklch(calc(-0.5 * 3) calc(0.5 + 1) calc(-20deg * 2) / calc(-0.5 * 2))", "oklch(0 1.5 320 / 0)");
test_computed_value("color", "oklch(none none none / none)", "oklch(none none none / none)");
test_computed_value("color", "oklch(none none none)", "oklch(none none none)");
test_computed_value("color", "oklch(0.2 none none / none)", "oklch(0.2 none none / none)");
test_computed_value("color", "oklch(none none none / 0.5)", "oklch(none none none / 0.5)");
test_computed_value("color", "oklch(0 0 0 / none)", "oklch(0 0 0 / none)");
// These tests validate the ranges of lch() vs. oklch() lightness and chroma
test_computed_value("color", "lch(20% 80% 10/0.5)", "lch(20 120 10 / 0.5)");
test_computed_value("color", "oklch(20% 60% 10/0.5)", "oklch(0.2 0.24 10 / 0.5)");
test_computed_value("color", "oklch(calc(NaN) 0 0)", "oklch(0 0 0)");
test_computed_value("color", "oklch(calc(0 / 0) 0 0)", "oklch(0 0 0)");
</script>
</body>
</html>