Friday, January 16, 2026
HomeLanguagesJavascriptD3.js | color.opacity

D3.js | color.opacity

The color.opacity in D3.js is used to fade the color. The opacity value is in the range of [0, 1].

Syntax:

color.opacity

Parameters: This function does not accept any parameters.

Return Value: This function returns the opacity value of the specified color.

Below program illustrate the color.opacity function in D3.js:

Example:




<!DOCTYPE html>
<html>
  
<head>
    <title>color.rgb() function</title>
  
    <script src='https://d3js.org/d3.v4.min.js'>
  </script>
</head>
  
<body>
    <script>
        // Calling the d3.color() function
        // with some parameters
        var color1 = d3.color("red");
        var color2 = d3.color("green");
        var color3 = d3.color("blue");
  
        // Calling the color.opacity
        var A = color1.opacity;
        var B = color2.opacity;
        var C = color3.opacity;
  
        // Getting the opacity value
        console.log(A);
        console.log(B);
        console.log(C);
    </script>
</body>
  
</html>


Output:

1
1
1

Ref: https://devdocs.io/d3~5/d3-color#color_opacity

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
32474 POSTS0 COMMENTS
Milvus
117 POSTS0 COMMENTS
Nango Kala
6846 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12062 POSTS0 COMMENTS
Shaida Kate Naidoo
6985 POSTS0 COMMENTS
Ted Musemwa
7219 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6911 POSTS0 COMMENTS