---
title: "withAlpha"
description: "A color with its alpha replaced by a separately built mask."
group: "paint"
groupTitle: "Painting"
categoryId: "patterns"
categorySlug: "patterns"
categoryTitle: "Patterns & tiling"
kind: "function"
sourceUrl: "https://github.com/shader-effects-inc/shaders/blob/main/packages/core/src/std/paint/patterns.ts#L272"
---

# withAlpha

A color with its alpha replaced by a separately built mask.

```ts
withAlpha(color: PaintSlot, alpha: PaintSlot): PatternPaint
```

Import `patterns` from `shaders/std` and use `patterns.withAlpha`.

The usual way to hang a pattern under one color: the mask becomes the coverage and the color's own alpha is dropped.

## Parameters

| Name | Type | Notes |
|---|---|---|
| `color` | `PaintSlot` |  |
| `alpha` | `PaintSlot` |  |

## Example

```ts
paint: withAlpha(p('color'), dotLattice({density: p('density'), dotSize: p('dotSize'), offset: p('offset'), speedVariance: p('speedVariance'), twinkle: p('twinkle')}))
```

> **Tip.** To keep the color's own alpha as well, multiply it in: `withAlpha(color, times(alphaOf(color), mask))`.

## See also

- [`alphaOf`](/docs/primitives/patterns/alphaof) — The alpha channel of a color, as a number per pixel.
- [`times`](/docs/primitives/patterns/times) — The product of two values: a mask scaled by a prop, an RGB dimmed by a shade, two masks combined.
- [`opaque`](/docs/primitives/patterns/opaque) — An RGB value finished as a fully opaque color.

## Used by

[Chevron](/docs/components/chevron), [DotGrid](/docs/components/dotgrid), [FallingLines](/docs/components/fallinglines)