Thursday, September 4, 2025
HomeLanguagesJavascriptFabric.js toHexa() Method

Fabric.js toHexa() Method

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

Syntax:

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
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
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS