Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

Fabric.js toHexa() Method

  • Last Updated : 19 Mar, 2021

The toHexa() method is used to convert any type of the specified color representation to it’s HEXA (Hexadecimal alpha) representation.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

toHexa()

Parameters: This method does not accept any parameter.

Return Value: This method returns color representation in HEXA format.



Example 1:

HTML




<!DOCTYPE html>
<html>
  
<head>
  <!-- Adding the FabricJS library -->
  <script src=
  </script>
</head>
  
<body>
<script type="text/javascript">
  
 // Calling the toHexa() function over 
 // the specified color values
 console.log(new fabric.Color("rgb(10, 120, 150)").toHexa());
 console.log(new fabric.Color("hsl(5%, 10%, 250%)").toHexa());
</script>
  
</body>
  
</html>

Output:

0A7896FF
000000FF

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 different color format
 var A = "rgb(0, 12, 50)";
 var B = "rgba(10, 13, 250, 0.1)";
 var C = "hsl(0, 100%, 50%)";
 var D = "hsla(10%, 0, 0, 0.2)";
  
 // Calling the toHexa() function over 
 // the above specified color values
 console.log(new fabric.Color(A).toHexa());
 console.log(new fabric.Color(B).toHexa());
 console.log(new fabric.Color(C).toHexa());
 console.log(new fabric.Color(D).toHexa());
</script>
  
</body>
  
</html>

Output:

000C32FF
0A0DFA1A
FF0000FF
000000FF



My Personal Notes arrow_drop_up
Recommended Articles
Page :