Sunday, May 19, 2024
HomejQueryTailwind CSS background Coloration utilities

Tailwind CSS background Coloration utilities

Setting background colours by Tailwind background utility lessons

For controlling the background shade of net web page components, you could use the background utility lessons of Tailwind. These lessons:

  • Begin with the prefix bg
  • That is adopted by a splash ()
  • Then use the shade identify and its quantity

For instance:











and so forth.

See the entire checklist on the official web site:

The examples under present utilizing background shade lessons in varied HTML components.

An instance of utilizing background lessons in buttons

Within the first instance of demonstrating utilization of Tailwind background shade lessons, we’ll use these in controlling the button colours.

For that, we’ve got created six buttons the place we set the Tailwind width, padding, and background colours of the buttons.

See on-line demo and code




Utilizing background shade in a desk instance

Within the demo under, we used background shade within the HTML desk. Once more, we styled the desk by different tailwind lessons and in addition used background shade for the desk head and knowledge as proven under:


See on-line demo and code

Utilizing background shade in paragraph instance

Now we’re utilizing background shade and different lessons within the paragraphs.

5 paragraphs are created the place we utilized completely different bg colours, margins, width, textual content colours and alignments as follows:

See on-line demo and code

Apply background shade on hover state instance (buttons)

Tailwind has the power to use completely different utility lessons in varied states together with hover.

For that, you could use the variant modifiers. For instance, you could use the next for making use of the background shade on the hover state to a component like button:


See the instance under the place we prolonged the above button instance and added lessons for the hover state.

After opening the demo web page, convey the mouse over any button to see how the background shade adjustments.


See on-line demo and code

Hover state instance in a desk

Within the instance under, we used completely different background colours within the hover state of the desk. As you convey the mouse over the desk header or desk knowledge (th and td), the background and textual content shade change.

Click on on the demo hyperlink to take a look your self:


See on-line demo and code

The way to use a customized background shade in Tailwind

In conditions the place it is advisable to use another shade than out there within the Tailwind pre-defined lessons whereas nonetheless utilizing Tailwind – you are able to do this as follows.

An instance of utilizing arbitrary worth:

<p class=”bg-[#408080]”>

So, you should utilize sq. brackets to generate the worth on the fly.

See an instance under we use this within the paragraph’s background colours:

See on-line demo and code



Utilizing completely different background colours for varied gadgets

Tailwind additionally allows you to make the most of variant modifiers for concentrating on media queries.

For instance, you could use a special background shade for a desktop/pocket book and another for a smartphone or pill – fairly simply.

Equally, you could use completely different colours for gentle or darkish modes for a similar components.

How to do that? An instance is under:

bg-gray-600 lg:bg-red-700

Which means, utilizing purple shade for giant display screen and gray-600 in small and medium screens.

For shortly viewing a demo, click on on the hyperlink under and see the demo web page on giant display screen and resize to a small dimension to see how its shade change:

See on-line demo and code





Please enter your comment!
Please enter your name here

Most Popular

Recent Comments