Skip to content

Theming ​

unix-ui theming is driven by SCSS variables. A default theme ships with the components (imported inside each component) and works with zero configuration.

Overriding Theme Variables ​

Define variables with the same names directly in the project root uni.scss to override globally:

scss
// Custom theme colors (applies to all components)
$m-color-primary: #10b981;
$m-color-danger: #dc2626;

// Custom component metrics
$m-button-normal-height: 48px;
$m-radius-md: 12px;

All variables in the variable file are declared with !default, so user-defined values always win over component defaults, regardless of where they are written.

How It Works ​

  1. Each component imports theme/vars.scss at the top level of its style (all !default), which expands to the default values at compile time
  2. The uni-app x compiler injects the project root uni.scss into every component's style for the same compilation
  3. Variables defined by the user in uni.scss make the !default declarations skip, thus overriding the defaults

Never import vars.scss in uni.scss

Do not @import the library's vars.scss in uni.scss — the compiler injects uni.scss into every component's style, and importing the same file again forms a circular import that fails the build:

[sass] This file is already being loaded.

To override the theme, just define the variables directly — no import of any file is needed.

Variable Reference ​

Theme Colors ​

VariableDescriptionDefault
$m-color-primaryPrimary color#1989fa
$m-color-successSuccess color#07c160
$m-color-warningWarning color#ff976a
$m-color-dangerDanger color#ee0a24
$m-whiteBase white#ffffff
$m-text-colorBase text color#323233
$m-disabled-opacityDisabled opacity0.5
$m-color-default-bgBackground of the default type#ffffff
$m-color-default-borderBorder of the default type#ebedf0

Base Metrics ​

VariableDescriptionDefault
$m-border-widthBase border width1px
$m-radius-mdBase radius8px
$m-radius-maxFull radius999px

Button ​

See Button Theming for the full set of Button variables, including height, padding, font size and radius for each size.

Next Steps ​

  • Button: component props and events
  • FAQ: common pitfalls of the theming mechanism

Released under the MIT License.