New Global Styling Hooks Guidance

New Global Styling Hooks Guidance

This document describes the new Salesforce Lightning Design System (SLDS) global styling hooks and calls out best practices for using them. Use this document to help you implement the changes recommended in Prepare Customizations for SLDS Architecture Updates. See the SLDS Architecture Updates FAQs for more information.

Note: The existing Styling Hooks section describes component styling hooks that you use to style at the component level. The new styling hooks have a wider scope which makes them more versatile.

Global Styling Hooks

Use the global styling hooks to apply Salesforce Lightning Design System values correctly to style your components. The design system determines the values of global styling hooks. Salesforce can change these values at any time and announce the changes in release notes. We don’t support overriding the values of global styling hooks in your customizations.

What are Global Styling Hooks?

Global styling hooks are CSS custom properties that we identify with the '-g-' syntax that comes after the --slds- namespace in the custom property name. They're designed for general use and don't impose specific usage rules. You can apply these properties across standard HTML elements, components, selectors, and more. The versatility of global styling hooks allows designers to implement overarching changes to an application, while complying with the Salesforce Lightning Design System.

We created a system to define the values and names of the styling hooks. The styling hooks typically are in sets, where each hook has a common base name and ends with a different numerical identifier. Generally, the set begins with '1', signifying the smallest or starting value, and increments by 'x'. However, each category can have different ranges within its set, reflecting their usage frequency in UI design. For instance, font sizes likely have a wider range than box-shadows.

Global styling hooks are organized into several property categories, each addressing a different aspect of design:

  • Colors: These properties define the color palette of your application and include primary key colors, UI surface colors, neutral colors, and explicit colors.
  • Font: These properties influence the typography in your application, defining aspects like font family, size, weight, line-height, etc.
  • Border radius: These properties manage the curvature of UI elements' corners, impacting the perceived softness or hardness of components.
  • Shadows: These properties control the appearance of shadows, affecting the depth perception and layering of UI elements.
  • Sizing: These properties dictate the dimensions of UI components, directly affecting layout.
  • Spacing: These properties govern the amount of space between UI elements, guiding the overall layout and ensuring adequate whitespace for readability and aesthetics.

In summary, global styling hooks offer a structured, flexible, and wide-ranging framework for designers to effectively craft their application's look and feel. The SLDS color system is part of these properties and plays a crucial role in defining the visual identity of your application.

Do not reassign globals

Re-assigning a new value to a global styling hook inside your component is prohibited. You will be subject to test failures and future breaking changes. Global styling hooks are only for consuming a predetermined value defined by the Design System. The values are subject to change by Salesforce.

General Concepts

Here are some helpful concepts to hold onto as you read further.

  • Semantic UI Colors: A set of semantic styling hooks that derive the design properties that express the visual language of the SLDS brand. These styling hooks are mutable and their values are subject to change.
    • Surface: Used for backgrounds and large areas of the application that express new visual stacking context to create visual depth.
    • Accent: Accent colors, typically brand colors, to emphasize areas that you want to draw attention too.
    • Container: The fill color for elements that contain text or icons.
    • On: Indicates the color of text or icons that is paired with a container color. All surface, accent, and feedback colors have a pairing and should be used together. For example, on-accent should always be paired with an accent-container value.
    • Feedback: A group of colors that indicate CRUD (CREATE, READ, UPDATE and DELETE) actions such as success, error, warning, info, and disabled feedback states.
  • Accessible System Colors: A set of accessible colors that are used throughout the user interface. These styling hooks contain the complete set of values based on their semantics, brand, neutral, and feedback colors. These styling hooks are mutable and their values are subject to change. Only use in edge cases where a semantic UI color does not make sense.
  • Accessible Color Palettes: A range of accessible color palettes. These colors hold no semantics and can be used within the user interface. These values are immutable and will not change.
  • Ranges: Every global styling hook set uses names that end in a numerical range, starting at 1 and ending at x. The lowest number is always the lightest color of a color range or lowest value of property range. The highest number x is the darkest color of a color range or largest value of a property range.

Understand the SLDS color system

The SLDS color system provides a flexible framework that makes it easier to implement consistent and aesthetically pleasing designs across your products. It consists of derived color values for primary key colors and UI "surfaces", as well as explicit color values. Here we explain how to effectively use this color system.

Surface Colors

A surface can be defined as the canvas in which UI elements sit. Surface colors express the visual stacking context of our application. Surface colors work in harmony so that making sweeping changes like dark mode can be enabled with ease.

Surfaces

--slds-g-color-surface-1
--slds-g-color-surface-2
Usage

Surface colors are reserved for the bottom layer of a surface. These elements are surfaces:

  • application background
  • panels
  • modals
  • docked containers
  • popovers

Anything that comes into the application's view and has a higher stacking context than a previous surface ultimately establishes a new surface.

Surface Containers

--slds-g-color-surface-container-1
--slds-g-color-surface-container-2
--slds-g-color-surface-container-3
Usage

Surface container colors are reserved for the elements that sit on top of a surface, and contain other UI elements or artifacts, such as text or icons. These elements are surface containers:

  • cards or containers
  • buttons
  • button icons
  • tabset

One of the clearest signals that something is a surface container is if there is text or icons residing on it.

WCAG 2.1 color contrast requirements

To ensure proper WCAG 2.1 color contrast requirements, pair the text that sits on top of a surface with an on surface value. It is valid to use any of the accent or feedback colors that are used for text or icons on top of a surface color, for example, --slds-g-color-accent-1

On Surface

--slds-g-color-on-surface-1
--slds-g-color-on-surface-2
--slds-g-color-on-surface-3
Usage

On-surface colors are reserved for text or icons that sit on top of a surface or surface container. Use the on-surface color value as this ensures you pass correct color contrast that meets WCAG 2.1 requirements.

For example, if a surface container uses--slds-g-color-surface-container-3, the text on it should use--slds-g-color-on-surface-3.

Border Colors

--slds-g-color-border-1
--slds-g-color-border-2
Usage

The border colors are reserved for borders or outlines that need to render the neutral color. These are our “grey” border colors. Use only on the following properties:

  • border-color
  • outline
  • stroke

WCAG 2.1 color contrast requirements

For compliance with WCAG 2.1 color contrast guidelines, if your component is an interactive element like a button or input, use--slds-g-color-border-2. If your component is a non-interactive, presentational element like a divider line, use--slds-g-color-border-1.

Accent Colors

Accent colors express a brand's accent color throughout the user interface or to draw attention to an action.

--slds-g-color-accent-1
--slds-g-color-accent-2
--slds-g-color-accent-3
Usage

Accents can be used when there is no text or icon sitting on top of the accent color. Typically accents are used to draw attention to something, and is used as a text color or to denote that an element is active or selected. These elements can use accent colors:

  • links
  • icons

If elements that use accent colors aren't sitting on top of another accent color, pair them with a surface color. For example, pair a link that's using --slds-g-color-accent-1 with a surface that's using --slds-g-color-surface-container-1.

Accent Containers

--slds-g-color-accent-container-1
--slds-g-color-accent-container-2
--slds-g-color-accent-container-3
Usage

Accent containers are similar to surface containers, except that text or icons reside on top of the brand accent. These elements are accent containers:

  • brand buttons
  • selected/active states

Border Accent

--slds-g-color-border-accent-1
--slds-g-color-border-accent-2
--slds-g-color-border-accent-3
Usage

The border accent color is reserved for adding borders or outlines that render the brands accent color. You can use this independently or pair it with an accent container color.

Feedback Colors

Feedback colors are a way to express stateful feedback messaging based on a response or interaction type. We have feedback colors for the following message types:

  • error
  • success
  • warning
  • informational
  • disabled

Each feedback type comes with a generic color to use for text and icons, container colors, on color, and border color values.

Error Colors

Error colors are reserved for component states that indicate that an error has occurred or could occur if action is taken.

--slds-g-color-error-1
--slds-g-color-error-container-1
--slds-g-color-error-container-2
--slds-g-color-on-error-1
--slds-g-color-border-error-1
--slds-g-color-border-error-2

Success Colors

Success colors are reserved for component states that indicate that a successful action has occurred or will occur if action is taken.

--slds-g-color-success-1
--slds-g-color-success-container-1
--slds-g-color-success-container-2
--slds-g-color-on-success-1
--slds-g-color-on-success-2
--slds-g-color-border-success-1

Warning Colors

Warning colors are reserved for component states that indicate that something has prevented an action from being taken, such as a dirty state of a form.

--slds-g-color-warning-1
--slds-g-color-warning-container-1
--slds-g-color-on-warning-1
--slds-g-color-border-warning-1

Informational Colors

Informational colors are reserved to provide visual feedback to indicate that some content on the page is purely informational.

--slds-g-color-info-1
--slds-g-color-info-container-1
--slds-g-color-on-info-1

Disabled Colors

Disabled colors are reserved for component states to indicate that the component is disabled and you can't interact with it.

--slds-g-color-disabled-1
--slds-g-color-disabled-2
--slds-g-color-disabled-container-1
--slds-g-color-disabled-container-2
--slds-g-color-on-disabled-1
--slds-g-color-on-disabled-2
--slds-g-color-border-disabled-1
--slds-g-color-border-disabled-2

Usage Guidelines

Diagram of an example app showing how to use styling hooks

Legend

  1. --slds-g-color-surface-2
  2. --slds-g-color-surface-container-1
  3. --slds-g-color-accent-1
  4. --slds-g-color-on-surface-3
  5. --slds-g-color-border-1
  6. --slds-g-color-accent-container-1
  7. --slds-g-color-on-accent-1

✅ Do

Always use an on color with a container color to ensure WCAG 2.1 color contrast requirements.

❌ Don't

Do not use system colors or colors from another group like surfacecolors in combination with accent containers.

✅ Do

Feel free to use accent/feedback colors to express your brand's accent or intent on top of surface and surface container colors only.

❌ Don't

Do not use accent/feedback colors if text or icons sit on top of the accent color. To ensure correct WCAG 2.1 color contrast, use accent/feedback container color for this scenario.

✅ Do

Always use the appropriate border color for borders or outlines, if necessary.

❌ Don't

Do not use non-border accent colors on borders to achieve a border with an accent color.

Accessible System Colors

A set of accessible colors that are used throughout the user interface. These stying hooks contain the complete set of values based on their semantics, brand, neutral, and feedback colors. These are mutable and their values are subject to change. Only use in edge cases where a semantic UI color does not make sense.

These styling hooks are also documented in the Global Color Style Hooks for accessibility.

Neutral Colors

neutral-base-10
neutral-base-15
neutral-base-20
neutral-base-30
neutral-base-40
neutral-base-50
neutral-base-60
neutral-base-65
neutral-base-70
neutral-base-80
neutral-base-90
neutral-base-95
neutral-base-100

Brand Colors

brand-base-10
brand-base-15
brand-base-20
brand-base-30
brand-base-40
brand-base-50
brand-base-60
brand-base-65
brand-base-70
brand-base-80
brand-base-90
brand-base-95
brand-base-100

Error Colors

Warning Colors

Success Colors

Accessible Color Palettes

These styling hooks are also documented in the Global Color Style Hooks for accessibility.

blue-10
blue-15
blue-20
blue-30
blue-40
blue-50
blue-60
blue-65
blue-70
blue-80
blue-90
blue-95
cloud-blue-10
cloud-blue-15
cloud-blue-20
cloud-blue-30
cloud-blue-40
cloud-blue-50
cloud-blue-60
cloud-blue-65
cloud-blue-70
cloud-blue-80
cloud-blue-90
cloud-blue-95
green-10
green-15
green-20
green-30
green-40
green-50
green-60
green-65
green-70
green-80
green-90
green-95
hot-orange-10
hot-orange-15
hot-orange-20
hot-orange-30
hot-orange-40
hot-orange-50
hot-orange-60
hot-orange-65
hot-orange-70
hot-orange-80
hot-orange-90
hot-orange-95
indigo-10
indigo-15
indigo-20
indigo-30
indigo-40
indigo-50
indigo-60
indigo-65
indigo-70
indigo-80
indigo-90
indigo-95
orange-10
orange-15
orange-20
orange-30
orange-40
orange-50
orange-60
orange-65
orange-70
orange-80
orange-90
orange-95
pink-10
pink-15
pink-20
pink-30
pink-40
pink-50
pink-60
pink-65
pink-70
pink-80
pink-90
pink-95
purple-10
purple-15
purple-20
purple-30
purple-40
purple-50
purple-60
purple-65
purple-70
purple-80
purple-90
purple-95
red-10
red-15
red-20
red-30
red-40
red-50
red-60
red-65
red-70
red-80
red-90
red-95
teal-10
teal-15
teal-20
teal-30
teal-40
teal-50
teal-60
teal-65
teal-70
teal-80
teal-90
teal-95
violet-10
violet-15
violet-20
violet-30
violet-40
violet-50
violet-60
violet-65
violet-70
violet-80
violet-90
violet-95
yellow-10
yellow-15
yellow-20
yellow-30
yellow-40
yellow-50
yellow-60
yellow-65
yellow-70
yellow-80
yellow-90
yellow-95
neutral-10
neutral-15
neutral-20
neutral-30
neutral-40
neutral-50
neutral-60
neutral-65
neutral-70
neutral-80
neutral-90
neutral-95

Shadows

These properties control the appearance of shadows, affecting the depth perception and layering of UI elements.

shadow-1
shadow-2
shadow-3
shadow-4

Border Radius

These properties manage the curvature of UI elements' corners, impacting the perceived softness or hardness of components.

radius-border-1
radius-border-2
radius-border-3
radius-border-4
radius-circle
radius-border-pill

Typography

These properties influence the typography in your application, defining aspects like font family, size, weight, line-height, etc.

Font Scale

Font sizes are scaled, based on the --slds-g-font-size-base property which sets the default font-size of the application.

The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.

Font Weight

Font weights are available in a range where --slds-g-font-weight-4 is normal weight.

The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.

Line Height

Line height values are set to unitless numbers which are multiplied by the font size used in the element to obtain the desired line height.

Lorem ipsum dolor sit amet consectetur adipisicing elit. Unde harum officiis sit at mollitia, ducimus natus doloremque quos maiores obcaecati consequuntur pariatur quisquam nobis sequi excepturi in dolorem provident iste!

Lorem ipsum dolor sit amet consectetur adipisicing elit. Unde harum officiis sit at mollitia, ducimus natus doloremque quos maiores obcaecati consequuntur pariatur quisquam nobis sequi excepturi in dolorem provident iste!

Lorem ipsum dolor sit amet consectetur adipisicing elit. Unde harum officiis sit at mollitia, ducimus natus doloremque quos maiores obcaecati consequuntur pariatur quisquam nobis sequi excepturi in dolorem provident iste!

Lorem ipsum dolor sit amet consectetur adipisicing elit. Unde harum officiis sit at mollitia, ducimus natus doloremque quos maiores obcaecati consequuntur pariatur quisquam nobis sequi excepturi in dolorem provident iste!

Lorem ipsum dolor sit amet consectetur adipisicing elit. Unde harum officiis sit at mollitia, ducimus natus doloremque quos maiores obcaecati consequuntur pariatur quisquam nobis sequi excepturi in dolorem provident iste!

Spacing

The spacing values are used to create space between elements. The styling hook values are relative to the root font size and follow a modular scale of 4. Use them to set values for margins and padding, for example.

Don't use spacing properties to establish dimensions of an element targeting width and height. Use the sizing properties for this purpose.

Sizing

The sizing values are used to create dimensions of an element, like using height and width based properties.

Border Widths

Use these styling hooks to specify the pixel width of a border.

sizing-border-1
sizing-border-2
sizing-border-3
sizing-border-4

Dimensions

Use these styling hooks for elements like icons to set their height and width relative to the root element's font-size.

Salesforce Private CSS Properties and Syntax

The use of SLDS private styling hooks and @layer syntax is prohibited.

Some SLDS styling hooks are private and reserved only for internal Salesforce use. They aren't documented for your use. Private SLDS styling hooks have prefixes --_slds- and --slds-s-. If you come across one of these hooks in your rendered content, don't use it as a reference or assign a new value to it. These reserved properties are subject to change and can be removed in future releases.

You may also discover some syntax called @layer. This is an internal mechanism Salesforce uses to establish the correct CSS cascade that we expect CSS to render. Don't attempt to use @layer within your component CSS or modify the CSS within a layer.

See Also

For the complete list of global styling hooks, see the Global Styling Hooks Reference.