@db-ux/core-foundations

中文文档
6.3.2发布于 2026/11/11Apache-2.0TypeScriptES Module零依赖构建来源已验证近 30 天下载 9200

Provides basic tokens and assets based on DB UX Design System – Generation 3

原始使用文档
文档目录17 节
  1. When to use this package
  2. Install
  3. Usage
  4. CSS
  5. SCSS
  6. Tailwind
  7. Optimize dependencies
  8. Theme, Assets & Init
  9. Font Preloading
  10. How to Preload Fonts
  11. Tips for identifying fonts to preload
  12. Important notes
  13. Migration
  14. Deutsche Bahn brand
  15. Contributions
  16. Code of conduct
  17. License

@db-ux/core-foundations

Apache 2.0 license badge code style: prettier Conventional Commits PRs Welcome

A library containing all tokens (colors, spacings, font formatting, etc.) and assets (icons) of DB UX Design System – Generation 3.

When to use this package

⚠️ Looking for UI components? You probably want @db-ux/core-components instead, which automatically includes this package.

Use this package if you:

  • Only need design tokens (colors, spacing, fonts) without any component styles
  • Want to build custom components using the design system tokens
  • Need just icons and fonts without pre-built components

Use @db-ux/core-components when you:

  • Want to use ready-made UI components (buttons, inputs, navigation, etc.)
  • Need both design tokens AND component styles (most common use case)

We currently support:

Install

npm i @db-ux/core-foundations

Usage

You use this library if you need some colors, spacings etc.

tl;dr: Use the default theme and the bundled styles by importing bundle.css and theme/[relative|absolute|rollup|webpack].css.


First of all you need to import a theme which contains all tokens (css-properties). We provide a theme/[relative|absolute|rollup|webpack].css which handles dark/light mode as well.

Afterward, you may import helper classes / placeholders to easily consume the tokens from your theme. There are some categories:

  • init: Global styles which apply to all or a large group of selectors. Make sure to import inits/required.css to normalize tags like body etc. Furthermore, we provide some default styles.
  • icons: Icons classes to load woff2 files and adds [data-icon] and [data-icon-trailing] to enable icons for all tags and components.
  • helpers: Use dividers or focus border
  • fonts: Overwrite default font-size, line-height and icon-size
  • density: Overwrite default density to scale adaptive components inside container using density
  • colors: Sets an adaptive color to a container, which passes all required css-properties to children

The bundle.css applies those default:

CSS

Default assets path for relative.css is ../../../assets, which matches the package structure (build/styles/ and assets/). This lets you load the CSS straight from the package, e.g. from a CDN. If you copy the files into your public folder, keep this structure. Or you use a modern bundler which handles bundling for you. In this case use [rollup|webpack].css.

Import

Import the styles in your main .css file.

/* index.css */
@layer whitelabel-theme, db-ux;

@import "@db-ux/core-foundations/build/styles/theme/relative.css" layer(theme);

@import "@db-ux/core-foundations/build/styles/bundle.css" layer(db-ux);

/* Optional: Use [data-divider] & [data-focus] everywhere */
@import "@db-ux/core-foundations/build/styles/helpers/classes/all.css"
    layer(db-ux);
/* Optional: Use [data-density] everywhere */
@import "@db-ux/core-foundations/build/styles/density/classes/all.css"
    layer(db-ux);
/* Optional: Use [data-font-size] everywhere */
@import "@db-ux/core-foundations/build/styles/fonts/classes/all.css"
    layer(db-ux);
/* Optional: Use [data-color] everywhere */
@import "@db-ux/core-foundations/build/styles/colors/classes/all.css"
    layer(db-ux);

Use

In CSS:

.my-container {
    padding: var(--db-spacing-fixed-md);
}

In HTML:

<!-- With data attributes-->
<div
    class="my-container"
    data-density="functional"
    data-color="successful-bg-lvl-1"
></div>

Note: In CSS you might to use the classes or data-attributes even more because you cannot use placeholders or mixins like we have it in scss. If you use a 3rd party library and cannot apply classes or data-attributes you might want to copy the content of our helper classes to apply it to the 3rd party class.

SCSS

Use

In SCSS:

@use "@db-ux/core-foundations/build/styles/variables";

.my-container {
    padding: variables.$db-spacing-fixed-md;
}

In SCSS with placeholder:

@use "@db-ux/core-foundations/build/styles/fonts";
@use "@db-ux/core-foundations/build/styles/colors";

.placeholder-container {
    @extend %db-overwrite-font-size-sm;
    @extend %db-successful-bg-lvl-1;
}

In HTML:

<!-- With data attributes-->
<div
    class="my-container"
    data-density="functional"
    data-color="successful-bg-lvl-1"
></div>

Tailwind

Check the required imports for CSS to enable all tokens and defaults.

Tailwind v4

@import "tailwindcss";
@import "@db-ux/core-foundations/build/tailwind/theme/index.css";

Tailwind v3

Note: In Tailwind v4 you can use the config with @config "tailwind.config.[js|ts]"; inside your .css file as well.

After this you can extend your tailwind config like this:

JavaScript
//tailwind.config.js
/** @type {import('tailwindcss').Config} */
import tokens from "@db-ux/core-foundations/build/tailwind/tailwind-tokens.json";

export default {
    content: ["./index.html", "./src/**/*.{js,jsx,ts,tsx}"],
    plugins: [],
    theme: {
        ...tokens,
        gap: ({ theme }) => ({
            ...theme("spacing")
        }),
        space: ({ theme }) => ({
            ...theme("spacing")
        })
    }
};
TypeScript
//tailwind.config.ts
import type { Config } from "tailwindcss";
import { CustomThemeConfig } from "tailwindcss/types/config";
import tokens from "@db-ux/core-foundations/build/tailwind/tailwind-tokens.json";
const customThemeConfig: CustomThemeConfig = tokens as any;

export default {
    content: [],
    theme: {
        ...customThemeConfig,
        gap: ({ theme }) => ({
            ...theme("spacing")
        }),
        space: ({ theme }) => ({
            ...theme("spacing")
        })
    },
    plugins: []
} satisfies Config;

In your tailwind.css add this to enable default headlines:

@layer base {
    h1 {
        @apply text-head-xl font-head;
    }
    h2 {
        @apply text-head-lg font-head;
    }
    h3 {
        @apply text-head-md font-head;
    }
    h4 {
        @apply text-head-sm font-head;
    }
    h5 {
        @apply text-head-xs font-head;
    }
    h6 {
        @apply text-head-2xs font-head;
    }
}

Use

<div class="grid gap-fix-sm p-res-md"></div>

Optimize dependencies

If you want to optimize the size of the loaded styles, you might want to skip loading @db-ux/core-foundations/build/styles/[relative|absolute|rollup|webpack].css. But there are some required styles for this Design System to work properly.

Theme, Assets & Init

/* The theme contains all prop required for components like spacings, colors, etc. You can replace it with your own theme. */
@import "@db-ux/core-foundations/build/styles/theme/relative.css";
/* The font include uses default font families based on your bundling paths (relative, absolute, webpack, rollup). You can replace it with your own fonts. */
@import "@db-ux/core-foundations/build/styles/fonts/relative.css";
/* The icon include uses default icons based on your bundling paths (relative, absolute, webpack, rollup). You can replace it with your own icons. */
@import "@db-ux/core-foundations/build/styles/icons/relative.css";

Optimize index

You are able to optimize the initial settings as well:

/* The required styles normalize css, add focus, set the default body font, and apply the mandatory headline typography (font-sizes & line-heights) to h1-h6. */
@import "@db-ux/core-foundations/build/styles/defaults/default-required.css";
/* The default setting for :root, adds a color space (neutral-bg-basic-level-1) and a density (regular). */
@import "@db-ux/core-foundations/build/styles/defaults/default-root.css";
/* Adds the optional font-weight utilities ([data-font], heading [data-variant]) and the small/code font-size. The headline h1-h6 typography is no longer here - it moved to default-required.css. */
@import "@db-ux/core-foundations/build/styles/defaults/default-fonts.css";
/* Adds "[data-icon]" and other icon related styles. If you don't need icons in your application you could skip this. */
@import "@db-ux/core-foundations/build/styles/defaults/default-icons.css";
/* Adds "[data-elevation]" and other icon related styles. If you don't need elevation in your application you could skip this. */
@import "@db-ux/core-foundations/build/styles/defaults/default-elevation.css";
/* Adds defaults for `blockquote`, `code` and `pre`. If you don't need them in your application you could skip this. */
@import "@db-ux/core-foundations/build/styles/defaults/default-code.css";

Font Preloading

To ensure optimal performance and reliability — especially in flaky or offline internet conditions — you could preload or at least prefetch any fonts your application depends on.

How to Preload Fonts

After identifying the critical fonts required for your application's UI, use the following <link> tag in the <head> of your HTML to preload them:

<link
    rel="preload"
    href="/media/dbneoscreensans-regular.woff2"
    as="font"
    type="font/woff2"
    crossorigin="anonymous"
/>

Otherwise, if the font is not initially required but would be requested later or by some dynamically inserted content, you could still prefetch it. Prefetching works at a lower priority than preload:

<link
    rel="prefetch"
    href="/assets/icons/fonts/default/db-ux.woff2"
    crossorigin="anonymous"
/>

Tips for identifying fonts to preload

  • Use browser dev tools to track font requests that are essential to your application
  • Fonts that fail to load during unstable connections should be prioritized.

Important notes

  • Make sure the href path is correct and accessible at runtime.
  • Always use crossorigin="anonymous" for fonts served from your domain or a CDN, unless your server requires credentials (rare for fonts).
  • By preloading fonts this way, you improve perceived performance and avoid layout shifts or invisible text during initial rendering.

Migration

For migration guidance between versions, see the migration docs.

Deutsche Bahn brand

As we'd like to perfectly support our users and customers on their digital journey, the usage of Deutsche Bahn brand and trademarks are bound of clear guidelines and restrictions even if being used with the code that we're providing with this product; Deutsche Bahn fully reserves all rights regarding the Deutsche Bahn brand, even though that we're providing the code of DB UX Design System products free to use and release it under the Apache 2.0 license. Please have a look at our brand portal at https://marketingportal.extranet.deutschebahn.com/ for any further questions and whom to contact on any brand issues.

For any usage outside of Deutsche Bahn websites and applications you aren't allowed to use any Deutsche Bahn brand and design assets as well as protected characteristics and trademarks, that for not including the DB Theme.

Contributions

Contributions are very welcome, please refer to the contribution guide.

Code of conduct

We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone – have a look at our Contributor Covenant Code of Conduct.

License

This project is licensed under Apache-2.0.

版本与发布记录

@db-ux/core-foundations 共发布 200 个版本,首次发布于 2025/02/13;过去 12 个月发布了 119 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
6.3.2latest2026/11/11今天
6.3.12026/11/101 天前
6.3.02026/11/056 天前
6.2.12026/11/047 天前
6.2.1-optimized-icon-fonts-amount2-b78987enext2026/11/047 天前
6.2.02026/10/2913 天前

关于 @db-ux/core-foundations 的常见问题

@db-ux/core-foundations 是什么?

Provides basic tokens and assets based on DB UX Design System – Generation 3

如何安装 @db-ux/core-foundations?

在项目目录运行 npm install @db-ux/core-foundations,或使用 pnpm add / yarn add / bun add。

@db-ux/core-foundations 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@db-ux/core-foundations 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@db-ux/core-foundations 可以商用吗?

@db-ux/core-foundations 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@db-ux/core-foundations 的下载量有多少?

根据 npm 官方下载统计,@db-ux/core-foundations 在 2026/10/12 – 2026/11/10 这 30 天内被下载 9,200 次,日均约 307 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@db-ux/core-foundations 还在维护吗?

最新版本 6.3.2 发布于 2026/11/11(今天);至今共发布 200 个版本,其中过去 12 个月发布了 119 个;首次发布于 2025/02/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。