Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Color Level 4: Parsing and serialization of colors using valid HSL notation</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/support/parsing-testcommon.js"></script>
</head>
<body>
<script>
test_valid_value("color", "hsl(120 30% 50%)", "rgb(89, 166, 89)");
test_valid_value("color", "hsl(120 30% 50% / 0.5)", "rgba(89, 166, 89, 0.5)");
test_valid_value("color", "hsl(none none none)", "rgb(0, 0, 0)");
test_valid_value("color", "hsl(0 0% 0%)", "rgb(0, 0, 0)");
test_valid_value("color", "hsl(none none none / none)", "rgba(0, 0, 0, 0)");
test_valid_value("color", "hsl(0 0% 0% / 0)", "rgba(0, 0, 0, 0)");
test_valid_value("color", "hsla(none none none)", "rgb(0, 0, 0)");
test_valid_value("color", "hsla(0 0% 0%)", "rgb(0, 0, 0)");
test_valid_value("color", "hsla(none none none / none)", "rgba(0, 0, 0, 0)");
test_valid_value("color", "hsla(0 0% 0% / 0)", "rgba(0, 0, 0, 0)");
test_valid_value("color", "hsl(120 none none)", "rgb(0, 0, 0)");
test_valid_value("color", "hsl(120 0% 0%)", "rgb(0, 0, 0)");
test_valid_value("color", "hsl(120 80% none)", "rgb(0, 0, 0)");
test_valid_value("color", "hsl(120 80% 0%)", "rgb(0, 0, 0)");
test_valid_value("color", "hsl(120 none 50%)", "rgb(128, 128, 128)");
test_valid_value("color", "hsl(120 0% 50%)", "rgb(128, 128, 128)");
test_valid_value("color", "hsl(120 100% 50% / none)", "rgba(0, 255, 0, 0)");
test_valid_value("color", "hsl(120 100% 50% / 0)", "rgba(0, 255, 0, 0)");
test_valid_value("color", "hsl(none 100% 50%)", "rgb(255, 0, 0)");
test_valid_value("color", "hsl(0 100% 50%)", "rgb(255, 0, 0)");
// Test with number components.
test_valid_value("color", "hsl(120 30 50)", "rgb(89, 166, 89)");
test_valid_value("color", "hsl(120 30 50 / 0.5)", "rgba(89, 166, 89, 0.5)");
test_valid_value("color", "hsl(120 30% 50)", "rgb(89, 166, 89)");
test_valid_value("color", "hsl(120 30% 50 / 0.5)", "rgba(89, 166, 89, 0.5)");
test_valid_value("color", "hsl(120 30 50%)", "rgb(89, 166, 89)");
test_valid_value("color", "hsl(120 30 50% / 0.5)", "rgba(89, 166, 89, 0.5)");
test_valid_value("color", "hsl(120 none 50)", "rgb(128, 128, 128)");
test_valid_value("color", "hsl(120 none 50 / 0.5)", "rgba(128, 128, 128, 0.5)");
test_valid_value("color", "hsl(120 30 none)", "rgb(0, 0, 0)");
test_valid_value("color", "hsl(120 30 none / 0.5)", "rgba(0, 0, 0, 0.5)");
test_valid_value("color", "hsl(120 30 50 / none)", "rgba(89, 166, 89, 0)");
// Test parse-time clamp of negative saturation to zero
test_valid_value("color", "hsl(0 -50% 40%)", "rgb(102, 102, 102)");
test_valid_value("color", "hsl(30 -50% 60)", "rgb(153, 153, 153)");
test_valid_value("color", "hsl(0 -50 40%)", "rgb(102, 102, 102)");
test_valid_value("color", "hsl(30 -50 60)", "rgb(153, 153, 153)");
// Test non-finite values. calc(infinity) goes to upper bound while calc(-infinity) and NaN go to the lower bound.
test_valid_value("color", "hsl(calc(infinity) 100% 50%)", "rgb(255, 0, 0)"); // hsl(360 100% 50%)
test_valid_value("color", "hsl(calc(-infinity) 100% 50%)", "rgb(255, 0, 0)"); // hsl(0 100% 50%)
test_valid_value("color", "hsl(calc(0 / 0) 100% 50%)", "rgb(255, 0, 0)"); // hsl(0 100% 50%)
test_valid_value("color", "hsl(90 50% 50% / calc(infinity))", "rgb(128, 191, 64)"); // hsl(90 50% 50%)
test_valid_value("color", "hsl(90 50% 50% / calc(-infinity))", "rgba(128, 191, 64, 0)"); // hsl(90 50% 50% / 0)
test_valid_value("color", "hsl(90 50% 50% / calc(0 / 0))", "rgba(128, 191, 64, 0)"); // hsl(90 50% 50% / 0)
</script>
</body>
</html>