The SVG `fill` attribute sets the color inside a shape. Most SVG shapes appear black until you set a fill. Give a rectangle a CSS color value, such as `fill="#6ba5d7"`, to change its interior; use `stroke` separately for its border. section 1.2.2
Color a rectangle with D3
Append a rectangle, set its position and size, then chain `.attr("fill", "turquoise")`. The color is passed as a string; `x`, `y`, `width`, and `height` determine where the colored shape appears. section 2.5
Fill can also be set with D3’s `.style("fill", "plum")` or a CSS rule such as `rect { fill: orange; }`. If the same rectangle has an attribute fill of turquoise, an inline-style fill of plum, and a stylesheet fill of orange, the inline style wins. Use one approach consistently when possible so the result is easier to manage. section 2.6
Choose a fill to match the visible result you want:
- Use `fill="none"` for a stroked path or outline without a filled interior. section 1.2.2
- Use `fill-opacity` to make a filled shape semitransparent. section 1.2.2
