--- title: "Themes" slug: ovhcloud-design-system-customize-themes category: generic type: overview version: 20.0.0 tokens: 2001 source: https://ovh.github.io/design-system/v20.0.0/llms/ovhcloud-design-system-customize-themes.txt --- # Themes A theme is a stylesheet that declares the ODS design tokens as CSS custom properties on `:root`. ODS components read these tokens, and so can your own CSS: load a theme, and both follow it. A theme names its fonts, but does not load them: loading them is up to you. ## Available themes `@ovhcloud/ods-themes` ships four themes. Each one is a complete stylesheet: - **Default** (`@ovhcloud/ods-themes/default/css`), the Aluminium look. - **Aluminium dark** (`@ovhcloud/ods-themes/aluminium-dark/css`), its dark mode. - **Blue Jeans** (`@ovhcloud/ods-themes/blue-jeans/css`), the OVHcloud look. - **Blue Jeans dark** (`@ovhcloud/ods-themes/blue-jeans-dark/css`), its dark mode. ## Load a theme Load a single theme. A theme does not build on another one: two themes loaded together override each other. ```typescript import '@ovhcloud/ods-themes/blue-jeans-dark/css'; ``` Then load the fonts it names (see **Fonts**). > Make sure the page loads the fonts of the theme you choose. A font the page does not load falls back to the next one of its stack, without any error. ## Fonts A theme names its fonts in three tokens: `--ods-semantic-font-family-body`, `--ods-semantic-font-family-heading` and `--ods-semantic-font-family-code`. Another theme may name other fonts. The four themes above use the same two fonts, **Source Sans 3** for text and **Source Code Pro** for code. ODS ships them in `@ovhcloud/ods-themes/default/fonts`, a name kept from v19 though it serves every theme, with **ODS Icon**, the icon font of the components, needed whatever the theme: ```typescript import '@ovhcloud/ods-themes/default/fonts'; ``` This stylesheet declares the fonts with relative `url()`s to the font files of the package: your bundler resolves them and emits the files. As a help for these four themes, `@ovhcloud/ods-themes/fonts-base64` declares the same fonts with the files inlined as base64, for a setup that cannot serve font files. Load it instead of `default/fonts`, not with it. It weighs about 700 KB and the browser cannot load its fonts in parallel: keep it as a fallback. ## Switch themes A page shows one theme. No attribute or class selects it: to switch themes, replace the theme stylesheet of the page. To follow the color scheme of the operating system, without any script, import each mode with a media query, so that only one applies: ```css @import '@ovhcloud/ods-themes/default/css' (prefers-color-scheme: light); @import '@ovhcloud/ods-themes/aluminium-dark/css' (prefers-color-scheme: dark); @import '@ovhcloud/ods-themes/default/fonts'; ``` To switch from your code, put an empty `` for the theme in the `
` of your page, before your own stylesheets, and set its URL from your code: your styles stay after the theme and can override it. With Vite, a `?url` import emits the theme file and gives its URL: ```html ``` ```typescript import '@ovhcloud/ods-themes/default/fonts'; import lightThemeUrl from '@ovhcloud/ods-themes/default/css?url'; import darkThemeUrl from '@ovhcloud/ods-themes/aluminium-dark/css?url'; const theme = document.getElementById('ods-theme') as HTMLLinkElement; theme.href = lightThemeUrl; function setDarkMode(isDark: boolean): void { theme.href = isDark ? darkThemeUrl : lightThemeUrl; } ``` Without a bundler, serve the files the export paths resolve to, and point the `` at them: the layout of the package folder may change from one version to the next, the export paths do not. The fonts stay loaded when the theme changes. If the two themes do not name the same fonts, load the fonts of both. This documentation does it differently: it keeps the default theme loaded, and puts the theme shown, whole, in a single `Starter plan
€4.99 / month