Friday, December 12, 2025
HomeLanguagesJavascriptFabric.js fromHsla() Method

Fabric.js fromHsla() Method

The fromHsla() method is used to return a new color object for the specified color in HSLA(hue saturation lightness and alpha) format.

Syntax:

fromHsla(color)

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

  • color: This parameter holds the specified string color value in HSLA format.

Return Value: This method returns a new color object in the format of “RGBA(Red-Green-Blue-Alpha)” for the specified color in HSLA format.

Example 1:

Javascript




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


Output:

{"_source":[255,0,0,1]}

Example 2:

Javascript




<!DOCTYPE html>
<html>
  
<head>
  <!-- Adding the FabricJS library -->
  <script src=
  </script>
</head>
  
<body>
  <script type="text/javascript">
  
   // Initializing some color values in HSLA format
   var Black = "hsla(0, 0% ,0%, 0.1)";
   var Red = "hsla(0, 100%, 50%, 1.0)";
  
   // Calling the fromHsla() function over
   // the above specified color values
   console.log(fabric.Color.fromHsla(Black)); 
   console.log(fabric.Color.fromHsla(Red)); 
  </script>
</body>
  
</html>


Output:

{"_source":[0,0,0,0.1]}
{"_source":[255,0,0,1]}
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

Most Popular

Dominic
32444 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6813 POSTS0 COMMENTS
Nicole Veronica
11951 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12028 POSTS0 COMMENTS
Shaida Kate Naidoo
6945 POSTS0 COMMENTS
Ted Musemwa
7198 POSTS0 COMMENTS
Thapelo Manthata
6892 POSTS0 COMMENTS
Umr Jansen
6881 POSTS0 COMMENTS