Skip to content

Backgrounds ​

Five SVG patterns, and the wrapper that puts one behind your content.

Open in demo
Open in demo

Usage ​

SaBackground wraps your content and paints a pattern behind it. Give it a pattern and put whatever you like in the default slot.

The pattern layer is clipped, takes no pointer events, and is aria-hidden. The content layer is positioned and later in the DOM, so it always paints above it without a z-index anywhere.

Every pattern is drawn in currentColor, so it takes the text color it inherits. That is what lets one set of patterns work on any surface and follow a re-theme, and color overrides it per instance.

Examples ​

The five patterns ​

pattern is dots, grid, waves, geometric, mesh or none. none renders no layer at all, which is how a page turns the pattern off without a v-if around the wrapper.

Position ​

position is full, top-right or bottom-left. The two corners cover two thirds of the box, and they use logical sides, so they mirror in a right-to-left layout.

Color and opacity ​

opacity defaults to 0.05, which is a texture rather than a decoration. Turn it up and the pattern becomes the point; the examples on this page use higher values so the shapes are visible.

A pattern on its own ​

Each pattern is also a component. Use one directly where you want to own the positioning, the clipping and the opacity yourself.

API ​

Source: src/shared/components/backgrounds/

SaBackground props ​

PropTypeDefaultDescription
pattern'dots' | 'grid' | 'waves' | 'geometric' | 'mesh' | 'none'requiredWhich pattern, or none.
opacitynumber0.05The pattern layer's opacity.
position'full' | 'top-right' | 'bottom-left''full'Where the layer sits. The corners are two thirds of the box.
colorstring—Overrides the inherited currentColor the pattern tints to.

SaBackground emits ​

None.

SaBackground slots ​

SlotDescription
defaultThe content, which paints above the pattern.

The five patterns ​

Each takes no props, emits nothing and has no slots. They fill their parent at 100% by 100%.

ComponentThe tileSize
PatternDotsOne filled dot per tile.24 × 24
PatternGridA single-pixel rule along two sides.32 × 32
PatternWavesTwo stroked waves.80 × 40
PatternGeometricTwo stroked triangles, the second at half opacity.40 × 35
PatternGradientMeshThree overlapping radial gradients, filled rather than stroked.Fills the box

PatternGradientMesh is the one that fills rather than strokes: each gradient fades currentColor to transparent, so the mesh tints to whatever color it inherits. It is a pattern the template ships and is documented as it ships.

Each instance generates its own id for its SVG <pattern> or gradients, so several patterns on one page cannot collide.

Accessibility ​

  • Every pattern SVG is aria-hidden, and so is the layer SaBackground puts it in. They are decoration and say nothing.
  • The layer takes no pointer events, so a pattern never eats a click meant for the content above it.
  • At the default opacity the pattern is a texture rather than a background, so text over it keeps its contrast. If you turn it up, check the text over it again.