.style()

Published May 30, 2024
Contribute to Docs

the .style() method is used to set or get the inline style properties of selected elements. This method is useful for applying CSS styles to elements.

Syntax

selection.style("property", "value");
  • property: It is the name of the property or style name.
  • value: The value of property to set to it.

Example

In the given example above, the color property of text is set to red:

d3.select('text').style('color', 'red');

All contributors

Looking to contribute?

Learn JavaScript:D3 on Codecademy