Set up a brand theme with design tokens
On this page
Put brand colours, type and spacing in the design library, style blocks with them, and let colour fields follow the library.
Plan: Free Visual Builder package
Goal: change the brand colour once and see every page follow, without editing pages or touching the database. Blocks styled in the builder use design-library values; colour fields your templates read use the Design token colour editor, which stores a reference to a library colour instead of a fixed hex value.
Before you start #
- Visual Builder installed and turned on, and the site opted in to styles. See Opt a site into Visual Builder styles in code.
- The brand's colours, fonts and spacing scale (fictional example: "Demo Bakery" with Crust
#8a4b1f, Flour#f7f1e8and Ink#1f1a17).
Step by step #
- 1Add the coloursOpen a page in the builder and select Design library › Colours. Add Crust, Flour and Ink with their values.
- 2Add type and spacingIn Typography, add the brand font family and a few sizes. In Spacing and radii, add your spacing steps (for example 8, 16, 24, 40 px) and corner radii.
- 3Publish the stylesSelect Publish styles and confirm "Publish styles to the whole site?".
- 4Style blocks with the librarySelect a section, open Style › Background and pick Flour; pick Ink as text colour. Set padding from your spacing steps. Save and publish the page.
- 5Make template colour fields follow the libraryFor colour fields your templates read (for example a header colour on a site settings document), create a data type in Settings › Data types with the Design token colour property editor and use it for that field. Editors then pick a library colour; existing hex values keep working and show as "Fixed colour" until someone picks a library colour.
- 6Read the colour in RazorThe value converter always returns the current colour as a
#hex string, so templates don't change:1@{2 var header = Model.Value<string>("headerColour");3}4<header class="site-header" style="@(string.IsNullOrEmpty(header) ? null : $"--header-bg: {header}")">5 @* header markup *@6</header> - 7Change the brand onceBack in Design library › Colours, change Crust to a new value and Publish styles. Reload a few pages: blocks styled with the library and fields using Design token colour show the new colour, with no page edits.
Result #
One source of truth for the brand. Pages store references to library values, so a rebrand is a library change and a publish.
NoteThe Design token colour editor stores
token:<key>|#fallback. If a colour is removed from the library, pages fall back to the hex value saved with the reference, and the editor asks editors to pick another colour. The design library's delete warning doesn't yet count these fields.NoteThe Design token colour editor works with fields on Umbraco's text box schema. Fields that use another colour-picker package store their own value format and need that package's converter to accept the
token: form.Was this article helpful?