> ## Documentation Index
> Fetch the complete documentation index at: https://gocharting.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Color and transparency

> Color constants, hex colors with alpha, opacity with color.new and color.rgb, gradients, reading a color's parts, and colors that change by bar.

A color is a value of type `color`. You write one as a constant, a hex literal or a call, and every drawing and plot takes one.

## Constants and hex

The constants are `color.aqua`, `black`, `blue`, `fuchsia`, `gray`, `green`, `lime`, `maroon`, `navy`, `olive`, `orange`, `purple`,
`red`, `silver`, `teal`, `white` and `yellow`. A plot without a `color` is `#483D8B`.

A hex literal is `#RRGGBB` or `#RRGGBBAA`, where the last pair is the alpha: `FF` is solid, `00` invisible. `#F00` (three digits) is
not a color:

```lipi-invalid theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Short hex")
plot(close, color=#F00)
```

The compiler says: token recognition error at: '#F00)'. Write `#FF0000`.

## Opacity

`color.new(color, alpha)` returns the color with a new opacity. **`alpha` runs from 0 to 1, and 1 is solid.** There is no
`transp` argument and no 0 to 100 scale. A value outside 0..1 is clamped when the script runs; a literal or `const` one also gives a
warning when you check the script, for example `color.new(color.red, 80)`: opacity 80 is outside 0–1; 1 is solid.

`color.rgb(r, g, b, a)` builds a color from integers 0 to 255 for `r`, `g`, `b` and, optionally, an opacity `a` from 0 to 1
(default solid). A literal component outside 0..255 warns: component r value 300 is outside 0–255.

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Opacity", overlay=true)
plot(close, title="Close", color=color.new(color.blue, 0.3), linewidth=3)
plot(open, title="Open", color=color.rgb(255, 165, 0, 0.6))
plot(hl2, title="Midpoint", color=color.new(#00FF0080, 0.5))
```

## Colors that change by bar

A color argument that is `series` may differ on every bar, so a condition decides the color:

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Trend color", overlay=true)
avg = talib.sma(close, 20)
plot(avg, title="Average", color=close > avg ? color.green : color.red)
bgcolor(close > open ? color.new(color.green, 0.9) : na)
```

`na` as a color means no color. The opacity of `color.new` may itself be a series.

## Gradients

`color.from_gradient(value, bottom_value, top_value, bottom_color, top_color)` blends the two colors by where `value` lies between
the two bounds (clamped to them). It returns `na` when the bounds are equal. All five arguments are required.

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("RSI gradient")
rsi = talib.rsi(close, 14)
plot(rsi, title="RSI", color=color.from_gradient(rsi, 30, 70, color.red, color.green), linewidth=2)
```

## Reading a color

`color.r(c)`, `color.g(c)` and `color.b(c)` return 0 to 255; `color.a(c)` returns the opacity from 0 to 1.

## Matching the chart's theme

`chart.bg_color` is the chart's background and `chart.fg_color` a color that contrasts with it, so text and lines stay readable on a light or a dark chart. Both are `input` colors: use them where a fixed value is required, such as `plot(color=...)`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.