Nearby lessons

12 of 61

⚡ Tailwind CSS - Functions & Directives

📖 Functions & Directives Overview

Tailwind CSS provides powerful functions and directives that extend CSS capabilities and enable dynamic styling. These tools allow you to create flexible, maintainable styles while staying within the utility-first paradigm.

This guide covers the essential functions and directives that make Tailwind CSS a powerful styling framework for modern web development.

🎯 @apply Directive

The @apply directive extracts utility classes into CSS rules. This is perfect for creating component classes while maintaining consistency with your design system.

🌀

tailwind Designer

Live Component Playground

html Source
Loading...
Built with Tailwind CSS • Instant Reflection

🔧 @layer Directive

The @layer directive helps organize your CSS into logical layers and controls the order of CSS rules. This ensures your custom styles work properly with Tailwind's utilities.

🌀

tailwind Designer

Live Component Playground

html Source
Loading...
Built with Tailwind CSS • Instant Reflection

🎨 theme() Function

The theme() function accesses values from your Tailwind configuration. This allows you to use design tokens consistently across your custom CSS.

🌀

tailwind Designer

Live Component Playground

html Source
Loading...
Built with Tailwind CSS • Instant Reflection

🔧 screen() Function

The screen() function creates media queries using your Tailwind breakpoint configuration. This ensures consistency with your responsive design system.

🌀

tailwind Designer

Live Component Playground

html Source
Loading...
Built with Tailwind CSS • Instant Reflection

🎭 @config Directive

The @config directive allows you to reference values from your Tailwind configuration directly in your CSS. This is useful for accessing custom configuration values.

🌀

tailwind Designer

Live Component Playground

html Source
Loading...
Built with Tailwind CSS • Instant Reflection

🔧 @variant Directive

The @variant directive applies variants to existing CSS rules. This allows you to create variant-specific styles for your custom components.

🌀

tailwind Designer

Live Component Playground

html Source
Loading...
Built with Tailwind CSS • Instant Reflection

🎨 @utility Directive

The @utility directive creates custom utility classes. This extends Tailwind's utility system with your own specific needs.

🌀

tailwind Designer

Live Component Playground

html Source
Loading...
Built with Tailwind CSS • Instant Reflection

🔧 @reference Directive

The @reference directive includes CSS without generating output. This is useful for importing styles that you want to extend but not output directly.

🌀

tailwind Designer

Live Component Playground

html Source
Loading...
Built with Tailwind CSS • Instant Reflection

🎯 Advanced Function Combinations

Combine multiple functions and directives for powerful styling solutions. This enables complex, maintainable CSS architectures.

🌀

tailwind Designer

Live Component Playground

html Source
Loading...
Built with Tailwind CSS • Instant Reflection

🔧 Performance Considerations

When using functions and directives, consider performance implications and best practices to maintain efficient CSS generation.

  • Use @layer for proper CSS organization
  • Leverage theme() for consistent design tokens
  • Combine @apply with theme() for maintainable components
  • Use screen() for responsive consistency
  • Create utilities only when necessary
  • Avoid over-engineering simple styles
  • Profile CSS output for optimization

🧠 Test Your Knowledge

5 Questions

Progress: 0 / 5
Keep Going!Tailwind CSS - Aspect Ratio