@financial-times/o-colors

中文文档
6.7.1发布于 2026/02/26MITES Module零依赖近 30 天下载 1.6万

The default colour palette for all FT products. The palette supports colour contrast checking, colour mixing and toneing.

原始使用文档
文档目录18 节
  1. Usage
  2. Markup
  3. Colour Usecase Classes
  4. CSS Custom Properties
  5. Colour Palette Custom Properties
  6. Colour Usecase Custom Properties
  7. Sass
  8. Palette Colours
  9. Default Palette Colours
  10. Usecases
  11. Custom Usecase
  12. Generated Text Colors
  13. Mix colors
  14. Tone Palette Colors
  15. Colour Tools
  16. Migration
  17. Contact
  18. Licence

⚠️ NOTE: o-colors has been replaced with o3-foundation. Please see Migration Guide for steps to upgrade.

o-colors MIT licensed

A component to manage colours. Includes the FT colour palette.

Usage

Check out how to include Origami components in your project to get started with o-colors.

Markup

Colour Usecase Classes

A limited number of colour usecases are available as CSS classes, including:

  • .o-colors-page-background
  • .o-colors-box-background
  • .o-colors-body-text
  • .o-colors-muted-text
<body class="o-colors-page-background">
    <!-- default background colour set -->
    <!-- e.g. for the core brand `background: #fff1e5;` -->
</body>

More colours are available for build service users as CSS Custom Properties.

CSS Custom Properties

Colour Palette Custom Properties

All palette colors, including default mixes and tones, are available as CSS Custom Properties (CSS Variables) in the format --o-colors-[NAME].

See all palette colours available in the registry.

.ft-pink {
    background: var(--o-colors-paper);
    color: var(--o-colors-black-80);
}

Colour Usecase Custom Properties

A limited number of colour usecases are also available as CSS Custom Properties (CSS Variables), including:

  • --o-colors-page-background
  • --o-colors-box-background
  • --o-colors-body-text
  • --o-colors-muted-text
  • --o-colors-link-text
  • --o-colors-link-hover-text
body {
    background: var(--o-colors-page-background);
}

Sass

o-colors has a number of mixins and functions for you to access the color palette in your project. We recommend Sass projects use these mixins and functions directly. E.g. oColorsByName and oColorsByUsecase. However, it is also possible to output all o-colors CSS Custom Properties (CSS Variables) and classes using the oColors mixin.

@import '@financial-times/o-colors/main';
@include oColors(
    $opts: (
        'palette-custom-properties': true,
        // e.g. --o-colors-paper
        'usecase-custom-properties': true,
        // e.g. --o-colors-page-background
        'usecase-classes': true // e.g. .o-colors-page-background,
    )
);

Palette Colours

o-colors defines a colour palette (a set of named colours) which may be previewed in the registry. Custom palette colours may be added to the palette to share them with dependencies.

Color NameBrand Support
blackcore, internal, whitelabel
whitecore, internal, whitelabel
oxfordcore, internal
tealcore, internal
slatecore, internal,
lemoncore, internal,
jadecore, internal
mandarincore, internal
crimsoncore, internal
papercore
claretcore
wheatcore
skycore
velvetcore
candycore
wasabicore
light-bluecore
graphics-dark-bluecore
ft-pink (previously brand-ft-pink)core
ft-greycore
org-b2ccore
org-b2c-darkcore
org-b2c-lightcore
mintcore

There are additional colours in the palette by default including tones and mixes. See the registry demos for a full list.

ft-pink and ft-grey are brand colours which are used in some digital assets, such as the FT logo, but have a limited number of valid use-cases for digital UI. Instead consider paper and slate or a black/paper mix such as black-80. As an example of a usecase for ft-pink, it could be used to prevent a flash of the wrong colour as a logo image loads.

Default Palette Colours

Get a default colour from the palette using oColorsByName.

.example {
    // Get a default o-colors palette colour.
    background: oColorsByName('paper');
}

Custom Palette Colours

To set a custom palette colour to share with other components call oColorsSetColor. Colour names must be namespaced for the project or component using a forward slash.

// Set a custom palette colour within a project `o-example`.
@include oColorsSetColor(
    $color-name: 'o-example/myhotpink',
    $color-value: #ff69b4
);

.example {
    // Get a custom palette colour from a project `o-example`.
    background: oColorsByName('o-example/myhotpink');
}

By default custom colours do not allow tones to reduce the number of colours used within a project. To allow tones set the allow-tones option.

// Set a custom palette colour within a project `o-example`,
// which allows tones of the same colour.
@include oColorsSetColor(
    $color-name: 'o-example/myhotpink',
    $color-value: #ff69b4,
    $opts: (
        'allow-tones': true,
    )
);

.example {
    // Get a toned custom palette colour from a project `o-example`.
    background-color: oColorsGetTone('o-example/myhotpink', 80);
}

Removing a colour is considered a breaking change and requires a major release. To inform users a colour should not be used deprecate it by passing an $opts argument with a deprecation message.

// Deprecate a custom colour, which will be removed in a future major release.
@include oColorsSetColor(
    $color-name: 'o-example/myhotpink',
    $color-value #ff69b4,
    $opts: (
        'deprecated': 'Use the default colour claret instead.',
    )
);

See o-colors SassDoc for more details and examples.

Usecases

A colour palette helps products use the same set of colours, but does not help them use the colours consistently. Therefore o-colors provides tools to return colours based on usecases. E.g. a colour for the page background or body text.

UsecasePropertyBrand Support
pagebackgroundcore, internal, whitelabel
focusoutlinecore, internal
boxbackgroundcore, internal
linktextcore, internal
link-hovertextcore, internal
link-titletextcore, internal
link-title-hovertextcore, internal
titletextcore, internal
bodytextcore, internal
mutedtextcore, internal
tag-linktextcore
tag-link-hovertextcore
opinion-tag-linktextcore
opinion-tag-link-hovertextcore
opinionbackgroundcore
herobackgroundcore
hero-opinionbackgroundcore
hero-highlightbackgroundcore
adsbackgroundcore
Section colors
section-life-artsallcore
section-life-arts-altallcore
section-magazineallcore
section-magazine-altallcore
section-house-homeallcore
section-house-home-altallcore
section-moneyallcore
section-money-altallcore

Default Usecases

To get a colour for a default usecase call oColorsByUsecase.

html {
    // get the background colour for the page usecase
    background: oColorsByUsecase('page', 'background');
}

.paragraph {
    // get the text colour for the body usecase
    color: oColorsByUsecase('body', 'text');
}

Custom Usecase

To create a new usecase call oColorsSetUseCase.

  • $usecase: The name of the usecase, e.g. 'page'. This must include a namespace for your component or project followed by a forward slash.
  • $colors: A map of properties ('text', 'background', 'border', or 'outline') to a palette color name.
  • $opts (optional):
    • deprecated: A deprecation message for the usecase.
// set colours for a "stripes" in o-example.
@include oColorsSetUseCase(
    'o-example/stripes',
    (
        'text': 'white',
        'background': 'black',
        'border': 'black-50',
    )
);

Removing a usecase is a breaking change and requires a major release. To inform users a usecase should not be used it should be deprecated. Deprecate a usecase by passing an $opts argument with a deprecation message.

Deprecate all usecase properties:

// deprecate all usecase properties for the o-example custom usecase "stripes".
@include oColorsSetUseCase(
    'o-example',
    'stripes',
    (
        'text': 'white',
        'background': 'black',
        'border': 'black-50',
    ),
    (
        'deprecated': 'o-example has no stripes anymore, use a different colour',
    )
);

Deprecate individual usecase properties:

// deprecate only the background property for the o-example custom usecase "stripes".
@include oColorsSetUseCase(
    'o-example',
    'stripes',
    (
        'text': 'white',
        'background': 'black',
        'border': 'black-50',
    ),
    (
        'deprecated': (
            'background':
                'o-example stripes has no background anymore, use a different colour',
        ),
    )
);

Generated Text Colors

oColorsGetTextColor will return a light or dark text color based on the background and an opacity specified.

.example {
    background: oColorsByName('teal');
    // Get a text colour for a teal background
    color: oColorsGetTextColor('teal');
}
.example {
    background: oColorsByName('teal');
    // Get a text colour for a teal background,
    // with greater than usual opacity (80)
    color: oColorsGetTextColor('teal', 80);
}

The contrast of the background and resulting text colour is checked against WCAG 2.1 guidelines. If the contrast is too low an error is thrown. By default the contrast is checked for normal text at AA level. The contrast may be checked for large text or against stricter AAA recommendations (aa-normal, aa-large, aaa-normal, or aaa-large).

.example-large-text {
    background: oColorsByName('teal');
    // Get a text colour for a teal background,
    // enforce a lower level of contrast "large text".
    color: oColorsGetTextColor('teal', $minimum-contrast: 'aa-large');
}

Set $minimum-contrast to null to remove contrast checking. Only ignore contrast for incidental or logo text, otherwise your project may be inaccessible.

Mix colors

oColorsMix will mix two colors based on a percentage. This gives the impression of the base color appearing at the percentage opacity over the background color. oColorsMix will accept either a color value or the name of an o-colors palette color as arguments.

By default oColorsMix mixes with the page background colour usecase:

$color: oColorsMix(
    $color: 'black',
    $percentage: 30,
); // same as black-30

But two colours may be given. For example to mix claret over slate at 20%:

$color: oColorsMix(
    $color: 'claret',
    $background: 'slate',
    $percentage: 20,
);

Tone Palette Colors

An o-colors tone is a palette colour with modified saturation and luminosity, to create a lighter or darker colour whilst retaining vibrancy.

Recommended tones are already in the colour palette, e.g. teal-80 (see default tones in the registry). However for cases where a new tone is required use oColorsGetTone. It will return a new color based on a specified brightness.

.teal-tone-example {
    background-color: oColorsGetTone('teal', 80);
}

For design consistency not all colours are allowed to be toned. Only colours with default tones in the palette (e.g. teal, oxford, and claret) may be used. Other colours may still be mixed. If your project has defined custom colours using oColorsSetColor, these may be toned by setting the allow-tones option.

Colour Tools

o-colors provides other useful functions for working with colours, including:

  • oColorsGetContrastRatio
  • oColorsColorBrightness
  • oColorsColorLuminance

See o-colors SassDoc for more details and examples.

Migration

StateMajor VersionLast Minor ReleaseMigration guide
✨ activeo3N/Amigrate to o3
⚠ maintained6N/Amigrate to v6
╳ deprecated5N/Amigrate to v5
╳ deprecated44.10migrate to v4
╳ deprecated33.6migrate to v3
╳ deprecated22.5migrate to v2
╳ deprecated11.1migrate to v1
╳ deprecated00.2N/A

Contact

If you have any questions or comments about this component, or need help using it, please either raise an issue, visit #origami-support or email Origami Support.


Licence

This software is published by the Financial Times under the MIT licence.

版本与发布记录

@financial-times/o-colors 共发布 70 个版本,首次发布于 2019/02/13;过去 12 个月发布了 1 个版本。

版本发布日期距今
6.7.1latest2026/02/268 个月前
6.7.02024/07/312 年前
6.6.42024/03/272 年前
6.6.32023/10/273 年前
6.6.22023/07/053 年前
6.6.12023/06/023 年前

其他发布通道:prerelease → 6.0.0-beta.0。

关于 @financial-times/o-colors 的常见问题

@financial-times/o-colors 是什么?

The default colour palette for all FT products. The palette supports colour contrast checking, colour mixing and toneing.

如何安装 @financial-times/o-colors?

在项目目录运行 npm install @financial-times/o-colors,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@financial-times/math(^1.0.0)、@financial-times/o-brand(^4.0.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@financial-times/o-colors 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/financial-times__o-colors 是否存在。

@financial-times/o-colors 支持 ESM 还是 CommonJS?

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

@financial-times/o-colors 可以商用吗?

@financial-times/o-colors 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@financial-times/o-colors 的下载量有多少?

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

@financial-times/o-colors 还在维护吗?

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