NexusBerry Training & Solutions
    NexusBerry Training & Solutions

    NexusBerry provides cutting-edge training and solutions for modern technology needs.

    About Us

    • Privacy Policy
    • Blog
    • Ruls and Regulations
    • Forms

    NexusBerry

    • Contact Us
    • About Us
    • Job Openings
    • Payment Methods

    Resources

    • Internship
    • Tutorials
    • Fee Structure
    • Admission Form

    AI & Data Science

    • Data Science Professional with Python & Applied Analytics
    • Full Stack Python Developer
    • Advanced Data Analytics Professional with Python and BI Tools
    • Agentic AI Engineer – GenAI, RAG & Autonomous Agents
    • AI Machine Learning Engineer with Python & Deep Learning
    • Python Programming for Software & AI Careers

    Software Engineering

    • Modern Frontend Developer with React & Next.js
    • MEAN Stack Mastery: Empower Your Web Development Skills for Modern Applications
    • Advanced Web Development with ASP.NET Core and Angular.js
    • Unlocking the Potential of PHP Laravel with Vue.js: A Comprehensive Training Course for Web Development Success
    • Django & React: Build Full-Stack Modern, Scalable Web Applications
    • Full Stack JavaScript Developer Specialization: Building Web and Mobile Apps with MERN Stack and React Native
    • Next.js: The Modern Path to Full Stack Web Development
    • Python Full Stack Web Development With Django
    • MERN Full Stack Web Development With Nextjs & GenAI

    Mobile App Development

    • Flutter App Development Course: Masterclass with Real-World Projects
    • React Native for Android and iOS App Development

    Digital Marketing

    • Social Media Marketing Course
    • SEO (Search Engine Optimization) Course
    • Full Stack Digital Marketing Course

    Creative Design

    • Master Video Editing: From Beginner to Pro Storyteller
    • Full Stack Designing & Video Editing Course
    • UI/UX Designing
    • Professional Graphic Design Masterclass: Master Visual Branding & AI Tools

    IT Infrastructure & Security

    • The Ultimate Cybersecurity Course: Web App Protection from Scratch
    • DevOps and Cloud Computing
    • CCNA Course

    © Copyright 2025, All Rights Reserved By NexusBerry Training & Solutions

    1. Home
    2. Tutorials
    3. Web Development Fundamentals
    4. Lecture 7: Advanced Tailwind & Customization
    tailwind 2/2

    Lecture 7: Advanced Tailwind & Customization

    Subscribe to our channel

    Stop using someone else's design system. In this lecture, you make Tailwind truly yours — custom colors, custom fonts, and reusable components built from scratch.


    What You'll Learn

    This lecture takes you from Tailwind user to Tailwind power user:

    • 🎯 @theme Directive — define your own brand colors and fonts that automatically generate Tailwind utility classes like bg-brand and font-display
    • 🖋️ Custom Fonts — integrate Google Fonts and register them in your design system in three simple steps
    • 🧩 @apply Component Extraction — stop repeating 7-class combinations everywhere; turn them into clean, reusable class names like .menu-card and .btn-primary
    • 🌈 Gradients — build smooth diagonal and multi-stop gradients using from-*, via-*, and to-*
    • 🌑 Dark Mode Basics — plan a light/dark palette using the dark: variant prefix
    • 🏷️ Badge & Button Systems — build a base + variant component pattern that scales cleanly across your project

    Why This Matters

    Raw Tailwind defaults look generic. Every professional project has a brand — specific colors, typography, and repeating UI components. @theme and @apply are how you encode that brand into your workflow so every element you build looks cohesive, consistent, and yours. This is how real agency and product work gets done.


    Before You Watch

    This lecture is the direct continuation of Lecture 6: Tailwind CSS Basics. You should already be comfortable with:

    • Tailwind's utility class syntax and spacing scale
    • Responsive prefixes like md: and lg:
    • Hover and transition modifiers

    💡 You'll be building a complete Restaurant Digital Menu in this lecture — so you'll see every concept applied in a real, polished project, not just isolated examples.

    📎 The cheatsheet is attached below the video. The full Restaurant Menu Component Library at the bottom is ready to copy directly into your own projects!

    Advanced Tailwind & Customization Cheatsheet

    Quick reference for all Tailwind CSS customization techniques covered in Lecture 7.


    @theme Directive — Custom Design Tokens

    The @theme directive lets you define custom colors, fonts, and spacing that automatically generate Tailwind utility classes.

    Setup (CDN)

    1<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
    2<style type="text/tailwindcss">
    3 @theme {
    4 --color-brand: #8B1A1A;
    5 --color-sage: #7C9070;
    6 --color-cream: #FFF8F0;
    7 --font-display: 'Playfair Display', serif;
    8 --font-body: 'Inter', sans-serif;
    9 }
    10</style>

    Critical: The <style> tag MUST have type="text/tailwindcss" for @theme and @apply to work with the CDN.

    Namespace System

    @theme Variable

    Generated Utilities

    Example

    --color-brand: #8B1A1A

    bg-brand, text-brand, border-brand, ring-brand, shadow-brand

    <div class="bg-brand text-cream">

    --color-sage: #7C9070

    bg-sage, text-sage, border-sage, ring-sage

    <span class="text-sage">

    --font-display: ...

    font-display

    <h1 class="font-display">

    --font-body: ...

    font-body

    <body class="font-body">

    Pattern: --color-* → all color utilities, --font-* → font-* utility, --spacing-* → spacing utilities

    Pro Tip: Name tokens by PURPOSE (brand, sage, cream) not appearance (dark-red, green). If the client changes from maroon to navy, --color-brand still makes sense.


    Custom Colors

    Defining a Palette

    1@theme {
    2 --color-brand: #8B1A1A; /* Primary brand */
    3 --color-brand-light: #A52A2A; /* Hover/accent */
    4 --color-brand-dark: #6B1010; /* Gradients/emphasis */
    5 --color-sage: #7C9070; /* Secondary accent */
    6 --color-sage-light: #A3B898; /* Subtle backgrounds */
    7 --color-cream: #FFF8F0; /* Page background */
    8 --color-cream-dark: #F5EDE0; /* Section alternation */
    9 --color-charcoal: #2C2C2C; /* Text color */
    10 --color-warm-gray: #6B6360; /* Muted text */
    11}

    Using Custom Colors

    1<!-- All these are auto-generated from @theme -->
    2<body class="bg-cream text-charcoal">
    3<h1 class="text-brand">Heading</h1>
    4<button class="bg-brand text-cream border-sage">Button</button>
    5<div class="ring-2 ring-brand">Focused element</div>

    :root (Lecture 5) vs @theme (Lecture 7)

    Feature

    :root CSS Variables

    @theme Directive

    Creates CSS variable

    Yes

    Yes

    Generates Tailwind utilities

    No

    Yes

    Use with var()

    Yes

    Yes

    Use as bg-*, text-*

    No

    Yes

    Requires Tailwind

    No

    Yes

    `@theme` is `:root` on steroids — it speaks Tailwind's language.


    Custom Fonts

    Google Fonts Integration

    1<!-- Step 1: Load fonts in <head> (before Tailwind script) -->
    2<link rel="preconnect" href="https://fonts.googleapis.com">
    3<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    4<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Playfair+Display:wght@400;500;600;700&display=swap" rel="stylesheet">
    1/* Step 2: Register in @theme */
    2@theme {
    3 --font-display: 'Playfair Display', serif;
    4 --font-body: 'Inter', sans-serif;
    5}
    1<!-- Step 3: Use in HTML -->
    2<body class="font-body"> <!-- Inter everywhere -->
    3<h1 class="font-display text-4xl">Title</h1> <!-- Playfair Display for headings -->

    Pro Tip: Two fonts is the sweet spot — one display (headings), one body (text). Three fonts is messy. One font is boring.


    @apply — Component Extraction

    Syntax

    1.nav-link {
    2 @apply text-warm-gray text-sm uppercase tracking-widest hover:text-brand transition duration-200;
    3}
    1<!-- Before: 7 classes × 4 links = 28 class instances -->
    2<a class="text-warm-gray text-sm uppercase tracking-widest hover:text-brand transition duration-200">
    3
    4<!-- After: 1 class × 4 links = 4 class instances -->
    5<a class="nav-link">

    When to Use @apply

    Scenario

    Decision

    Nav link repeated 4+ times

    @apply

    Menu card repeated 9+ times

    @apply

    Unique hero section padding

    Keep as utility

    One-off text color on heading

    Keep as utility

    Button style used across sections

    @apply

    Rule of 3+: If a utility pattern repeats 3 or more times, extract with @apply.

    All Modifiers Work Inside @apply

    1.menu-card {
    2 @apply bg-white rounded-xl shadow-md overflow-hidden
    3 hover:-translate-y-1 hover:shadow-xl
    4 transition duration-300;
    5}

    hover:, focus:, md:, lg:, dark:, active: — all work inside @apply.

    Base + Variant Pattern

    1/* Base class */
    2.badge {
    3 @apply text-xs font-semibold px-3 py-1 rounded-full uppercase tracking-wide;
    4}
    5
    6/* Variants (use both classes in HTML) */
    7.badge-spicy {
    8 @apply bg-red-100 text-red-700;
    9}
    10.badge-veg {
    11 @apply bg-green-100 text-green-700;
    12}
    13.badge-popular {
    14 @apply bg-amber-100 text-amber-700;
    15}

    Overriding @apply with Inline Utilities

    1<!-- .btn-primary has @apply bg-brand text-cream -->
    2<!-- Inline utilities OVERRIDE the @apply defaults -->
    3<button class="btn-primary bg-cream text-brand">Inverted Button</button>

    Inline utilities always win over @apply defaults.


    Gradients

    Syntax

    1<div class="bg-gradient-to-br from-brand via-brand-dark to-charcoal">

    Gradient Directions

    Class

    Direction

    bg-gradient-to-t

    Bottom → Top

    bg-gradient-to-r

    Left → Right

    bg-gradient-to-b

    Top → Bottom

    bg-gradient-to-l

    Right → Left

    bg-gradient-to-tr

    Bottom-left → Top-right

    bg-gradient-to-br

    Top-left → Bottom-right

    bg-gradient-to-bl

    Top-right → Bottom-left

    bg-gradient-to-tl

    Bottom-right → Top-left

    Gradient Color Stops

    Class

    Role

    Example

    from-*

    Start color

    from-brand

    via-*

    Middle color (optional)

    via-brand-dark

    to-*

    End color

    to-charcoal

    Pro Tip: Always include a via-* color for smoother, more professional gradients. Without via-*, the transition can look harsh.


    Dark Mode Basics

    The dark: Variant

    1<body class="bg-cream text-charcoal dark:bg-charcoal dark:text-cream">
    2<h1 class="text-brand dark:text-brand-light">Title</h1>

    How to Activate

    Add class="dark" to the <html> element:

    1<html lang="en" class="dark">

    Note: Toggling dark mode dynamically requires JavaScript (covered in Module 2). For now, know the dark: prefix exists and plan your inverse palette.


    Button Components

    1.btn-primary {
    2 @apply bg-brand text-cream font-semibold py-3 px-8 rounded-lg
    3 hover:bg-brand-light transition duration-300;
    4}
    5
    6.btn-outline {
    7 @apply border-2 border-brand text-brand font-semibold py-3 px-8 rounded-lg
    8 hover:bg-brand hover:text-cream transition duration-300;
    9}
    1<button class="btn-primary">Book a Table</button>
    2<button class="btn-outline">View Menu</button>
    3
    4<!-- Override for dark section -->
    5<button class="btn-primary bg-cream text-brand hover:bg-cream-dark">Light Button</button>

    Badge Pattern

    1.badge {
    2 @apply text-xs font-semibold px-3 py-1 rounded-full uppercase tracking-wide;
    3}
    4.badge-spicy { @apply bg-red-100 text-red-700; }
    5.badge-veg { @apply bg-green-100 text-green-700; }
    6.badge-popular { @apply bg-amber-100 text-amber-700; }
    1<span class="badge badge-spicy">Spicy</span>
    2<span class="badge badge-veg">Vegetarian</span>
    3<span class="badge badge-popular">Popular</span>

    Common Mistakes to Avoid

    1. Missing type="text/tailwindcss"

    1<!-- WRONG — @theme and @apply don't work -->
    2<style>
    3 @theme { --color-brand: #8B1A1A; }
    4</style>
    5
    6<!-- CORRECT — Tailwind processes this block -->
    7<style type="text/tailwindcss">
    8 @theme { --color-brand: #8B1A1A; }
    9</style>

    2. Wrong Namespace

    1/* WRONG — no --color- prefix, utilities won't generate */
    2@theme {
    3 --brand: #8B1A1A;
    4}
    5
    6/* CORRECT — --color- prefix generates bg-brand, text-brand, etc. */
    7@theme {
    8 --color-brand: #8B1A1A;
    9}

    3. Over-Extracting with @apply

    1/* WRONG — pointless extraction */
    2.red-text { @apply text-red-500; }
    3.big-padding { @apply p-8; }
    4
    5/* CORRECT — meaningful component extraction */
    6.menu-card { @apply bg-white rounded-xl shadow-md overflow-hidden hover:-translate-y-1 transition duration-300; }

    4. Missing -- Prefix

    1/* WRONG — not a valid CSS custom property */
    2@theme {
    3 color-brand: #8B1A1A;
    4}
    5
    6/* CORRECT — CSS custom properties require -- prefix */
    7@theme {
    8 --color-brand: #8B1A1A;
    9}

    VS Code Shortcuts

    Shortcut

    Action

    Ctrl + Space

    Trigger Tailwind class autocomplete (including custom classes)

    Ctrl + D

    Select next occurrence (great for renaming @apply classes)

    Alt + Up/Down

    Move line up/down

    Shift + Alt + Down

    Duplicate line (great for menu card repetition)

    Hover over class

    See generated CSS in tooltip (works for custom tokens too)


    Quick Reference Table

    What you want

    How to do it

    Custom brand color

    @theme { --color-brand: #HEX; } → bg-brand

    Custom font

    @theme { --font-display: 'Font', serif; } → font-display

    Reusable component class

    .nav-link { @apply ...; } → class="nav-link"

    Diagonal gradient

    bg-gradient-to-br from-brand to-charcoal

    Smooth gradient

    Add via-brand-dark between from-* and to-*

    Dark mode style

    dark:bg-charcoal dark:text-cream

    Badge system

    .badge base + .badge-spicy variant, use both classes

    Override @apply default

    Add inline utility: class="btn-primary bg-cream"

    Frosted glass nav

    bg-white/90 backdrop-blur-md

    Button pair (CTA)

    .btn-primary + .btn-outline side by side


    Restaurant Menu Component Library

    1/* Full @apply components from this lecture */
    2.nav-link { @apply text-warm-gray text-sm uppercase tracking-widest hover:text-brand transition duration-200; }
    3.section-title { @apply font-display text-3xl md:text-4xl font-bold text-charcoal text-center mb-2; }
    4.section-subtitle{ @apply text-warm-gray text-center text-lg mb-12 max-w-2xl mx-auto; }
    5.menu-card { @apply bg-white rounded-xl shadow-md overflow-hidden hover:-translate-y-1 hover:shadow-xl transition duration-300; }
    6.menu-card-image { @apply w-full h-48 object-cover; }
    7.price-tag { @apply font-display text-xl font-bold text-brand; }
    8.badge { @apply text-xs font-semibold px-3 py-1 rounded-full uppercase tracking-wide; }
    9.badge-spicy { @apply bg-red-100 text-red-700; }
    10.badge-veg { @apply bg-green-100 text-green-700; }
    11.badge-popular { @apply bg-amber-100 text-amber-700; }
    12.btn-primary { @apply bg-brand text-cream font-semibold py-3 px-8 rounded-lg hover:bg-brand-light transition duration-300; }
    13.btn-outline { @apply border-2 border-brand text-brand font-semibold py-3 px-8 rounded-lg hover:bg-brand hover:text-cream transition duration-300; }

    What's Next?

    Module Assignment: Fashion E-commerce Homepage

    Combines EVERYTHING from Lectures 1-7:

    • Semantic HTML structure (Lectures 1-2)
    • Responsive design (Lecture 5)
    • Tailwind customization with @theme and @apply (Lectures 6-7)
    • Custom brand colors, fonts, gradients, and component extraction

    Module 2: Programming Logic with JavaScript

    Your pages are beautiful — but they don't DO anything yet:

    • Can't add items to a cart
    • Can't filter the menu
    • Can't toggle dark mode
    • Can't validate a reservation form
    • JavaScript brings your pages to life

    > "Module 1 complete. 7 lectures. Zero to production-quality websites you can sell. Module 2 adds the logic that makes them interactive."


    Keep this cheatsheet handy while working on your assignment!

    All Web Development Fundamentals Tutorials