Sub topic 1
The Default Palette and Shade Scale
Prerequisites
This chapter assumes basic HTML and CSS, including the box model. You should also know how Tailwind utility classes work and have a Tailwind CSS project or playground available.
Tailwind’s default color palette is a set of named colors, each with numbered shades. Lower numbers are usually lighter, while higher numbers are usually darker. For example, indigo-500 is a medium indigo and indigo-700 is darker.
<p class="text-slate-700">Readable body text</p>
<div class="bg-indigo-600 text-white">Colored panel</div>
<div class="border border-slate-300">Panel with a border</div>The utility prefix identifies what receives the color:
text-sets text color.bg-sets background color.border-sets border color.
The palette and shade are separate parts of the class name. This makes colors predictable across a project.
Adjusting Transparency with the Opacity Modifier
Add a slash and an opacity value to a color utility. The value is commonly a percentage from 0 to 100.
<div class="border border-white/20 bg-black/50 p-4 text-white">
Semi-transparent panel
</div>Here, bg-black/50 creates a background that is 50% opaque. border-white/20 makes the border 20% opaque. The text remains fully opaque because it uses text-white without a modifier.
Border Width and Style
Use border for a one-pixel solid border. Add a number for another width, such as border-2. Style utilities include border-dashed and border-dotted.
<div class="rounded-lg border-2 border-dashed border-slate-300 p-4">
Dashed panel
</div>The classes set width, style, and color independently. You can also target one side with prefixes such as border-b-4 for the bottom border width or border-t-slate-400 for the top border color.
Exercise
Which class creates a 50% opaque indigo background?
Show answer
Use bg-indigo-500/50, replacing 500 with the shade you need.