Logo

dev-resources.site

for different kinds of informations.

Tailwind tip: Managing a long list of utility classes in a single line of code

Published at
11/11/2024
Categories
tailwindcss
css
uidesign
Author
kaleemelahi
Categories
3 categories in total
tailwindcss
open
css
open
uidesign
open
Author
11 person written this
kaleemelahi
open
Tailwind tip: Managing a long list of utility classes in a single line of code

Managing a long list of utility classes in a single line can become unwieldy.

Here is Tailwind's built-in feature @apply that can help make your code more readable and manageable:

Use @apply in Custom CSS

With Tailwind's @apply directive, you can create reusable CSS classes by grouping multiple Tailwind utilities. This helps reduce the number of classes in your HTML and keeps your components more organized.

Example:

/* styles.css */
.btn-primary {
  @apply bg-blue-500 text-white font-bold py-2 px-4 rounded;
}
Enter fullscreen mode Exit fullscreen mode

You can then use this new .btn-primary class in your HTML instead of repeating the Tailwind utilities:

<button class="btn-primary">Primary Button</button>
Enter fullscreen mode Exit fullscreen mode

If it helped you, you can support:
https://buymeacoffee.com/kaleemelahi


Follow for more:
Linkedin
GIthub

uidesign Article's
30 articles in total
Favicon
Ship mobile apps faster with React-Native-Blossom-UI
Favicon
How Thoughtful UI/UX Design Drives Digital Success (And Why Your Brand Needs It)
Favicon
How I built UI-Forest: Ui-Library
Favicon
UI Design Trends: Exploring Modern Aesthetics
Favicon
Color Theory in UI Design
Favicon
The Basics of UI vs UX
Favicon
iPhone 16 Mockup for Figma
Favicon
If the setting is missing, add it yourself
Favicon
16 Free Resources You Should Know for Design Inspiration
Favicon
The Power of Design Systems: How to Create and Maintain a Consistent Design Language
Favicon
Designing Beautiful Dashboard Layouts with Tailwind CSS
Favicon
Navigating the Web Development Landscape: Finding Your Role
Favicon
Como o Figma Virou Parte do Meu Dia a Dia no Front-End
Favicon
Building Modern Websites and Managing Online Presence with Expertise in Magento, WordPress, & Shopify
Favicon
UI/UX Testing: Why It’s Important for Your Project
Favicon
Domina el arte de la personalización en Ionic: Crea paletas de colores únicas paso a paso
Favicon
This API Client Has A Brilliant Landing Page Trick
Favicon
Discover the 9 Best Open-Source Alternatives to Postman
Favicon
5 Tips to improve your UI Designs
Favicon
Transform Digital Platforms with Custom UI/UX Design Solutions
Favicon
Top 10 Books on Design System that i Read last year
Favicon
Tailwind tip: Managing a long list of utility classes in a single line of code
Favicon
Why Wireframing Matters in UI/UX Design
Favicon
Secrets to Designing a Great API
Favicon
Streamline Your API Design Workflow: Using Schemas with EchoAPI
Favicon
EchoAPI vs. Postman: Why EchoAPI is the Superior Choice for API Management
Favicon
Desizen: Empowering Designers with Practical UI/UX Challenges Introduction
Favicon
5 dicas de design de um front-end pra UI Designers
Favicon
Biometrics and Security: Designing for Trust in Web and Mobile Apps
Favicon
Touch-Friendly UI Design: Best Practices to Ensure Seamless Mobile Interactions

Featured ones: