Effects
Effects add texture, depth and light on top of your gradients and patterns. This page documents every effect, its options and how effects stack.
Overview
xeerpe ships four effects: noise, vignette, grain and glow. Every option is optional, so .noise() with no arguments already works.
import { Builder } from 'xeerpe'
const style = new Builder()
.linearGradient({
from: '#4c1d95',
to: '#0ea5e9',
})
.noise()
.toStyle()Effects come in two kinds:
- Background layers:
noise,vignetteandgrainare drawn above patterns and gradients. When you add several, the one you add first is drawn on top. - Shadow:
glowdoes not add a layer. It adds abox-shadow, so it is drawn around or inside the element itself.
The effects that take a color (vignette and glow) accept any valid CSS color string.
Noise
Overlays a grayscale noise texture generated with an SVG turbulence filter. Because it is grayscale, it adds texture without tinting the colors below.
Options
opacitynumber0.25Opacity of the noise, from 0 (invisible) to 1 (fully opaque).
scalenumber0.65The base frequency of the noise. High values (around 0.5 to 1) produce fine, sand-like grain, while low values (such as 0.01) produce large, soft shapes.
type'turbulence''fractalNoise''fractalNoise'The kind of noise. fractalNoise gives an even, grainy texture. turbulence is more contrasted and, at low scale values, produces cloud-like patterns.
octavesnumber16How many layers of detail are combined. Lower values give a smoother, simpler texture and are cheaper to render.
backgroundSizestring'auto'A CSS background-size value for the noise layer.
Examples
Default noise
With no options, noise() adds a fine, subtle texture.
new Builder()
.linearGradient({
from: '#4c1d95',
to: '#0ea5e9',
angle: '160deg',
})
.noise()
.toStyle()Scale and opacity
Lower scale to enlarge the grain and raise opacity to make it more visible.
new Builder()
.linearGradient({
from: '#f97316',
to: '#7c2d12',
})
.noise({ scale: 0.3, opacity: 0.35 })
.toStyle()Turbulence
Switch type to turbulence and use a very low scale for soft clouds. Fewer octaves keep the shapes simple.
new Builder()
.linearGradient({
from: '#0f172a',
to: '#1d4ed8',
})
.noise({
type: 'turbulence',
scale: 0.012,
octaves: 4,
opacity: 0.5,
})
.toStyle()Vignette
Darkens, or tints, the edges of the element with a radial fade, which draws the eye toward the center.
Options
colorstring'#000000'The color at the edges. The intensity is applied to hex, rgb() and hsl() colors. Any other format, such as a named color or rgba(), is used as it is and ignores intensity. For 8-digit hex colors the alpha channel of the color wins over intensity.
intensitynumber0.2Opacity of the vignette color at the edges, from 0 to 1. Values outside that range are clamped.
spreadnumber0.2How far the vignette reaches toward the center, from 0 (no visible vignette) to 1 (it starts at the center). With the default of 0.2 only the outer 20% fades; with 0.5 the outer half does.
backgroundSizestring'auto'A CSS background-size value for the vignette layer.
Examples
Default vignette
The defaults darken the corners lightly.
new Builder()
.linearGradient({
from: '#fde68a',
to: '#fb923c',
angle: '135deg',
})
.vignette()
.toStyle()Color, intensity and spread
Use a tinted color, a higher intensity and a wider spread for a strong framing effect.
new Builder()
.linearGradient({
from: '#f9a8d4',
to: '#c4b5fd',
angle: '135deg',
})
.vignette({
color: '#312e81',
intensity: 0.65,
spread: 0.45,
})
.toStyle()Grain
Adds a very light film grain. It is designed to be subtle: the strongest setting is only a faint texture, which is what makes backgrounds feel less digital.
Options
intensitynumber1How visible the grain is. The grain opacity is 0.08 × intensity, limited to a range from 0.01 to 0.12. In practice values from about 0.125 to 1.5 change the strength, and anything above 1.5 has the same maximum effect.
sizestring'100%'The width and height of the generated grain image, as an SVG length such as '100%' or '200px'.
animatedbooleanfalseWhen true, the grain flickers slowly in a two-second loop, like moving film.
backgroundSizestring'auto'A CSS background-size value for the grain layer.
Examples
Film grain
Grain works best on large, smooth areas. At full strength it is a quiet texture rather than a visible pattern, so zoom in to see it.
new Builder()
.linearGradient({
from: '#2dd4bf',
to: '#1e1b4b',
})
.grain({ intensity: 1.5 })
.toStyle()Glow
Adds a soft colored light around the element, or inside it. Under the hood it is a box-shadow, so it follows the element's rounded corners.
Options
amountstring'20px'The blur radius of the glow. Larger values give a softer, wider light.
spreadstringHow much the glow grows before it is blurred. Positive values make it larger and more intense, negative values make it smaller. It is omitted by default.
xstring'0px'Horizontal offset of the glow.
ystring'0px'Vertical offset of the glow.
colorstring'#ffffff'The color of the glow. Use a translucent color such as rgba() for a softer light.
type'outer''inner''outer'outer draws the glow outside the element. inner draws it inside, along the edges.
Note: an outer glow is drawn outside the element's box. Leave some space around it and make sure no parent has
overflow: hidden, which would clip it.
Examples
Outer glow
A cyan light around a dark panel. spread makes the glow slightly stronger near the edge.
new Builder()
.linearGradient({
from: '#0b1020',
to: '#05060f',
})
.glow({
color: '#22d3ee',
amount: '40px',
spread: '2px',
})
.toStyle()Inner glow
With type: 'inner' the light comes from the edges and fades toward the center.
new Builder()
.linearGradient({
from: '#0b1020',
to: '#05060f',
})
.glow({
type: 'inner',
color: '#a855f7',
amount: '70px',
})
.toStyle()Offset glow
Use x and y to move the light, for example to simulate a colored shadow below the element.
new Builder()
.linearGradient({
from: '#1e293b',
to: '#0f172a',
})
.glow({
color: 'rgba(244,114,182,0.6)',
amount: '48px',
y: '28px',
})
.toStyle()Stacked glows
Each glow() call adds a shadow, and they are combined. Pairing an inner and an outer glow gives a neon outline.
new Builder()
.linearGradient({
from: '#06080f',
to: '#0b1020',
})
.glow({
type: 'inner',
color: '#22d3ee',
amount: '40px',
})
.glow({
color: '#22d3ee',
amount: '30px',
})
.toStyle()Combining effects
Effects combine with each other, with patterns and with any gradient. Add them after the gradient in the order you want them stacked: the first one ends up on top.
Examples
Film look
A warm gradient with a tinted vignette and film grain.
new Builder()
.linearGradient({
from: '#7c4a2d',
to: '#e0a96d',
angle: '160deg',
})
.vignette({
color: '#1a0f0a',
intensity: 0.7,
spread: 0.5,
})
.grain({ intensity: 1.5 })
.toStyle()Textured aurora
A mesh gradient with a light noise layer and a vignette to focus the center.
new Builder()
.meshGradient({
background: '#070b1f',
layers: [
{
from: 'rgba(124,58,237,0.85)',
to: 'transparent',
position: '12% 18%',
colorToPosition: '60%',
},
{
from: 'rgba(34,211,238,0.65)',
to: 'transparent',
position: '88% 20%',
colorToPosition: '55%',
},
{
from: 'rgba(244,114,182,0.65)',
to: 'transparent',
position: '70% 100%',
colorToPosition: '60%',
},
],
})
.noise({ opacity: 0.2 })
.vignette({
intensity: 0.6,
spread: 0.4,
})
.toStyle()Types reference
type EffectType =
| 'noise'
| 'vignette'
| 'grain'
| 'glow'
type NoiseType = 'turbulence' | 'fractalNoise'
type GlowType = 'outer' | 'inner'
interface NoiseOptions {
opacity?: number
scale?: number
type?: NoiseType
octaves?: number
backgroundSize?: string
}
interface VignetteOptions {
color?: string
intensity?: number
spread?: number
backgroundSize?: string
}
interface GrainOptions {
intensity?: number
size?: string
animated?: boolean
backgroundSize?: string
}
interface GlowOptions {
amount?: string
spread?: string
x?: string
y?: string
color?: string
type?: GlowType
}
type EffectOptions =
| NoiseOptions
| VignetteOptions
| GrainOptions
| GlowOptions