Skip to content

yet3/tailwindcss-bg-patterns

Repository files navigation

@yet3/tailwindcss-bg-patterns

GitHub license npm

A plugin that adds css background patterns to TailwindCss

Live Demo

See a live demo

Table of Contents

Installation

npm install --save-dev @yet3/tailwindcss-bg-patterns
yarn add -D @yet3/tailwindcss-bg-patterns
pnpm add -D @yet3/tailwindcss-bg-patterns

In tailwind.config.js

import bgPatterns from "fluid-tailwind";

export default {
  // ...
  plugins: [bgPatterns],
};

Customizing config

import bgPatterns from "@yet3/tailwindcss-bg-patterns";

export default {
  // ...
  plugins: [
    bgPatterns({
      prefix: "bg-",
    }),
  ],
};

Example usage

<div
  class="bg-blue-500 bg-pattern-grid bg-pattern-line-0.5 bg-pattern-spacing-32"
/>

this code will result in:

Grid pattern

Pattern offsets

Each pattern can be offset using bg-pattern-offset-x and bg-pattern-offset-y

Offset also accept arbritary values bg-pattern-offset-x-[321px] as well as negative values -bg-pattern-offset-y-24

Patterns

Horizontal lines

See it live here

<div
  class="bg-blue-500 bg-pattern-x-lines bg-pattern-line-0.5 bg-pattern-spacing-32"
/>

Horizontal lines

Vertical lines

See it live here

<div
  class="bg-blue-500 bg-pattern-y-lines bg-pattern-line-0.5 bg-pattern-spacing-32"
/>

Vertical lines

Grid

See it live here

<div
  class="bg-blue-500 bg-pattern-grid bg-pattern-line-0.5 bg-pattern-spacing-32"
/>

Grid pattern

Checkers

See it live here

<div
  class="bg-blue-500 bg-pattern-checkers bg-pattern-square-white bg-pattern-square-32"
/>

Checkers pattern

Hatching

See it live here

<div
  class="bg-blue-500 bg-pattern-hatching bg-pattern-line-0.5 bg-pattern-spacing-16 bg-pattern-hatching-left-to-right"
/>

Hatching pattern

Cross-Hatching

See it live here

<div
  class="bg-blue-500 bg-pattern-cross-hatching bg-pattern-line-0.5 bg-pattern-spacing-16"
/>

Cross-Hatching pattern

Polka dot

See it live here

<div
  class="bg-blue-500 bg-pattern-polka-dot bg-pattern-dot-white bg-pattern-dot-8 bg-pattern-spacing-16"
/>

Polka dot pattern

Hexagonal polka dot

See it live here

<div
  class="bg-blue-500 bg-pattern-hex-polka-dot bg-pattern-dot-white bg-pattern-dot-8 bg-pattern-spacing-16"
/>

Polka dot pattern

Todo

  • Add utility to adjust pattern opacity
  • Add pattern: honeycomb
  • Add pattern: bricks

Support

ko-fi