CSS Tools

CSS Background Pattern Generator

Use this free CSS Background Pattern Generator to build seamless background patterns using nothing but CSS. Pick a pattern, adjust colors, scale, and spacing, then copy code that adds texture to your page without loading a single image file. No sign-up required.

No Image Files Live Preview 100% Free

                    
                

Why You Are Here

A flat background color is safe and a little boring. A background image adds texture but costs you an HTTP request, a few dozen kilobytes, and a decision about what happens on a retina display. CSS patterns sit between the two: real visual texture for a few hundred bytes of code that stays sharp at any resolution and any element size.

The catch is that writing them by hand is genuinely awkward. A polka dot pattern is a radial gradient with a hard stop and a carefully matched background-size. A checkerboard needs two layered gradients offset against each other by exactly half the tile. Getting the numbers right involves a lot of saving, refreshing, and squinting. That is what a generator solves.

The first situation is adding subtle texture to a section. A hero, a pricing table, a testimonial band: somewhere the flat color feels empty but a photograph would be too loud.

The second is functional patterns. Graph paper grids behind a canvas or diagram editor, the checkerboard that signals transparency in an image tool, ruled lines behind a notes interface. These are patterns doing a job, not just decoration.

The third is replacing an existing image tile. You inherited a site loading a 40KB seamless tile PNG, and the same effect is achievable in four lines of CSS.

What This Tool Does

The CSS Background Pattern Generator gives you a library of seamless patterns with visual controls for customising each one.

Choose a pattern type, adjust the colors, scale, spacing, and line weight, and watch a live preview update as you work. When it looks right, copy the generated CSS and paste it into your stylesheet.

Every pattern is pure CSS. No image files are generated, downloaded, or requested. Everything runs in your browser and nothing is uploaded or stored.

How CSS Patterns Actually Work

Understanding the mechanism means you can modify the generated code rather than being limited to what the presets produce. There are two approaches, and knowing which one you are looking at explains most of the CSS you will see.

Approach one: a repeating gradient

repeating-linear-gradient() and repeating-radial-gradient() tile themselves automatically. You define one cycle using color stops, and the browser repeats it infinitely along the gradient line. No background-size is needed.

background: repeating-linear-gradient(
  45deg,
  #8B5CF6 0 10px,
  #EC4899 10px 20px
);

/* At 45 degrees: purple from 0 to 10px, pink from 10 to 20px,
   then start over. The result is diagonal stripes. */

Approach two: one tile plus background-size

A normal linear-gradient() or radial-gradient() draws a single shape. Setting background-size defines how big one tile is, and the default background-repeat tiles it across the element.

background-color: #ffffff;
background-image: radial-gradient(#8B5CF6 2px, transparent 2px);
background-size: 24px 24px;

/* Draws one 2px dot inside a 24px square, then repeats it.
   Change background-size and the dots spread further apart
   without changing size. Change the 2px and the dots grow
   without changing spacing. */

The three concepts that unlock everything else

Hard stops make shapes

A gradient with two colors at the same position produces a sharp edge instead of a blend. #8B5CF6 2px, transparent 2px means solid purple up to 2 pixels, then nothing: a crisp circle, not a fuzzy glow.

Multiple backgrounds layer

Comma-separated background images stack, with the first one listed sitting on top. A grid is simply horizontal lines layered over vertical lines.

Background-position offsets layers

A checkerboard is the same gradient twice, with the second copy shifted by half a tile.

Pattern Recipe Reference

The core patterns and the CSS behind each. Colors are placeholders. Swap in your own.

Polka dots

background-color: #ffffff;
background-image: radial-gradient(#8B5CF6 2px, transparent 2px);
background-size: 24px 24px;

Grid / graph paper

background-color: #ffffff;
background-image:
  linear-gradient(#e5e7eb 1px, transparent 1px),
  linear-gradient(90deg, #e5e7eb 1px, transparent 1px);
background-size: 24px 24px;

Horizontal stripes

background: repeating-linear-gradient(
  0deg,
  #8B5CF6 0 10px,
  #EC4899 10px 20px
);

Diagonal stripes

background: repeating-linear-gradient(
  45deg,
  #8B5CF6 0 10px,
  #EC4899 10px 20px
);

Checkerboard

background-color: #ffffff;
background-image:
  linear-gradient(45deg, #e5e7eb 25%, transparent 25%,
                  transparent 75%, #e5e7eb 75%),
  linear-gradient(45deg, #e5e7eb 25%, transparent 25%,
                  transparent 75%, #e5e7eb 75%);
background-size: 40px 40px;
background-position: 0 0, 20px 20px;

Cross-hatch

background-image:
  repeating-linear-gradient(45deg,  #e5e7eb 0 1px, transparent 1px 12px),
  repeating-linear-gradient(-45deg, #e5e7eb 0 1px, transparent 1px 12px);

Concentric rings

background: repeating-radial-gradient(
  circle at center,
  #8B5CF6 0 10px,
  #EC4899 10px 20px
);

Ruled notebook lines

background-color: #fffef7;
background-image: repeating-linear-gradient(
  #fffef7 0 27px,
  #d1d5db 27px 28px
);

Pattern Use Case Reference

Pattern Typical Use Suggested Contrast

Fine dots

Subtle section texture

Very low, barely visible

Large dots

Playful hero backgrounds

Medium

Grid

Canvas, diagram, and dashboard backgrounds

Low

Graph paper

Design tools, plotting interfaces

Low

Diagonal stripes

Warning bands, progress bars, accents

Medium to high

Horizontal stripes

Retro or editorial section dividers

Medium

Checkerboard

Transparency indicator in image tools

Low

Cross-hatch

Textured panels, print-style backgrounds

Low

Concentric rings

Radial focal points, decorative headers

Medium

Ruled lines

Note-taking and writing interfaces

Very low

The contrast column matters more than it looks. A pattern that sits behind text should be barely perceptible. A pattern that IS the design element can be bold.

Accessibility Considerations

This is the part most pattern tools skip entirely, and it matters more than the pattern choice itself.

Text over a pattern needs contrast against every part of it

WCAG requires a 4.5 to 1 contrast ratio for normal text. A pattern means the background behind your text alternates between two colors. Your text must clear the threshold against the lighter AND the darker parts of the pattern, not against their average. The safest approach is keeping any pattern behind text extremely low contrast, so the two pattern colors are close enough that either one passes.
High-contrast fine stripes can cause genuine physical discomfort

Tightly repeating parallel lines in high contrast are a known trigger for visual discomfort, dizziness, and in some cases seizures in photosensitive individuals. They also produce moire interference when they interact with a screen's pixel grid, which is why fine stripes sometimes appear to shimmer during scrolling. Keep repeating stripes either widely spaced or low contrast, and avoid animating them.
Provide a solid fallback background color

Always declare background-color alongside your pattern. If the pattern fails to render for any reason, the text still has a defined background to sit against rather than falling through to whatever is beneath.

Performance — The Honest Version

Most tools tell you CSS patterns are simply faster than images. The file size argument is real, but it is not the whole picture.

Performance Details

Where CSS patterns clearly win

File size, typically a few hundred bytes against several kilobytes for a seamless tile. No additional HTTP request. Perfect sharpness at any resolution with no retina variant needed. Colors changeable by editing one line rather than regenerating an asset.

Where they can cost you

The browser rasterizes gradients at paint time. A single simple pattern is negligible. Several layered repeating gradients stretched across a full-viewport element can become measurably expensive, particularly during scroll and particularly on lower-end mobile devices. Adding background-attachment: fixed to a patterned element is especially costly because it forces repainting as the page scrolls.

Practical guidance

For typical patterns on typical elements, use CSS without hesitation. If you are layering four or more gradients across a full-page background, or combining a pattern with fixed attachment or animation, profile it on a mid-range phone before shipping.

Common Mistakes to Avoid

Forgetting the Solid Background Color Behind the Pattern

Most pattern recipes draw shapes over transparency, meaning the gaps between the dots or lines are see-through rather than white. Without an explicit background-color, whatever sits beneath the element shows through the gaps, which is rarely what you intended and often produces an unreadable result over a parent background. Always pair the pattern with a solid background-color declaration.
Changing Pattern Size Without Adjusting Both Values

In the tile-plus-background-size approach, the shape size and the tile size are independent. Increasing background-size from 24px to 48px spaces the dots twice as far apart but leaves them the same size, which usually reads as a mistake rather than a design choice. To scale the whole pattern proportionally, multiply the shape dimension and the tile dimension by the same factor.
Leaving Decorative Patterns in the Print Stylesheet

A background pattern that looks good on screen consumes a surprising amount of ink on paper, and many browsers suppress background graphics when printing anyway, producing an inconsistent result. Strip decorative patterns in a print media query so printed pages come out clean.
@media print {
  .patterned { background-image: none; }
}

Quick Reference

Concept Detail

Repeating gradient

Tiles itself, no background-size needed

Gradient + background-size

One tile, repeated

Hard stop

Same position twice

Layering

Comma-separated, first listed on top

Offset a layer

background-position

Always add

Solid background-color

Behind text

Keep contrast very low

Print

Strip with a media query

Network cost

No image file, no HTTP request

Resolution

Sharp at any pixel density

Frequently Asked Questions

What is a CSS background pattern generator?

A CSS background pattern generator is a free online tool that creates seamless repeating background patterns using only CSS, with no image files involved. You choose a pattern type, customise the colors and scale, and copy the generated code into your stylesheet. This CSS Background Pattern Generator produces patterns from gradients, so they stay sharp at any size and add almost nothing to your page weight.

How do CSS patterns work without images?

They are built from gradients with hard color stops. A gradient that changes color abruptly instead of blending produces a defined shape, and either a repeating gradient function or a background-size value causes that shape to tile across the element. A polka dot pattern, for example, is a radial gradient drawing one dot inside a defined tile that the browser then repeats.

Are CSS patterns better for performance than background images?

For file size, clearly yes: a pattern is typically a few hundred bytes against several kilobytes for an image tile, with no extra HTTP request. The nuance is that gradients are rasterized by the browser at paint time, so heavily layered patterns across very large elements can cost rendering performance, especially during scroll on lower-end devices. For typical use, CSS patterns are the better choice.

How do I change the size of a CSS pattern?

It depends which approach the pattern uses. For patterns built with background-size, adjust that value to change tile spacing and adjust the shape dimension inside the gradient to change the shape itself. Scale both by the same factor to resize the pattern proportionally. For repeating-linear-gradient patterns, change the pixel values in the color stops.

Can I use CSS patterns behind text?

Yes, but keep the contrast between the two pattern colors very low. Your text has to meet contrast requirements against the lightest and darkest parts of the pattern, not their average, so a subtle pattern is far safer than a bold one. Avoid fine high-contrast stripes behind text entirely, since they reduce legibility and can cause visual discomfort.

Do CSS background patterns work on mobile?

Yes. CSS patterns are resolution independent, so they render sharply on high-density mobile displays without needing a separate retina asset. They also scale with the element rather than the viewport, so a pattern applied to a responsive container adapts automatically as the container resizes.

How do I layer two patterns together?

Comma-separate multiple background images in a single background-image declaration. The first one listed renders on top of the ones after it. Because patterns are drawn over transparency, the layers beneath show through the gaps, which is exactly how a grid pattern works: horizontal lines layered over vertical lines.

Is the generated CSS free to use in commercial projects?

Yes. The CSS produced by this CSS Background Pattern Generator is plain CSS with no licensing restrictions, attribution requirement, or usage limit. Use it in client work, commercial products, and open source projects freely. Everything is generated in your browser and nothing you create is stored.

Comments

Login to leave a comment

No comments yet. Be the first to comment!