Monday, December 15, 2025
HomeLanguagesJavascriptFabric.js sourceFromHsl() Method

Fabric.js sourceFromHsl() Method

The sourceFromHsl() method is used to return an array representation of color for the specified color values in HSL (Hue-saturation-lightness) or HSLA (Hue-saturation-lightness-alpha) format.

Syntax:

sourceFromHsl(color)

Parameters: This method accepts a parameter as mentioned above and described below:

  • color: This parameter holds the specified color values in HSL or HSLA format.

Return Value: This method returns an array representation of values in RGBA (Red Green Blue and Alpha) format of the color for the specified color values in HSL or HSLA format.

Example 1:

HTML




<!DOCTYPE html>
<html>
  
<head>
  <!-- Adding the FabricJS library -->
  <script src=
  </script>
</head>
  
<body>
<script type="text/javascript">
  
 // Calling the sourceFromHsl() function over
 // the color value in HSL and HSLA format
 console.log(fabric.Color.sourceFromHsl("hsl(0, 100%, 50%)"));
 console.log(fabric.Color.sourceFromHsl("hsla(0, 100%, 50%, 0.6)"));
</script>
  
</body>
  
</html>


Output:

[255,0,0,1]
[255,0,0,0.6]

Example 2:

HTML




<!DOCTYPE html>
<html>
  
<head>
  <!-- Adding the FabricJS library -->
  <script src=
  </script>
</head>
  
<body>
<script type="text/javascript">
  
 // Initializing some color values in HSL format
 var A = "hsl(0, 100%, 50%)";
 var B = "hsl(0, 0%, 50%)";
   
 // Initializing some color values in HSLA format
 var C = "hsla(0, 100%, 50%, 0.9)";
 var D = "hsla(0, 0%, 50%, 0.2)";
  
 // Calling the sourceFromHsl() function over
 // the above color values
 console.log(fabric.Color.sourceFromHsl(A));
 console.log(fabric.Color.sourceFromHsl(B));
 console.log(fabric.Color.sourceFromHsl(C));
 console.log(fabric.Color.sourceFromHsl(D));
</script>
  
</body>
  
</html>


Output:

[255,0,0,1]
[128,128,128,1]
[255,0,0,0.9]
[128,128,128,0.2]
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32448 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6817 POSTS0 COMMENTS
Nicole Veronica
11954 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12031 POSTS0 COMMENTS
Shaida Kate Naidoo
6955 POSTS0 COMMENTS
Ted Musemwa
7202 POSTS0 COMMENTS
Thapelo Manthata
6899 POSTS0 COMMENTS
Umr Jansen
6884 POSTS0 COMMENTS