Oh MyUtils

CSS Background Pattern Generator - Create Pure CSS Gradient Patterns Online

Generate repeatable background patterns using pure CSS gradients. Choose from 21 patterns with live preview, custom colors, size and opacity control. One-click CSS code copy — 100% client-side.

Frequently Asked Questions

What is a CSS background pattern?

A CSS background pattern is a repeating visual design created entirely with CSS gradient functions like linear-gradient(), radial-gradient(), and repeating-conic-gradient(). Unlike image-based backgrounds, CSS patterns require no additional file downloads, are infinitely scalable, and look crisp at any screen resolution. They use the background-image, background-size, and background-position properties to tile a small gradient unit across an element.

How do I use this CSS background pattern generator?

Browse the pattern library and click on a pattern thumbnail to select it. Customize the pattern color and background color using the color pickers. Adjust size, opacity, and other parameters using the sliders. Preview the pattern in real time in the preview area. Copy the generated CSS code and paste it into your stylesheet.

Is my data secure? Does anything get sent to a server?

Yes, your data is completely secure. This tool runs 100% in your browser. No color choices, patterns, or generated CSS code are ever sent to any server. All pattern generation is performed client-side using JavaScript, ensuring total privacy.

What is the difference between CSS patterns and SVG patterns?

CSS patterns are built entirely from CSS gradient functions and require zero additional files or HTTP requests. SVG patterns use vector graphics embedded in CSS via url() or data URIs, which adds file size. CSS gradient patterns are typically smaller in code size, easier to customize via CSS properties, and render natively without parsing SVG. However, SVG patterns can achieve more complex shapes that gradients cannot.

Can I use these patterns in any CSS framework?

Yes. The generated CSS uses standard properties (background-image, background-size, background-position, background-color) supported by all modern browsers and all CSS frameworks. You can use the output directly in plain CSS, Sass, Less, Tailwind (via arbitrary values), or any CSS-in-JS solution.

How do CSS gradient patterns work technically?

CSS patterns exploit the repeating behavior of background-image combined with background-size. A small gradient tile is defined (e.g., a diagonal stripe in a 20x20px area), and the browser automatically repeats it across the element. By layering multiple gradient functions with different positions and sizes, complex patterns like checkerboards, zigzags, and diamonds can be created.

Will CSS patterns affect my website's performance?

CSS patterns are extremely performant. They add zero HTTP requests, require no image decoding, and are rendered natively by the browser's compositing engine. A typical pattern adds only 100-300 bytes of CSS. They are significantly faster than equivalent image backgrounds, especially on mobile devices.

Code Examples

// Creating CSS background patterns programmatically

// Dots pattern
function createDotsPattern(dotColor, bgColor, size = 20, dotRadius = 3) {
  return {
    backgroundImage: `radial-gradient(circle, ${dotColor} ${dotRadius}px, transparent ${dotRadius}px)`,
    backgroundSize: `${size}px ${size}px`,
    backgroundColor: bgColor,
  };
}

// Checkerboard pattern
function createCheckerboard(color, bgColor, size = 40) {
  return {
    backgroundImage: `repeating-conic-gradient(${color} 0% 25%, transparent 0% 50%)`,
    backgroundSize: `${size}px ${size}px`,
    backgroundColor: bgColor,
  };
}

// Diagonal stripes pattern
function createDiagonalStripes(stripeColor, bgColor, size = 20, angle = 45) {
  const half = size / 2;
  return {
    backgroundImage: `repeating-linear-gradient(${angle}deg, ${stripeColor}, ${stripeColor} ${half}px, transparent ${half}px, transparent ${size}px)`,
    backgroundSize: `${size}px ${size}px`,
    backgroundColor: bgColor,
  };
}

// Grid pattern
function createGrid(lineColor, bgColor, size = 30, thickness = 1) {
  return {
    backgroundImage: [
      `linear-gradient(0deg, ${lineColor} ${thickness}px, transparent ${thickness}px)`,
      `linear-gradient(90deg, ${lineColor} ${thickness}px, transparent ${thickness}px)`,
    ].join(', '),
    backgroundSize: `${size}px ${size}px`,
    backgroundColor: bgColor,
  };
}

// Apply pattern to a DOM element
function applyPattern(element, patternCSS) {
  Object.assign(element.style, patternCSS);
}

// Usage
const myDiv = document.getElementById('patterned-div');
applyPattern(myDiv, createDiagonalStripes('rgba(0,0,0,0.1)', '#ffffff', 20, 45));
applyPattern(myDiv, createCheckerboard('rgba(0,0,0,0.05)', '#f0f0f0', 40));

Related Tools