Writing CSS
Once your stylesheets have been set up how you want them, you can start writing CSS with the Norton Design System.
Themingβ
The Norton Design System's CSS is fully themeable through the use of Sass variables. The variables that capture the foundational style elements constitute the main interface for theming an application. Refer to the variables table to learn more about these customizable variables.
Recommended practicesβ
The following practices will help you get the most out of the Norton Design System's CSS.
Use CSS custom properties, not Sass variablesβ
CSS custom properties are live variables that can be modified via JavaScript and will always reference the current value of the token. Sass variables, on the other hand, are hard-coded into the stylesheet when the CSS is compiled and cannot be changed after that point.
@use '@wwnds/core';
// π Good: use the CSS custom property
.foo {
font-family: var(--nds-font-family-serif);
}
// π Bad: use the Sass variable
.foo {
font-family: core.$font-family-serif;
}
Use role tokens, not system tokensβ
Using role tokens will facilitate theming in your application since role tokens can be customized, whereas system tokens cannot. Refer to the design token types inheritance outline for more clarification of this convention.
@use '@wwnds/core';
// β¨ Best: modify a known role token at this scope and then use it
// (not always possible)
.foo {
--nds-background-color: var(--nds-base-color-20);
background-color: var(--nds-background-color);
}
// π Good: use the role token
.foo {
background-color: var(--nds-base-color-20);
}
// π Bad: use the system token
.foo {
background-color: var(--nds-navy-20);
}
Override token values instead of property values whenever possibleβ
Some tokens, like text-color
and background-color
are set globally and are designed to use the CSS cascade to style all elements.
We encourage you to embrace the cascadeβa fundamental feature of CSSβmodifying token values at specific scopes to accomplish your goals instead of modifying properties directly.
@use '@wwnds/core';
// π Good: override the token value and then use it
.foo {
--nds-text-color: var(--nds-base-color-10);
--nds-background-color: var(--nds-primary-color-80);
color: var(--nds-text-color);
background-color: var(--nds-background-color);
}
// Okay: override the property value
.foo {
color: var(--nds-base-color-10);
background-color: var(--nds-primary-color-80);
}
Compose your own CSS custom properties out of existing tokensβ
We deliberately provide only a small set of opinionated design tokens but recognize that you may have application-specific styles that would make sense as tokens.
@use '@wwnds/core';
// π Good: declare and use your own reusable custom properties out of existing tokens
:root {
--brand-gradient: linear-gradient(
var(--nds-primary-color),
var(--nds-primary-color-90),
);
}
Use Sass modulesβ
When using the Sass directly, avoid @import
, favoring @forward
and @use
.
// β¨ Best: forward a configured version of the core library
@forward '@wwnds/core' with (
// configured Sass variables
$radius-base: var(--nds-radius-xl),
);
// π Good: use the core library directly
@use '@wwnds/core';
// π Bad: use the deprecated import syntax
@import '@wwnds/core/full';