You can use a combination of directives and CSS to take advantage of the available utilities.
Use @apply
to inline any existing utility classes into your style block.
This is useful when you find a common utility pattern in your HTML that you'd like to extract to a new component.
.btn {
border-radius: 0.25rem;
font-weight: 700;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
padding-left: 1rem;
padding-right: 1rem;
}
.btn-blue {
--tw-bg-opacity: 1;
background-color: rgba(59, 130, 246, var(--tw-bg-opacity));
--tw-text-opacity: 1;
color: rgba(255, 255, 255, var(--tw-text-opacity));
padding-top: 1rem;
}
.btn-blue:hover {
--tw-bg-opacity: 1;
background-color: rgba(29, 78, 216, var(--tw-bg-opacity));
}
If you'd like to @apply
an existing class and make it !important
, simply add !important
to the end of the declaration:
.btn {
border-radius: 0.25rem !important;
font-weight: 700 !important;
padding-top: 0.5rem !important;
padding-bottom: 0.5rem !important;
padding-left: 1rem !important;
padding-right: 1rem !important;
}
You can generate screen variants, state variants, theme variants of your own utilities by wrapping their definitions in the @variants
directive.
.rotate-0:focus {
transform: rotate(0deg);
}
.rotate-90:focus {
transform: rotate(90deg);
}
.rotate-0:hover {
transform: rotate(0deg);
}
.rotate-90:hover {
transform: rotate(90deg);
}
.dark .bg-color {
background-color: #1c1c1e;
}
The @screen
directive allows you to create media queries that reference your breakpoints by name instead of duplicating their values in your own CSS.
@media (min-width: 640px) {
.custom {
font-size: 1.125rem;
line-height: 1.75rem;
}
}
The @layer
directive sets the order of how each class is applied. Valid layers are base
, components
, and utilities
.
.components {
--tw-bg-opacity: 1;
background-color: rgba(239, 68, 68, var(--tw-bg-opacity));
}
.utilities {
max-width: 768px;
}
base {
margin-left: auto;
}
.normal {
margin-right: auto;
}
The theme()
function allows you to access your config values using dot notation.
.btn-blue {
background-color: #3b82f6;
}