Background Color

Utilities for controlling an element's background color.

@include('_partials.background-color-class-table', [ 'rows' => $page->config['theme']['colors']->flatMap(function ($colors, $name) { if (is_string($colors)) { return [ [".bg-{$name}", "background-color: {$colors};"] ]; }

return collect($colors)->map(function ($value, $key) use ($name) {
  $class = ".bg-{$name}-{$key}";
  $code = "background-color: {$value};";
  return [
    $class,
    $code,
  ];
});

})->values()->all() ])

Usage

Control the background color of an element using the .bg-{color} utilities.

@component('_partials.code-sample', ['class' => 'text-center'])

@slot('code')@endslot @endcomponent

Changing opacityv1.4.0+

Control the opacity of an element's background color using the .bg-opacity-{amount} utilities.

@component('_partials.code-sample', ['style' => "background-image: url('/img/transparent-bg.svg')"])

@foreach ($page->config['theme']['backgroundOpacity']->reverse() as $name => $value)
@endforeach
@slot('code') @foreach ($page->config['theme']['opacity']->reverse() as $name => $value)
@endforeach @endslot @endcomponent

Learn more in the background opacity documentation.

Responsive

To control the background color of an element at a specific breakpoint, add a {screen}: prefix to any existing background color utility. For example, use md:bg-green-500 to apply the bg-green-500 utility at only medium screen sizes and above.

For more information about Tailwind's responsive design features, check out the Responsive Design documentation.

@component('_partials.responsive-code-sample', ['class' => 'text-center']) @slot('none')

@endslot @slot('sm')@endslot @slot('md')@endslot @slot('lg')@endslot @slot('xl')@endslot @slot('code')@endslot @endcomponent

Hover

To control the background color of an element on hover, add the hover: prefix to any existing background color utility. For example, use hover:bg-blue-500 to apply the bg-blue-500 utility on hover.

@component('_partials.code-sample', ['class' => 'text-center'])

@slot('code')

@endslot @endcomponent

Hover utilities can also be combined with responsive utilities by adding the responsive {screen}: prefix before the focus: prefix.

<button className="... md:bg-blue-500 md:hover:bg-blue-700 ...">Button</button>

Focus

To control the background color of an element on focus, add the focus: prefix to any existing background color utility. For example, use focus:bg-blue-500 to apply the bg-blue-500 utility on focus.

@component('_partials.code-sample', ['lang' => 'html'])

@slot('code')

@endslot @endcomponent

Focus utilities can also be combined with responsive utilities by adding the responsive {screen}: prefix before the focus: prefix.

<input className="... md:bg-gray-200 md:focus:bg-white ..."/>

Customizing

Background Colors

By default Tailwind makes the entire default color palette available as background colors.

You can customize your color palette by editing the theme.colors variable in your tailwind.config.js file, or customize just your background colors using the theme.backgroundColor section of your Tailwind config.

@component('_partials.customized-config', ['key' => 'theme.backgroundColor', 'usesTheme' => true])

  • ...theme('colors'),
  • 'primary': '#3490dc',
  • 'secondary': '#ffed4a',
  • 'danger': '#e3342f', @endcomponent

@include('_partials.variants-and-disabling', [ 'utility' => [ 'name' => 'background color', 'property' => 'backgroundColor', ], 'variants' => [ 'responsive', 'hover', 'focus' ], ])

Tailwind UI is now in early access!