Blazor playground

Nova v3.37.0

Preview

Blazor

Styling with Tailwind

Styling and Tailwind Guide for Nova Blazor

Introduction

This guide focuses on practical Tailwind CSS usage with Nova components in Blazor. As an Elia Group developer, you'll use Nova components as your foundation—most of your Tailwind work will involve layout, spacing, and composition rather than building components from scratch.

Key Principle: Nova handles component design. You handle page layout, spacing, and organization using Tailwind utilities.


Setup

Setup, config, and the recommended file structure for custom styles are documented in Tailwind Setup for Nova Blazor:

  • Go to: Guides/Tailwind Setup (includes the "Where to Put Custom Styles" section explaining which file to edit and stylesheet load order

Core Concepts

1. Nova Components + Tailwind Layout

Nova provides pre-styled, accessible components. Your job is to position and space them on the page.

razor@page "/dashboard"

<div class="min-h-screen bg-level-10 p-6">
    <div class="max-w-7xl mx-auto space-y-6">
        <h1 class="typo-heading-lg-bold text-high">Dashboard</h1>
        
        <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
            <div class="bg-level-00 rounded-lg shadow p-6">
                <h2 class="typo-heading-sm-medium mb-4">Total Users</h2>
                <p class="typo-text-xl-bold text-high">1,234</p>
            </div>
            
            <div class="bg-level-00 rounded-lg shadow p-6">
                <h2 class="typo-heading-sm-medium mb-4">Active Sessions</h2>
                <p class="typo-text-xl-bold text-high">567</p>
            </div>
            
            <div class="bg-level-00 rounded-lg shadow p-6">
                <h2 class="typo-heading-sm-medium mb-4">Revenue</h2>
                <p class="typo-text-xl-bold text-high">€89,000</p>
            </div>
        </div>
    </div>
</div>

What Tailwind does here:

  • min-h-screen - Full viewport height
  • bg-level-10 - Background elevation (semantic token)
  • p-6 - Padding (24px)
  • max-w-7xl mx-auto - Centered container with max width
  • space-y-6 - Vertical spacing between children
  • bg-level-00 rounded-lg shadow - Card-like container styling with base elevation
  • grid grid-cols-1 md:grid-cols-3 gap-6 - Responsive grid layout

2. Design Tokens Integration

Nova tokens are automatically available through Tailwind. The Nova CSS plugin maps tokens to Tailwind's theme system.

Color Tokens:

Nova uses an intentional token system that provides semantic meaning to colors. Always prefer intentional tokens over primitive color values.

📚 Learn more: Nova Design Tokens Documentation

Intentional Tokens (USE THESE FIRST):

razor@* Text colors (semantic hierarchy) *@
<p class="text-high">Primary text with highest contrast</p>
<p class="text-medium">Secondary text with medium contrast</p>
<p class="text-low">Tertiary text with lower contrast</p>
<p class="text-disabled">Disabled or inactive text</p>

@* Background elevations (layering system) *@
<div class="bg-level-00">Base level (cards, modals)</div>
<div class="bg-level-10">Elevated level (page background)</div>
<div class="bg-level-20">Higher elevation</div>

@* Border colors (semantic hierarchy) *@
<div class="border border-low">Subtle border</div>
<div class="border border-medium">Standard border</div>
<div class="border border-high">Prominent border</div>

@* Interactive states *@
<button class="bg-interactive hover:bg-interactive-hover active:bg-interactive-active">
  Interactive element
</button>

@* Feedback colors (alerts, notifications, form validation) *@
<div class="bg-feedback-success-low text-feedback-success-high">Success message</div>
<div class="bg-feedback-error-low text-feedback-error-high">Error message</div>
<div class="bg-feedback-warning-low text-feedback-warning-high">Warning message</div>
<div class="bg-feedback-information-low text-feedback-information-high">Info message</div>

Primitive Tokens (USE SPARINGLY - Only for specific design needs):

razor@* Only use primitive colors for data visualization, charts, or when intentional tokens don't fit *@
<div class="bg-green-500">Chart bar</div>
<div class="bg-turquoise-500">Data point</div>
<div class="bg-crimson-500">Alert indicator</div>

Token Selection Guide:

Use CaseToken to Use❌ Avoid
Page backgroundbg-level-10bg-gray-50
Card/modal backgroundbg-level-00bg-white
Primary texttext-hightext-gray-900
Secondary texttext-mediumtext-gray-600
Subtle bordersborder-lowborder-gray-200
Success statebg-feedback-success-low text-feedback-success-highbg-green-100 text-green-800
Data visualizationbg-green-500, bg-turquoise-500OK to use primitives here

Spacing Tokens:

Nova provides a consistent spacing scale based on a 4px grid system. All spacing utilities are multiples of 4px for visual harmony:

razor@* Padding *@
<div class="p-2">  @* 8px *@
<div class="p-4">  @* 16px *@
<div class="p-6">  @* 24px *@
<div class="p-8">  @* 32px *@

@* Margin *@
<div class="mt-4 mb-6">  @* top: 16px, bottom: 24px *@
<div class="mx-auto">    @* horizontal centering *@

@* Gap (for flex/grid) *@
<div class="flex gap-4">     @* 16px gap between items *@
<div class="grid gap-6">     @* 24px gap between grid items *@

Common spacing values:

  • 2 (8px): Tight spacing, inline elements
  • 4 (16px): Standard spacing, most common
  • 6 (24px): Comfortable spacing, section gaps
  • 8 (32px): Large spacing, major sections
  • 12 (48px), 16 (64px), 24 (96px): Extra large gaps

Direction modifiers:

  • p-*: All sides padding
  • px-*, py-*: Horizontal/vertical padding
  • pt-*, pr-*, pb-*, pl-*: Individual sides
  • Same pattern for margins (m-*, mx-*, etc.)

Typography Tokens:

Nova provides semantic typography classes that combine font size, weight, and line height. Always use these instead of Tailwind's font utilities for consistency:

razor@* Headings *@
<h1 class="typo-heading-xl-bold">Main Title</h1>
<h2 class="typo-heading-lg-medium">Section Title</h2>
<h3 class="typo-heading-md-medium">Subsection</h3>

@* Body text *@
<p class="typo-text-md-regular">Regular paragraph text</p>
<span class="typo-text-sm-medium">Label or emphasis</span>

@* Code/mono *@
<code class="typo-mono-sm-regular">dotnet run</code>

Naming pattern: typo-[usage]-[size]-[weight]

  • Usage: heading, text, mono
  • Size: xs, sm, md, lg, xl
  • Weight: regular, medium, bold

When to use:

  • Headings: Page titles, section headers, card titles
  • Text: Paragraphs, descriptions, labels, UI text
  • Mono: Code snippets, technical data, fixed-width content

Border Radius:

Nova provides a comprehensive border radius scale mapped to Tailwind utilities:

razor@* No rounding *@
<div class="rounded-none">    @* 0px *@

@* Small radius *@
<div class="rounded-sm">      @* 2px *@

@* Default radius *@
<div class="rounded">         @* 4px - most common for cards, buttons *@

@* Medium radius *@
<div class="rounded-md">      @* 6px *@

@* Large radius *@
<div class="rounded-lg">      @* 8px - good for larger cards *@

@* Extra large radius *@
<div class="rounded-xl">      @* 12px *@

@* 2X large radius *@
<div class="rounded-2xl">     @* 16px *@

@* 3X large radius *@
<div class="rounded-3xl">     @* 24px *@

@* Fully rounded (circular) *@
<div class="rounded-full">    @* 9999px - avatars, badges *@

@* Apply to specific corners *@
<div class="rounded-t-lg rounded-b-none">  @* top: 8px, bottom: 0 *@
<div class="rounded-l-md rounded-r-xl">   @* left: 6px, right: 12px *@

Common usage:

  • Cards and containers: rounded or rounded-lg
  • Buttons: handled by Nova components
  • Avatars and badges: rounded-full
  • Images: rounded-md or rounded-lg

Common Layout Patterns

These proven layout patterns solve common UI challenges in enterprise applications. Master these foundational patterns to build consistent, responsive interfaces efficiently. Each pattern uses Tailwind's flex and grid utilities combined with Nova's spacing tokens.

🎮 New to Flexbox and Grid? Learn by playing these interactive games:

Container and Page Layout

Centered page containers with max-width constraints provide optimal reading length and consistent alignment across screen sizes. Use this pattern as the foundation for most page layouts:

Best for: Main content areas, form pages, article layouts, dashboards

razor@page "/example"

<div class="min-h-screen bg-level-10">
    @* Main content container *@
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
        <h1 class="typo-heading-xl-bold text-high mb-6">Page Title</h1>
        <div class="bg-level-00 rounded-lg shadow p-6">
            @* Your content here *@
        </div>
    </div>
</div>

Flexbox Layouts

Flexbox is your primary tool for one-dimensional layouts—arranging items in a row or column. Use flex for navigation bars, button groups, form fields, and any content that needs flexible alignment or distribution.

Key utilities: flex, items-center, justify-between, gap-*, flex-col

Horizontal layout:

razor<div class="flex items-center gap-4">
    <NvButton>Cancel</NvButton>
    <NvButton Emphasis="high">Save</NvButton>
</div>

Vertical stack:

razor<div class="flex flex-col gap-4">
    <NvFieldtext Label="First Name" />
    <NvFieldtext Label="Last Name" />
    <NvFieldtext Label="Email" />
</div>

Space between items:

razor<div class="flex items-center justify-between">
    <h2 class="typo-heading-md-bold">Users</h2>
    <NvButton>Add User</NvButton>
</div>

Centered content:

razor<div class="flex items-center justify-center min-h-screen">
    <div class="bg-white rounded-lg shadow-lg p-8 w-full max-w-md">
        <h2 class="typo-heading-lg-bold mb-6">Login</h2>
        @* Form fields *@
    </div>
</div>

Grid Layouts

CSS Grid excels at two-dimensional layouts with rows and columns. Use grid for card galleries, data dashboards, sidebar layouts, and any content requiring precise alignment in both directions.

Key utilities: grid, grid-cols-*, gap-*, col-span-* Responsive pattern: grid-cols-1 md:grid-cols-2 lg:grid-cols-3 (mobile-first)

Responsive columns:

razor@* 1 column on mobile, 2 on tablet, 3 on desktop *@
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
    <div class="bg-level-00 rounded-lg shadow p-4">Card 1</div>
    <div class="bg-level-00 rounded-lg shadow p-4">Card 2</div>
    <div class="bg-level-00 rounded-lg shadow p-4">Card 3</div>
</div>

Sidebar layout:

razor<div class="grid grid-cols-12 gap-6">
    @* Sidebar - 3 columns on desktop *@
    <aside class="col-span-12 lg:col-span-3">
        <div class="bg-level-00 rounded-lg shadow p-4">Navigation</div>
    </aside>
    
    @* Main content - 9 columns on desktop *@
    <main class="col-span-12 lg:col-span-9">
        <div class="bg-level-00 rounded-lg shadow p-6">Main content</div>
    </main>
</div>

Form grid:

razor<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
    <NvFieldtext Label="First Name" />
    <NvFieldtext Label="Last Name" />
    <NvFieldtext Label="Email" Class="sm:col-span-2" />
    <NvFieldtext Label="Phone" />
    <NvFieldtext Label="Company" />
</div>

Spacing Utilities

Proper spacing creates visual hierarchy and improves readability. Tailwind offers two approaches: space-* for uniform spacing between children (best for lists), and individual margin/padding utilities for precise control.

Choose space-y-* / space-x-* when: All siblings need equal spacing (lists, menus, stacked content) Choose mt-* / mb-* when: Specific elements need custom spacing

Consistent spacing with space-*:

razor@* Vertical spacing *@
<div class="space-y-4">
    <p>Paragraph 1</p>
    <p>Paragraph 2</p>
    <p>Paragraph 3</p>
</div>

@* Horizontal spacing *@
<div class="flex space-x-2">
    <NvButton>Edit</NvButton>
    <NvButton>Delete</NvButton>
    <NvButton>Share</NvButton>
</div>

Individual spacing:

razor<div class="mt-8 mb-6 px-4">
    @* margin-top: 32px, margin-bottom: 24px, padding-x: 16px *@
</div>

Customizing Nova Components

Nova components are designed to work seamlessly with Tailwind utilities. While components handle their internal styling, you control their position, spacing, and responsive behavior through the Class parameter. This section shows you how to extend Nova components without breaking their design.

Key principle: Add layout and spacing utilities; avoid overriding component internals (padding, colors, borders) which may cause conflicts.

Adding Classes to Components

Every Nova component accepts a Class parameter for adding Tailwind utilities. Use this for layout positioning, margins, widths, and responsive behavior:

Nova components accept a Class parameter for customization:

razor@* Add margin using Class *@
<NvButton Class="mt-4">
    Button with Margin
</NvButton>

@* Use component parameters for component-specific features *@
<NvButton Fluid="true">
    Full Width Button (use 'Fluid' parameter, not 'w-full' class)
</NvButton>

@* Adjust card spacing and background *@
<div class="bg-level-00 rounded-lg shadow-lg p-8">
    Custom Card Content
</div>

Styling Content Inside Components

Many Nova components accept child content (RenderFragments). You have full control over the styling of content you place inside components using standard HTML elements and Tailwind classes:

razor@* Simple text with custom styling *@
<NvButton Emphasis="high">
    <span class="typo-text-md-medium">Save Changes</span>
</NvButton>

@* Complex content with icons *@
<NvButton>
    <span class="flex items-center gap-2">
        <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 20 20">
            <path d="M7.707 10.293a1 1 0 10-1.414 1.414l3 3a1 1 0 001.414 0l3-3a1 1 0 00-1.414-1.414L11 11.586V6h5a2 2 0 012 2v7a2 2 0 01-2 2H4a2 2 0 01-2-2V8a2 2 0 012-2h5v5.586l-1.293-1.293zM9 4a1 1 0 012 0v2H9V4z" />
        </svg>
        <span class="typo-text-sm-medium">Download</span>
    </span>
</NvButton>

@* For layout control, wrap the button instead of overriding its classes *@
<div class="px-8">
    <NvButton>Centered Button</NvButton>
</div>

⚠️ Important: Avoid overriding component internals like padding (px-*, py-*) directly on Nova components. Use wrapper elements for layout control instead.

Conditional Styling

Dynamic UI often requires different styles based on state or parameters. Use C# methods or ternary expressions to apply different Tailwind utilities based on your data:

⚠️ Critical: Never Build Class Names Dynamically

Tailwind scans your source files for complete class names at build time. Dynamic class construction breaks this:

razor@* ❌ WRONG - These classes won't be generated *@
<div class="text-@color-500">Won't work</div>
<div class="bg-@theme-@shade">Won't work</div>
<p class="@(isLarge ? "text-lg" : $"text-{size}")">Won't work</p>

@* ✅ CORRECT - Use complete class names *@
<div class="@(color == "red" ? "text-red-500" : "text-blue-500")">Works!</div>
<div class="@(theme == "dark" ? "bg-gray-900" : "bg-white")">Works!</div>
<p class="@(isLarge ? "text-lg" : "text-sm")">Works!</p>

📚 Learn more: Tailwind - Dynamic Class Names

Proper conditional styling:

razor@code {
    private bool isActive = true;
}

<span class="@GetStatusClass()">
    @(isActive ? "Active" : "Inactive")
</span>

@code {
    private string GetStatusClass()
    {
        return isActive
            ? "inline-block px-3 py-1 rounded-full typo-text-sm-medium bg-feedback-success-low text-feedback-success-high"
            : "inline-block px-3 py-1 rounded-full typo-text-sm-medium bg-level-10 text-medium";
    }
}

Cleaner approach with string interpolation:

razor<span class="inline-block px-3 py-1 rounded-full typo-text-sm-medium @(isActive ? "bg-feedback-success-low text-feedback-success-high" : "bg-level-10 text-medium")">
    @(isActive ? "Active" : "Inactive")
</span>

Responsive Behavior

Tailwind's responsive prefixes (sm:, md:, lg:, xl:) let you adapt layouts to different screen sizes. Apply these to Nova components and containers to create mobile-first responsive interfaces:

Mobile-first approach: Base styles apply to mobile, then override for larger screens.

razor@* Different layouts at different breakpoints *@
<div class="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
    <h2 class="typo-heading-lg-bold">Products</h2>
    <NvButton Emphasis="high">Add Product</NvButton>
</div>

@* Responsive spacing *@
<div class="p-4 md:p-6 lg:p-8">
    @* padding increases with screen size *@
</div>

@* Hide on mobile, show on desktop *@
<div class="hidden lg:block">
    <div class="bg-level-00 rounded-lg shadow p-4">Desktop only sidebar</div>
</div>

Working with Forms

Forms benefit greatly from thoughtful layout and spacing. Use Tailwind to create clear visual hierarchy, group related fields, and provide proper spacing for labels, inputs, and actions. Nova form components integrate seamlessly with these patterns.

Form layout principles:

  • Container max-width for readability (max-w-2xl)
  • Consistent vertical spacing between fields (space-y-4 or space-y-6)
  • Visual sections with borders to group related inputs
  • Clear separation between form content and action buttons

Form Layout

A complete form with header, fields, and actions demonstrating best practices for spacing and grouping:

razor@page "/users/create"

<div class="max-w-2xl mx-auto space-y-6">
    @* Form header *@
    <div class="border-b border-low pb-4">
        <h2 class="typo-heading-lg-bold text-high">Create User</h2>
        <p class="typo-text-sm-regular text-medium mt-2">
            Fill in the user details below
        </p>
    </div>

    <EditForm Model="@model" OnValidSubmit="HandleSubmit">
        @* Form fields *@
        <div class="space-y-4">
            <NvFieldtext 
                Label="Full Name" 
                Placeholder="Enter full name"
                @bind-Value="model.Name"
                Required="true" 
            />
            
            <NvFieldtext 
                Type="email"
                Label="Email Address" 
                Placeholder="user@example.com"
                @bind-Value="model.Email"
                Required="true" 
            />
            
            <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                <NvFieldtext Label="Phone" Placeholder="+32 123 45 67 89" @bind-Value="model.Phone" />
                <NvFieldtext Label="Department" Placeholder="Engineering" @bind-Value="model.Department" />
            </div>
            
            <NvFieldtextarea 
                Label="Notes"
                Placeholder="Additional information..."
                Rows="4"
                @bind-Value="model.Notes"
            />
        </div>

        @* Form actions *@
        <div class="flex items-center justify-end gap-3 pt-4 border-t border-gray-200 mt-6">
            <NvButton Type="button" OnClick="Cancel">Cancel</NvButton>
            <NvButton Type="submit" Emphasis="high">Create User</NvButton>
        </div>
    </EditForm>
</div>

@code {
    private UserModel model = new();

    private void HandleSubmit()
    {
        // Handle form submission
    }

    private void Cancel()
    {
        // Handle cancellation
    }

    public class UserModel
    {
        public string Name { get; set; } = "";
        public string Email { get; set; } = "";
        public string Phone { get; set; } = "";
        public string Department { get; set; } = "";
        public string Notes { get; set; } = "";
    }
}

Inline Form Elements

For search bars, filters, or quick actions, combine form fields with buttons horizontally. Use flex-1 on the input container to make it grow, and items-end to align the button with the input:

razor<div class="flex items-end gap-4">
    <div class="flex-1">
        <NvFieldtext Label="Search" Placeholder="Search users..." @bind-Value="searchTerm" />
    </div>
    <NvButton Emphasis="high" OnClick="Search">Search</NvButton>
</div>

@code {
    private string searchTerm = "";

    private void Search()
    {
        // Perform search
    }
}

Dark Mode Support

Nova's semantic tokens automatically adapt to dark mode, so when you use intentional tokens like bg-level-00, text-high, or border-low, they'll change appropriately when dark mode is active.

Key insight: If you're using semantic/intentional tokens throughout your app, dark mode support is built-in. You only need explicit dark: utilities when using primitive colors for specific purposes (like data visualization).

How it works: When .dark class is present on a parent, Nova's semantic tokens adapt automatically, and any dark:* utilities you've added will activate.

Best practice: Nova components and semantic tokens handle dark mode automatically. Only add explicit dark: variants when using primitive colors for special cases.

Using Semantic Tokens for Dark Mode

When using semantic tokens, dark mode adaptation is automatic:

razor@* These adapt automatically - no dark: variants needed! *@
<div class="bg-level-00">
    <h1 class="text-high typo-heading-lg-bold">Title</h1>
    <p class="text-medium typo-text-md-regular">
        Description text that automatically adapts to dark mode
    </p>
</div>

If you must use primitive colors (e.g., for data visualization), add explicit dark variants:

razor@* Only when using primitive colors *@
<div class="bg-green-500 dark:bg-green-700">
    <span class="text-white">Chart element</span>
</div>

Dark Mode for Cards and Containers

With semantic tokens, your cards automatically adapt to dark mode:

razor@* Semantic tokens handle dark mode automatically *@
<div class="bg-level-00 rounded-lg shadow border border-low p-6">
    <h2 class="typo-heading-md-bold text-high mb-4">Card Title</h2>
    <p class="typo-text-md-regular text-medium">
        Card content that automatically works in both light and dark mode
    </p>
</div>

Result:

  • Light mode: white background, dark text, light border
  • Dark mode: dark background, light text, dark border
  • All automatic - no dark: variants needed!

Toggling Dark Mode

Implement a dark mode toggle by adding/removing the dark class on a parent container. Store the preference in localStorage to persist across sessions:

Add this to your main layout (e.g., MainLayout.razor):

razor<div class="@(isDarkMode ? "dark" : "")">
    <div class="min-h-screen bg-level-00 text-high">
        <div class="flex justify-end p-4">
            <NvButton OnClick="ToggleDarkMode">
                @(isDarkMode ? "Light Mode" : "Dark Mode")
            </NvButton>
        </div>
        
        @Body
    </div>
</div>

@code {
    private bool isDarkMode = false;

    private void ToggleDarkMode()
    {
        isDarkMode = !isDarkMode;
    }
}

Complete Layout Examples

The following examples demonstrate complete, production-ready layouts with detailed inline documentation explaining every Tailwind class choice.

Example 1: Application Shell with Sidebar

This example shows a classic sidebar + main content layout pattern used in enterprise applications.

MainLayout.razor:

razor@inherits LayoutComponentBase
@inject PageStateService PageState
@inject NavigationManager NavigationManager
@implements IDisposable

@* ============================================================================
   TAILWIND LAYOUT GUIDE FOR EMS APPLICATION
   ============================================================================
   
   This layout uses a classic "sidebar + main content" pattern.
   The structure is:
   
   ┌─────────────────────────────────────────────────────────────┐
   │ flex w-full (root container)                                │
   │ ┌──────────┬────────────────────────────────────────────────┤
   │ │          │  grow flex flex-col h-screen (main area)       │
   │ │ Sidebar  │  ┌──────────────────────────────────────────┐  │
   │ │ (fixed   │  │ header (breadcrumbs + title + tabs)      │  │
   │ │  width)  │  ├──────────────────────────────────────────┤  │
   │ │          │  │ main > section > card (@Body goes here)  │  │
   │ │          │  │                                          │  │
   │ │          │  └──────────────────────────────────────────┘  │
   │ └──────────┴────────────────────────────────────────────────┘
   └─────────────────────────────────────────────────────────────┘
   
   ============================================================================ *@

@* ROOT CONTAINER
   ─────────────────────────────────────────────────────────────────────────────
   flex    → Creates a flexbox container. Children (sidebar + main) will sit
             side by side horizontally (default flex-direction is row).
   w-full  → Width 100%. Ensures the container spans the entire viewport width.
   ───────────────────────────────────────────────────────────────────────────── *@
<div class="flex w-full">

    @* SIDEBAR
       The NvSidebar component has its own fixed width defined internally.
       Because the main content uses "grow", the sidebar keeps its natural
       width while main expands to fill remaining space. *@
    <NvSidebar Type="NvSidebar.TypeEnum.collapsible">
        <NvSidebarlogo Label="@("EMS")">
        </NvSidebarlogo>
        <NvSidebarcontent>
            <NvSidebarnavitem Icon="NvSidebarnavitem.IconEnum.home" Active="@IsActive("/")">
                <NavLink href="/">Home</NavLink>
            </NvSidebarnavitem>
            <NvSidebarnavitem Icon="NvSidebarnavitem.IconEnum.database" Collapsible
                Active="@IsActivePrefix("/acquisition")">
                Acquisition
                <NvSidebarnavsubitem Active="@IsActive("/acquisition/iccp")">
                    <NavLink href="/acquisition/iccp">ICCP</NavLink>
                </NvSidebarnavsubitem>
                <NvSidebarnavsubitem Active="@IsActive("/acquisition/rtu")">
                    <NavLink href="/acquisition/rtu">RTU</NavLink>
                </NvSidebarnavsubitem>
            </NvSidebarnavitem>
        </NvSidebarcontent>
    </NvSidebar>

    @* MAIN CONTENT AREA
       ─────────────────────────────────────────────────────────────────────────
       grow      → flex-grow: 1. This is the KEY class that makes main content
                   expand to fill all remaining horizontal space after sidebar.
                   Without this, main would only be as wide as its content.
       flex      → Makes this a flex container too (for its children).
       flex-col  → flex-direction: column. Children (header, main) stack vertically.
       h-screen  → height: 100vh. Takes full viewport height. Combined with
                   flex-col, this creates a full-height column layout.
       ───────────────────────────────────────────────────────────────────────── *@
    <div class="grow flex flex-col h-screen">

        @if (PageState.Breadcrumbs.Any())
        {
            @* HEADER SECTION
               ─────────────────────────────────────────────────────────────────
               pt-10  → padding-top: 2.5rem (40px). Creates breathing room at
                        top of header. We only use pt (not p or py) because
                        we want specific control over each side's padding.
               ───────────────────────────────────────────────────────────────── *@
            <header class="pt-10">

                @* BREADCRUMBS
                   ─────────────────────────────────────────────────────────────
                   px-10  → padding-left and padding-right: 2.5rem (40px).
                            Horizontal padding aligns breadcrumbs with page content.
                            Using px (not p) so we don't add vertical padding.
                   ───────────────────────────────────────────────────────────── *@
                <NvBreadcrumbs class="px-10">
                    @foreach (var crumb in PageState.Breadcrumbs)
                    {
                        <NvBreadcrumb Current="@crumb.IsCurrent">
                            @if (crumb.Href != null && !crumb.IsCurrent)
                            {
                                <a href="@crumb.Href">@crumb.Label</a>
                            }
                            else
                            {
                                <span>@crumb.Label</span>
                            }
                        </NvBreadcrumb>
                    }
                </NvBreadcrumbs>

                @* PAGE TITLE
                   ─────────────────────────────────────────────────────────────
                   pt-2   → padding-top: 0.5rem (8px). Small gap between
                            breadcrumbs and title. Keeps them visually grouped.
                   px-10  → Matches breadcrumbs horizontal padding for alignment.
                   pb-6   → padding-bottom: 1.5rem (24px). Larger gap below title
                            to separate it from content/tabs below.
                   
                   WHY different padding values?
                   - pt-2 (small): Breadcrumbs and title are related, keep close
                   - pb-6 (large): Title and content are separate sections, more space
                   ───────────────────────────────────────────────────────────── *@
                <h2 class="pt-2 px-10 pb-6">@PageState.Breadcrumbs.Last().Label</h2>

                @if (PageState.Tabs.Any())
                {
                    @* TAB NAVIGATION BAR
                       ─────────────────────────────────────────────────────────
                       nv-tabs     → Nova design system class for tab styling.
                       bg-level-00 → Nova design system background color (base level).
                                     Creates visual separation from content below.
                       ───────────────────────────────────────────────────────── *@
                    <nav class="nv-tabs bg-level-00">

                        @* TAB LIST
                           ─────────────────────────────────────────────────────
                           flex  → Arranges tabs horizontally in a row.
                           px-8  → padding-left/right: 2rem (32px). Slightly less
                                   than px-10 used above because tabs have their
                                   own internal padding. This creates visual balance.
                           ───────────────────────────────────────────────────── *@
                        <ul class="flex px-8">
                            @foreach (var tab in PageState.Tabs)
                            {
                                <li>
                                    <NavLink href="@tab.Url" class="@GetTabClass(tab.Url)">
                                        <NvIcon Name="@tab.Icon" Size="NvIcon.SizeEnum.md"></NvIcon>
                                        @tab.Label
                                    </NavLink>
                                </li>
                            }
                        </ul>
                    </nav>
                }
                else
                {
                    @* DIVIDER (when no tabs)
                       ─────────────────────────────────────────────────────────
                       border-b   → border-bottom. Creates a horizontal line.
                       border-low → Nova design system border color (subtle).
                       
                       WHY? When there are no tabs, we still want visual separation
                       between header and content. This thin line provides that
                       without taking up space like the tab bar would.
                       ───────────────────────────────────────────────────────── *@
                    <div class="border-b border-low"></div>
                }
            </header>
        }

        @* MAIN ELEMENT
           ─────────────────────────────────────────────────────────────────────
           flex    → Creates flex container for the section inside.
           grow    → flex-grow: 1. Expands to fill remaining vertical space
                     after header. This is what makes the content area stretch
                     to fill the screen height.
           w-full  → width: 100%. Ensures main spans full width of parent.
           ───────────────────────────────────────────────────────────────────── *@
        <main class="flex grow w-full">

            @* CONTENT SECTION (the gray background area)
               ─────────────────────────────────────────────────────────────────
               p-8         → padding: 2rem (32px) on all sides. Creates gutter
                             around the white card container.
               bg-level-10 → Nova design system elevated background (gray).
                             Creates contrast with the white card inside.
               h-full      → height: 100%. Fills parent height.
               grow        → Expands to fill available space.
               
               WHY bg-level-10?
               This gray background creates visual depth. The white card (level-00)
               appears to "float" above it, creating a sense of hierarchy.
               ───────────────────────────────────────────────────────────────── *@
            <section class="p-8 bg-level-10 h-full grow">

                @* CARD CONTAINER (white box where page content lives)
                   ─────────────────────────────────────────────────────────────
                   bg-level-00 → Nova design system base background (white/light).
                                 This is the "card" that contains page content.
                   rounded-lg  → border-radius: 0.5rem (8px). Softens corners
                                 for a modern, friendly appearance.
                   border      → Adds a 1px border around the card.
                   border-low  → Nova design system subtle border color.
                                 Defines card edges without being harsh.
                   min-h-1/2   → min-height: 50%. Card is always at least half
                                 the parent height, even with little content.
                                 Prevents awkwardly small cards on empty pages.
                   
                   WHY these choices together?
                   - White background + gray parent = visual elevation
                   - Rounded corners = modern UI convention
                   - Subtle border = defines edges without heavy visual weight
                   - min-h-1/2 = consistent appearance across pages
                   ───────────────────────────────────────────────────────────── *@
                <div class="bg-level-00 rounded-lg border border-low min-h-1/2">
                    @Body
                </div>
            </section>
        </main>
    </div>
</div>

@code {
    private string CurrentPath => new Uri(NavigationManager.Uri).AbsolutePath;

    protected override void OnInitialized()
    {
        PageState.OnChange += StateHasChanged;
        NavigationManager.LocationChanged += OnLocationChanged;
    }

    private void OnLocationChanged(object? sender, LocationChangedEventArgs e)
    {
        StateHasChanged();
    }

    private bool IsActive(string path)
    {
        if (path == "/") return CurrentPath == "/";
        return CurrentPath.Equals(path, StringComparison.OrdinalIgnoreCase);
    }

    private bool IsActivePrefix(string prefix)
    {
        return CurrentPath.StartsWith(prefix, StringComparison.OrdinalIgnoreCase);
    }

    private string GetTabClass(string url)
    {
        var isActive = CurrentPath.Equals(url, StringComparison.OrdinalIgnoreCase);
        return isActive ? "nv-link active" : "nv-link";
    }

    public void Dispose()
    {
        PageState.OnChange -= StateHasChanged;
        NavigationManager.LocationChanged -= OnLocationChanged;
    }
}

Key Takeaways from this Layout:

  1. Nested Flex Containers: The root uses flex for horizontal layout (sidebar + main), while the main area uses flex flex-col for vertical stacking (header + content).

  2. The grow Class is Essential:

    • On the main content area: makes it fill remaining space after sidebar
    • On the content section: makes it expand vertically to fill available height
  3. Padding Patterns:

    • pt-10, px-10 on header elements for consistent alignment
    • p-8 on section for uniform gutter around the card
    • Different values (pt-2 vs pb-6) create visual hierarchy
  4. Background Levels: bg-level-10 (gray) + bg-level-00 (white) creates depth and card elevation

Example 2: Data Table Page with Toolbar

This example shows a common pattern for list/table pages with filters and actions.

UsersList.razor:

razor@page "/users/list"
@inject PageStateService PageState

<PageTitle>Users List</PageTitle>

@* ============================================================================
   PAGE CONTENT LAYOUT PATTERNS
   ============================================================================
   
   This page demonstrates common patterns for content inside the card container:
   
   ┌─────────────────────────────────────────────────────────────┐
   │ TOOLBAR (p-6 border-b flex)                                 │
   │ ┌─────────────────────────────────┐ ┌─────────────────────┐ │
   │ │ Filters (flex grow gap-4)       │ │ Actions (flex gap-4)│ │
   │ └─────────────────────────────────┘ └─────────────────────┘ │
   ├─────────────────────────────────────────────────────────────┤
   │ DATA TABLE (pb-4)                                           │
   │                                                             │
   └─────────────────────────────────────────────────────────────┘
   
   ============================================================================ *@

@* TOOLBAR ROW
   ─────────────────────────────────────────────────────────────────────────────
   p-6       → padding: 1.5rem (24px) on all sides. Consistent inner spacing
               that matches the card's visual style.
   border-b  → border-bottom: 1px solid. Creates horizontal separator below toolbar.
   border-low → Nova design system subtle border color.
   flex      → display: flex. Children arranged horizontally in a row.
   
   PATTERN: Toolbar with left-aligned filters and right-aligned actions.
   We achieve this by having two flex children:
   1. Left group with "grow" → expands to push right group to the edge
   2. Right group without grow → stays at its natural width on the right
   ─────────────────────────────────────────────────────────────────────────────  *@
<div class="p-6 border-b border-low flex">

    @* LEFT GROUP: FILTERS
       ─────────────────────────────────────────────────────────────────────────
       flex   → Children (dropdowns, button) arranged horizontally.
       grow   → flex-grow: 1. THIS IS THE KEY! This group expands to fill
                available space, pushing the right group (actions) to the edge.
                Without this, both groups would sit on the left.
       gap-4  → gap: 1rem (16px) between children. Creates consistent spacing
                between filter controls without using margins on each element.
       
       WHY gap instead of margins?
       - gap only adds space BETWEEN items, not before first or after last
       - Easier to maintain: change one value instead of margins on each child
       - Works automatically when adding/removing children
       ───────────────────────────────────────────────────────────────────────── *@
    <div class="flex grow gap-4">
        <NvFielddropdown FilterMode="NvFielddropdown.FilterModeEnum.strict" 
            Filterable="true"
            Options="MonthListOptions.ToArray()" 
            Placeholder="Select a month...">
        </NvFielddropdown>
        <NvFielddropdown FilterMode="NvFielddropdown.FilterModeEnum.strict" 
            Filterable="true"
            Options="YearListOptions.ToArray()" 
            Placeholder="Select a year...">
        </NvFielddropdown>
        <NvButton>
            Search
            <NvIcon Name="@("search")" Slot="trailing-icon"></NvIcon>
        </NvButton>
    </div>

    @* RIGHT GROUP: ACTIONS
       ─────────────────────────────────────────────────────────────────────────
       flex   → Children arranged horizontally (if multiple buttons).
       gap-4  → Consistent 16px spacing between action buttons.
       
       NOTE: No "grow" here! This group stays at its natural width.
       Because the left group has "grow", this group gets pushed to the right.
       ───────────────────────────────────────────────────────────────────────── *@
    <div class="flex gap-4">
        <NvButton Emphasis="NvButton.EmphasisEnum.medium">
            Import
            <NvIcon Name="@("download")" Slot="trailing-icon"></NvIcon>
        </NvButton>
    </div>
</div>

@* DATA TABLE WRAPPER
   ─────────────────────────────────────────────────────────────────────────────
   pb-4  → padding-bottom: 1rem (16px). Adds space between table bottom and
           card edge. Prevents content from touching the card boundary.
   
   WHY only pb (padding-bottom)?
   - The table component has its own internal horizontal padding
   - We only need bottom spacing to match the toolbar's visual weight
   - Using p-6 would add unnecessary horizontal padding (double-padding)
   ─────────────────────────────────────────────────────────────────────────────  *@
<div class="pb-4">
    <NvDatatable Columns="@employeeColumns" Rows="@employeeData" 
        Pagination="@(new NovaComponents.Models.NvDatatablePaginationConfig
        {
            Mode = NovaComponents.Models.NvDatatablePaginationMode.Client,
            InitialPageSize = 20,
            PageSizeOptions = new[] { 10, 20, 50, 100 }
        })">
    </NvDatatable>
</div>

@code {
    protected override void OnInitialized()
    {
        PageState.SetBreadcrumbs(
            new BreadcrumbItem("Home", "/"),
            new BreadcrumbItem("Users"),
            new BreadcrumbItem("All Users", IsCurrent: true)
        );
        PageState.SetTabs(
            new TabItem("All Users", "users", "/users/list"),
            new TabItem("Roles", "shield", "/users/roles")
        );
    }

    private List<NovaComponents.NvFielddropdownOptions> DepartmentOptions = new() {
        new NovaComponents.NvFielddropdownOptions { Label = "Engineering", Value = "Engineering" },
        new NovaComponents.NvFielddropdownOptions { Label = "Marketing", Value = "Marketing" },
        new NovaComponents.NvFielddropdownOptions { Label = "Sales", Value = "Sales" },
        new NovaComponents.NvFielddropdownOptions { Label = "HR", Value = "HR" },
        new NovaComponents.NvFielddropdownOptions { Label = "IT", Value = "IT" },
        new NovaComponents.NvFielddropdownOptions { Label = "Finance", Value = "Finance" }
    };

    private List<NovaComponents.NvFielddropdownOptions> StatusOptions = new() {
        new NovaComponents.NvFielddropdownOptions { Label = "Active", Value = "Active" },
        new NovaComponents.NvFielddropdownOptions { Label = "Inactive", Value = "Inactive" },
        new NovaComponents.NvFielddropdownOptions { Label = "Pending", Value = "Pending" }
    };

    private List<NovaComponents.Models.NvDatatableColumn> employeeColumns = new()
    {
        new() { Field = "Name", HeaderName = "Full Name" },
        new() { Field = "Email", HeaderName = "Email Address" },
        new() { Field = "Department", HeaderName = "Department" },
        new() { Field = "Age", HeaderName = "Age" },
        new() { Field = "Salary", HeaderName = "Salary" },
    };

    private List<Dictionary<string, object?>> employeeData = new()
    {
        new() {
            ["Name"] = "John Smith",
            ["Email"] = "john.smith@company.com",
            ["Department"] = "Engineering",
            ["Age"] = 32,
            ["Salary"] = 75000
        },
        // ... more data
    };
}

Key Takeaways from this Page Layout:

  1. Toolbar Pattern: Use flex parent with two children—left side with grow, right side without

  2. The Power of gap: Instead of managing margins on individual items, gap-4 handles all spacing automatically

  3. Strategic Padding: Different padding values for different purposes:

    • p-6 on toolbar for consistent inner spacing
    • pb-4 on table wrapper to prevent content touching edges
    • No horizontal padding on table wrapper (component handles it)
  4. Visual Separators: border-b border-low creates subtle division between toolbar and content


Advanced Patterns

As your application grows, you'll encounter repeated styling patterns. These advanced techniques help you create reusable, maintainable styles while keeping your components clean. Extract common patterns into CSS classes or Razor components to reduce duplication and ensure consistency.

Creating Reusable CSS Classes

When you repeat the same utility combinations across multiple components, extract them using Tailwind's @apply directive. This creates semantic class names while maintaining the utility-first approach:

When you repeat the same utility combinations, extract them using @apply in your CSS file.

Create or edit Styles/custom.css:

css.page-section {
    @apply bg-level-00 rounded-lg shadow-sm p-6 mb-6;
}

.stat-card {
    @apply bg-gradient-to-br from-brand-500 to-brand-700 text-white rounded-lg p-6;
}

.form-section {
    @apply border-b border-gray-200 pb-6 mb-6 last:border-0 last:pb-0 last:mb-0;
}

Import in your Styles/tailwind.css:

css@import 'tailwindcss';
@import '@nova-design-system/nova-base/theme/plugin.css';
@import '@nova-design-system/nova-base/dist/css/spark.css';
/* Or import ocean.css instead of spark.css. */

@import './custom.css';

Existing projects can keep the JavaScript theme/plugin configuration documented under Deprecated JavaScript configuration in Guides/Tailwind Setup; do not combine that setup with theme/plugin.css.

Usage in Razor:

razor<div class="page-section">
    <h2 class="typo-heading-md-bold mb-4">Overview</h2>
    <div class="grid grid-cols-3 gap-4">
        <div class="stat-card">
            <p class="typo-text-sm-regular opacity-90">Total Revenue</p>
            <p class="typo-heading-lg-bold mt-2">€125,000</p>
        </div>
    </div>
</div>

List Layouts

Display collections of items with consistent spacing and hover effects. Use divide-y for separators between items and negative margins (-mx-4) with padding to extend hover backgrounds beyond container edges:

Key utilities: divide-y, hover:bg-*, negative margins for extended hover areas

razor@foreach (var user in users)
{
    <div class="py-4 flex items-center justify-between hover:bg-level-10 px-4 -mx-4 rounded">
        <div class="flex items-center gap-4">
            <div class="w-10 h-10 rounded-full bg-brand-100 flex items-center justify-center">
                <span class="typo-text-md-medium text-brand-700">
                    @user.Name[0]
                </span>
            </div>
            <div>
                <p class="typo-text-md-medium text-high">@user.Name</p>
                <p class="typo-text-sm-regular text-medium">@user.Email</p>
                <p class="typo-text-sm-regular text-gray-500">@user.Email</p>
            </div>
        </div>
        <div class="flex items-center gap-2">
            <NvButton Size="NvButton.SizeEnum.sm" OnClick="() => Edit(user)">Edit</NvButton>
            <NvButton Size="NvButton.SizeEnum.sm" Danger="true" OnClick="() => Delete(user)">Delete</NvButton>
        </div>
    </div>
}

@code {
    private List<User> users = new();

    private void Edit(User user) { }
    private void Delete(User user) { }

    public class User
    {
        public string Name { get; set; } = "";
        public string Email { get; set; } = "";
    }
}

Empty States

Empty states guide users when no data is available. Center the content vertically and horizontally, use an icon for visual interest, and provide a clear call-to-action:

Pattern: flex flex-col items-center justify-center for centering, constrained text width for readability

razor@if (!items.Any())
{
    <div class="flex flex-col items-center justify-center py-12 text-center">
        <div class="w-16 h-16 bg-level-10 rounded-full flex items-center justify-center mb-4">
            <NvIcon Name="inbox" Class="text-low" Size="@NvIcon.SizeEnum.lg" />
        </div>
        <p class="typo-text-lg-medium text-high mb-2">No items found</p>
        <p class="typo-text-sm-regular text-medium mb-6 max-w-sm">
            Get started by creating your first item
        </p>
        <NvButton Emphasis="high" OnClick="CreateItem">Create Item</NvButton>
    </div>
}

@code {
    private List<object> items = new();
    
    private void CreateItem() { }
}

Component-Specific Styling with CSS

Blazor's CSS isolation feature allows you to create scoped styles that only apply to a specific component. Combine this with Tailwind's @apply to keep your Razor markup clean while maintaining component-specific styling:

For component-specific styles, create a .razor.css file alongside your component:

MyComponent.razor:

razor<div class="my-component">
    <h2 class="typo-heading-md-bold">@Title</h2>
    <div class="content">
        @ChildContent
    </div>
</div>

@code {
    [Parameter] public string Title { get; set; } = "";
    [Parameter] public RenderFragment? ChildContent { get; set; }
}

MyComponent.razor.css:

css.my-component {
    @apply bg-white dark:bg-gray-800 rounded-lg p-6 shadow-sm;
}

.my-component .content {
    @apply mt-4 space-y-4;
}

Best Practices

1. Use Semantic Tokens, Not Primitive Colors

❌ Avoid:

razor<div class="bg-gray-50 text-gray-900 border-gray-200">

✅ Prefer:

razor<div class="bg-level-10 text-high border-low">

2. Keep Components Focused

Don't overload the Class parameter with too many utilities. Extract repeated patterns.

❌ Avoid:

razor<div class="bg-level-00 rounded-lg shadow-md hover:shadow-lg transition-shadow p-6 border border-low">

✅ Prefer:

css/* In custom.css */
.elevated-card {
    @apply bg-level-00 rounded-lg shadow-md hover:shadow-lg 
           transition-shadow p-6 border border-low;
}
razor<div class="elevated-card">

3. Mobile-First Responsive Design

Build for mobile first, then add responsive classes for larger screens.

razor<div class="
    grid grid-cols-1 gap-4    @* mobile *@
    md:grid-cols-2 md:gap-6  @* tablet *@
    lg:grid-cols-3 lg:gap-8  @* desktop *@
">

4. Consistent Spacing

Use consistent spacing values from the Nova scale:

  • Small gaps: gap-2 (8px)
  • Medium gaps: gap-4 (16px)
  • Large gaps: gap-6 (24px)
  • Extra large: gap-8 (32px)

5. Typography Hierarchy

Always use Nova typography classes:

razor@* ❌ Don't use Tailwind font utilities *@
<h1 class="text-3xl font-bold">

@* ✅ Use Nova typography *@
<h1 class="typo-heading-xl-bold">

Common Pitfalls

1. Conflicting Styles

Be careful when combining Nova component styles with Tailwind:

razor@* Nova components already have padding, border-radius, etc. *@
@* Adding these may cause conflicts: *@
<NvButton Class="p-8 rounded-full border-2">  @* ⚠️ May conflict *@

@* Better: Use layout utilities only *@
<NvButton Class="mt-4 w-full">  @* ✅ Safe *@

2. Not Using Design Tokens

Always use the Nova token system for consistency:

razor@* ❌ Don't hardcode colors *@
<div class="bg-blue-500">

@* ✅ Use Nova brand or feedback colors *@
<div class="bg-brand-500">

3. Overusing @apply

Don't use @apply for every single element. It's meant for reusable patterns, not one-off styles.

4. Forgetting Razor Syntax

Remember to escape @ in Razor when using email addresses or conditional classes:

razor@* Correct syntax for conditional classes *@
<div class="@(isActive ? "bg-primary-500" : "bg-gray-500")">

@* For static classes, no @ needed *@
<div class="flex items-center gap-4">

Quick Reference

Essential Layout Classes

razor@* Containers *@
max-w-7xl mx-auto px-4 py-8

@* Flex *@
flex items-center justify-between gap-4
flex flex-col space-y-4

@* Grid *@
grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6

@* Spacing *@
p-4 px-6 py-8 mt-4 mb-6 gap-4 space-y-6

@* Positioning *@
relative absolute inset-0 top-0 left-0

@* Sizing *@
w-full h-full min-h-screen max-w-md

@* Display *@
hidden lg:block

Breakpoints

plaintextsm:   640px   @* Small devices (landscape phones) *@
md:   768px   @* Medium devices (tablets) *@
lg:   1024px  @* Large devices (desktops) *@
xl:   1280px  @* Extra large devices *@
2xl:  1536px  @* 2X large devices *@

Additional Resources


Get Help

If you need assistance with styling or have questions:

  • Check the Nova Blazor Storybook for component examples
  • Review existing components in your codebase
  • Reach out to the Nova Design System team

Remember: Nova handles the components, Tailwind handles the layout. Focus on spacing, positioning, and composition—the components are already beautifully designed for you.