---
title: Code
slug: wip/Abqa-code
createdAt: 2023-07-21T06:22:57.025Z
---

# Customization & Theming: Code

:::Iframe{iframeHeight="0" code="<iframe&#xA;  title=&#x22;Embeded content from codepen.io&#x22;&#xA;  class=&#x22;no-border max-full-width full-height flex-grow&#x22;&#xA;  src=&#x22;https://codepen.io/redbulldesign/embed/wvqyLRj/3daed4a5a31e0b8c4ec7de5d8af2869d?default-tab=result&#x26;amp;theme-id=39402&#x22;&#xA;  height=&#x22;438px&#x22;&#xA;></iframe>"}

:::

At Red Bull, we advocate projects that demonstrate brand diversity through engaging and recognizable visuals and design.

Cosmos is designed to support the creation of unique experiences by allowing a component's styling to be customized via pure CSS.

For high-level customizations, components provide CSS Custom Properties. For more advanced customizations, they expose CSS Shadow Parts to extend their styling.

:::hint{type="warning"}
**☝️ Watch out**

We strongly advise using a CSS class to target Cosmos web components rather than an element selector to make styles related to customizations more distinct and robust.
:::

## CSS Custom Properties

CSS Custom Properties are a reliable and easy way to customize the look of a component at a high level. Custom Properties are limited by design, they only allow selected styles of a component to be changed.

We recommend targeting Cosmos web components with a custom CSS class to customize them. Furthermore, specific variants of a component can be targeted by using [attribute selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors).

:::Iframe{iframeHeight="0" code="<iframe&#xA;  title=&#x22;Embeded content from codepen.io&#x22;&#xA;  class=&#x22;no-border max-full-width full-height flex-grow&#x22;&#xA;  src=&#x22;https://codepen.io/redbulldesign/embed/128c2af5c1a0c97f34874e17958ed876?defaultTab=html%2Cresult&#x26;amp;editable=true&#x26;amp;theme-id=39623&#x22;&#xA;  height=&#x22;400px&#x22;&#xA;  loading=&#x22;lazy&#x22;&#xA;></iframe>"}

:::

Most components expose CSS Custom Properties. They are specified in a components API documentation under "CSS Custom Properties" section.

:::hint{type="warning"}
**🤝 Support**

We guarantee full support for the use of CSS Custom Properties in future minor and patch updates of Cosmos.
:::

## Shadow Parts

While Custom Properties offer an easy and fast way to customize a component's style, they are limited by design. For more flexibility and advanced styling, components offer a low-level way to customize them via CSS Shadow Parts.

Cosmos web components use a Shadow DOM to encapsulate their style and behavior. Consequently, their internals can not be targeted with the usual CSS selectors. Instead, they expose "parts" that can be targeted with the [CSS part selector](https://developer.mozilla.org/en-US/docs/Web/CSS/\::part) `::part()`.

We recommend using available CSS Custom Properties for customizations and only using the Shadow Parts of a component to extend its design beyond the ordinary.

:::hint{type="warning"}
**⚠️ Caution**

Customizing components using Shadow Parts isn't free of risks. Style overwrites are not guaranteed to work with future updates of Cosmos.
:::

:::Iframe{iframeHeight="0" code="<iframe&#xA;  title=&#x22;Embeded content from codepen.io&#x22;&#xA;  class=&#x22;no-border max-full-width full-height flex-grow&#x22;&#xA;  src=&#x22;https://codepen.io/redbulldesign/embed/4cf4dfe750d7616fd374f9890598eb6f?default-tab=html%2Cresult&#x26;amp;editable=true&#x26;amp;theme-id=39623&#x22;&#xA;  height=&#x22;600px&#x22;&#xA;></iframe>"}

:::

Most Cosmos web components do expose parts. They are specified in a components API documentation under "CSS Shadow Parts" section.

## Theming Dark and Light Mode

The `appearance` attribute of a component always reflects the current value even when it hasn't been specifically set. A theme that differentiates between a dark and light appearance can be achieved by targeting components using an attribute selector `[appearance="dark"]` or `[appearance="light"]`

:::Iframe{iframeHeight="0" code="<iframe&#xA;  title=&#x22;Embeded content from codepen.io&#x22;&#xA;  class=&#x22;no-border max-full-width full-height flex-grow&#x22;&#xA;  src=&#x22;https://codepen.io/redbulldesign/embed/86baf084a74ad8ed33d3db07dea53f14?default-tab=html%2Cresult&#x26;amp;editable=true&#x26;amp;theme-id=39623&#x22;&#xA;  height=&#x22;400px&#x22;&#xA;></iframe>"}

:::

:::hint{type="info"}
**Design to Engineering handover**
For guidance on how to understand Design to Engineering handover, refer to the documentation which covers both [simple scenarios](https://cosmos.redbull.design/figma#_VOVk) and [complex scenarios](https://cosmos.redbull.design/figma#38AUd).
:::



