Styling and Theming

UXP provides a theme system with CSS variables for styling your v5 apps.


Theme System

Access the current theme in your components:

import { useUXPContext } from "uxp/components";

const MyComponent = () => {
    const uxpContext = useUXPContext();
    const theme = uxpContext.theme;

    return (
        <div style={{
            backgroundColor: theme.backgroundColor,
            color: theme.primaryTextColor
        }}>
            Content
        </div>
    );
};

CSS Variables

Use CSS variables in your stylesheets for automatic theme support:

Available Theme Variables


SCSS Organization

V5 apps use a simple, component-based SCSS structure:

Key Points:

  • global.scss - Shared mixins, variables, and utility classes used across components

  • Component SCSS - Co-located with component files, imported directly

  • App Prefix - Use your app prefix (e.g., ilocapp_ for Location app) to avoid conflicts

  • BEM Naming - Follow BEM convention: prefix_component__element--modifier

Note: CSS scoping will be added in future versions. For now, use app-specific prefixes to prevent style conflicts.


global.scss

Define shared mixins, variables, and utilities in src/global.scss:

Import global.scss once in src/index.tsx:


Component SCSS

Co-locate SCSS files with components and import directly:


Naming Convention

Use BEM with your app prefix:

Choosing your prefix:

  • Use app name abbreviation

  • Keep it short (4-8 characters)

  • Examples: ilocapp_ (Location), iuserapp_ (User)


RTL Support

Use logical CSS properties for RTL support:


Quick Tips

DO:

  • ✅ Use CSS variables for all theme colors (backgrounds, text, borders, etc.)

  • ✅ Define shared mixins/variables in global.scss

  • ✅ Co-locate component SCSS with component files

  • ✅ Use app prefix with BEM: ilocapp_component__element

  • ✅ Import global.scss once in index.tsx

  • ✅ Import component SCSS in each component file

  • ✅ Use logical properties (margin-inline-start, text-align: start) for RTL support

  • ✅ Use SCSS variables for non-theme values (spacing, border-radius, breakpoints)

DON'T:

  • ❌ Hardcode colors - always use CSS variables

  • ❌ Use inline styles for theming

  • ❌ Override UXP core component styles directly

  • ❌ Forget app prefix - prevents conflicts with other apps

  • ❌ Import global.scss in multiple files - only once in index.tsx


See Location 5.0 app (/Location/5.0/Resources/views/src/) for complete styling examples and patterns.


Next Steps

Last updated