> ## Documentation Index
> Fetch the complete documentation index at: https://www.beeq.design/llms.txt
> Use this file to discover all available pages before exploring further.

# Component CSS Variables

> Each BEEQ component exposes CSS custom properties that give you fine-grained control over styling without touching global variables.

export const CodeLivePreview = ({code, children, height, removePadding = false, mode = 'shadow'}) => {
  const previewRef = useRef(null);
  const BEEQ_ESM_URL = 'https://esm.sh/@beeq/core/dist/beeq/beeq.esm.js';
  const BEEQ_CSS_URL = 'https://esm.sh/@beeq/core/dist/beeq/beeq.css';
  const BEEQ_ICONS_URL = 'https://esm.sh/@beeq/core/dist/beeq/svg';
  const ensureParentBeeqRuntime = () => {
    if (document.querySelector('script[data-beeq-parent-runtime]')) return;
    const script = document.createElement('script');
    script.type = 'module';
    script.src = BEEQ_ESM_URL;
    script.dataset.beeqParentRuntime = BEEQ_ICONS_URL;
    document.head.appendChild(script);
  };
  const executeSnippetScripts = (root, runtimeWindow, previewRootArg, skipAttr) => {
    root.querySelectorAll('script').forEach(oldScript => {
      if (skipAttr && oldScript.hasAttribute(skipAttr)) return;
      if (oldScript.src) {
        const newScript = runtimeWindow.document.createElement('script');
        newScript.src = oldScript.src;
        oldScript.replaceWith(newScript);
        return;
      }
      runtimeWindow.Function('previewRoot', oldScript.textContent || '')(previewRootArg);
      oldScript.remove();
    });
  };
  const syncIframeMode = iframeDoc => {
    const root = document.documentElement;
    const explicitMode = root.getAttribute('bq-mode');
    const isDark = root.classList.contains('dark');
    const resolvedMode = explicitMode || (isDark ? 'dark' : 'light');
    iframeDoc.documentElement.setAttribute('bq-mode', resolvedMode);
    iframeDoc.body.setAttribute('bq-mode', resolvedMode);
  };
  useEffect(() => {
    if (mode === 'shadow') ensureParentBeeqRuntime();
  }, [mode]);
  useEffect(() => {
    const container = previewRef.current;
    if (!container) return;
    if (removePadding) container.style.padding = '0';
    container.innerHTML = '';
    if (mode === 'iframe') {
      const iframe = document.createElement('iframe');
      iframe.className = 'preview-iframe';
      iframe.style.width = '100%';
      iframe.style.border = '0';
      iframe.style.display = 'block';
      iframe.style.minHeight = height ?? '0px';
      iframe.setAttribute('title', 'Live code preview');
      iframe.setAttribute('loading', 'lazy');
      iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
      container.appendChild(iframe);
      const iframeDoc = iframe.contentDocument;
      const iframeWin = iframe.contentWindow;
      if (!iframeDoc || !iframeWin) return;
      iframeDoc.open();
      iframeDoc.write(['<!doctype html>', '<html>', '<head>', '  <meta charset="utf-8" />', '  <meta name="viewport" content="width=device-width, initial-scale=1" />', '  <style>html,body{margin:0;padding:0;min-height:100%;}</style>', `  <link rel="stylesheet" href="${BEEQ_CSS_URL}" />`, `  <script type="module" src="${BEEQ_ESM_URL}" data-beeq-iframe-runtime="${BEEQ_ICONS_URL}"></script>`, '</head>', '<body>', code, '</body>', '</html>'].join('\n'));
      iframeDoc.close();
      syncIframeMode(iframeDoc);
      const modeObserver = new MutationObserver(() => syncIframeMode(iframeDoc));
      modeObserver.observe(document.documentElement, {
        attributes: true,
        attributeFilter: ['class', 'bq-mode']
      });
      executeSnippetScripts(iframeDoc, iframeWin, iframeDoc, 'data-beeq-iframe-runtime');
      return () => modeObserver.disconnect();
    }
    const shadowRoot = container.shadowRoot ?? container.attachShadow({
      mode: 'open'
    });
    if (!shadowRoot.adoptedStyleSheets.length) {
      const fixSheet = new CSSStyleSheet();
      fixSheet.replaceSync(`
        bq-dropdown::part(panel),
        bq-panel::part(panel),
        bq-select::part(panel),
        bq-date-picker::part(panel) { z-index: 9999; }
        bq-tooltip::part(panel) { position: absolute; }
      `);
      shadowRoot.adoptedStyleSheets = [fixSheet];
    }
    shadowRoot.innerHTML = [`<link rel="stylesheet" href="${BEEQ_CSS_URL}">`, code].join('');
    executeSnippetScripts(shadowRoot, window, shadowRoot);
    return undefined;
  }, [code, mode, height]);
  return <div className="code-live-preview not-prose">
      {}
      <div className="preview" ref={previewRef} style={{
    minHeight: height
  }} />

      {}
      {children && <div className="code">{children}</div>}
    </div>;
};

Each component provides its own CSS custom properties, scoped to that component. This lets you tweak colors, spacing, or other design tokens locally without breaking consistency across the theme. You can find the component CSS variables listed at the bottom of each component documentation page.

For a practical overview of all three customization techniques — shadow DOM parts, global token overrides, and component variables — see [Styles](/guides/styles).

<Tip>
  For quick reference, you can also check these variables documented in each component's `scss/*.variables.scss` file on [GitHub](https://github.com/Endava/BEEQ/tree/main/packages/beeq/src/components).
</Tip>

***

## How to override component CSS variables

There are two strategies for customizing a BEEQ component's styles:

<CardGroup cols={2}>
  <Card title="Global override" icon="globe">
    Set CSS custom properties on the component element selector to apply changes across **all instances** of a component in your theme.
  </Card>

  <Card title="Targeted override" icon="crosshairs">
    Use CSS classes or specific component selectors to customize **individual instances** without affecting others.
  </Card>
</CardGroup>

### Global override

Set CSS custom properties directly on the component selector. This applies the customization to all instances of that component across your entire application.

```css theme={"theme":{"light":"one-light","dark":"night-owl"}}
bq-<component> {
  --bq-<component>--<property>: value;
}
```

### Targeted override

Create a custom CSS class and apply it to specific component instances. This gives fine-grained control without affecting other instances.

```css theme={"theme":{"light":"one-light","dark":"night-owl"}}
.my-component-variant {
  --bq-<component>--<property>: value;
}
```

```html theme={"theme":{"light":"one-light","dark":"night-owl"}}
<bq-component class="my-component-variant">Content</bq-component>
```

***

## Example: customizing the Badge component

The [Badge](/components/badge) component exposes the following CSS custom properties (see [`bq-badge.variables.scss`](https://github.com/Endava/BEEQ/blob/main/packages/beeq/src/components/badge/scss/bq-badge.variables.scss)):

```css theme={"theme":{"light":"one-light","dark":"night-owl"}}
--bq-badge--background-color: /* Badge background */
--bq-badge--box-shadow:       /* Badge shadow */
--bq-badge--border-color:     /* Badge border color */
--bq-badge--border-radius:    /* Badge border radius */
--bq-badge--border-style:     /* Badge border style */
--bq-badge--border-width:     /* Badge border width */
--bq-badge--size-small:       /* Small badge size (8px) */
--bq-badge--size-medium:      /* Medium badge size (12px) */
--bq-badge--size-large:       /* Large badge size (16px) */
--bq-badge--text-color:       /* Badge text color */
```

### Global override

Applies the custom styles to every `bq-badge` in the application.

<CodeLivePreview
  mode="shadow"
  code={`
<style>
:host {
  flex-direction: row !important;
  flex-wrap: wrap !important;
}
bq-badge {
  --bq-badge--background-color: var(--bq-green-400);
  --bq-badge--box-shadow: var(--bq-box-shadow--l);
  --bq-badge--border-color: var(--bq-green-600);
  --bq-badge--border-style: solid;
  --bq-badge--border-width: 1px;
  --bq-badge--border-radius: 4px;
}
</style>
<bq-badge size="small"></bq-badge>
<bq-badge size="medium"></bq-badge>
<bq-badge>99+</bq-badge>
`}
>
  <CodeGroup>
    ```css styles.css icon="css" expandable theme={"theme":{"light":"one-light","dark":"night-owl"}}
    bq-badge {
      --bq-badge--background-color: var(--bq-green-400);
      --bq-badge--box-shadow: var(--bq-box-shadow--l);
      --bq-badge--border-color: var(--bq-green-600);
      --bq-badge--border-style: solid;
      --bq-badge--border-width: 1px;
      --bq-badge--border-radius: 4px;
    }
    ```

    ```html HTML icon="html5" theme={"theme":{"light":"one-light","dark":"night-owl"}}
    <bq-badge size="small"></bq-badge>
    <bq-badge size="medium"></bq-badge>
    <bq-badge>99+</bq-badge>
    ```

    ```jsx React icon="react" theme={"theme":{"light":"one-light","dark":"night-owl"}}
    import { BqBadge } from "@beeq/react";
    import "./styles.css";
    // Import the CSS override in your global stylesheet

    <BqBadge size="small" />
    <BqBadge size="medium" />
    <BqBadge>99+</BqBadge>
    ```

    ```ts Angular icon="angular" expandable theme={"theme":{"light":"one-light","dark":"night-owl"}}
    import { Component } from "@angular/core";
    import { BqBadge } from "@beeq/angular/standalone";

    @Component({
      selector: "app-root",
      standalone: true,
      imports: [BqBadge],
      template: `
        <bq-badge size="small"></bq-badge>
        <bq-badge size="medium"></bq-badge>
        <bq-badge>99+</bq-badge>
      `,
      styles: [`
        bq-badge {
          --bq-badge--background-color: var(--bq-green-400);
          --bq-badge--box-shadow: var(--bq-box-shadow--l);
          --bq-badge--border-color: var(--bq-green-600);
          --bq-badge--border-style: solid;
          --bq-badge--border-width: 1px;
          --bq-badge--border-radius: 4px;
        }
      `],
    })
    export class AppComponent {}
    ```

    ```vue Vue icon="vuejs" expandable theme={"theme":{"light":"one-light","dark":"night-owl"}}
    <script setup lang="ts">
    import { BqBadge } from "@beeq/vue";
    </script>

    <template>
      <BqBadge size="small" />
      <BqBadge size="medium" />
      <BqBadge>99+</BqBadge>
    </template>


    <style>
      bq-badge {
        --bq-badge--background-color: var(--bq-green-400);
        --bq-badge--box-shadow: var(--bq-box-shadow--l);
        --bq-badge--border-color: var(--bq-green-600);
        --bq-badge--border-style: solid;
        --bq-badge--border-width: 1px;
        --bq-badge--border-radius: 4px;
      }
    </style>
    ```
  </CodeGroup>
</CodeLivePreview>

### Targeted override

Only the `bq-badge` elements with the matching CSS class will have the overridden style.

<CodeLivePreview
  mode="shadow"
  code={`
<style>
:host {
  flex-direction: row !important;
  flex-wrap: wrap !important;
}
bq-badge.success {
  --bq-badge--background-color: var(--bq-green-400);
  --bq-badge--box-shadow: var(--bq-box-shadow--l);
  --bq-badge--border-color: var(--bq-green-600);
  --bq-badge--border-style: solid;
  --bq-badge--border-width: 1px;
  --bq-badge--border-radius: 4px;
}
</style>

<bq-badge size="small"></bq-badge>
<bq-badge size="medium"></bq-badge>
<bq-badge>99+</bq-badge>
<bq-badge class="success">completed</bq-badge>
`}
>
  <CodeGroup>
    ```css styles.css icon="css" expandable theme={"theme":{"light":"one-light","dark":"night-owl"}}
    bq-badge.success {
      --bq-badge--background-color: var(--bq-green-400);
      --bq-badge--box-shadow: var(--bq-box-shadow--l);
      --bq-badge--border-color: var(--bq-green-600);
      --bq-badge--border-style: solid;
      --bq-badge--border-width: 1px;
      --bq-badge--border-radius: 4px;
    }
    ```

    ```html HTML icon="html5" theme={"theme":{"light":"one-light","dark":"night-owl"}}
    <bq-badge size="small"></bq-badge>
    <bq-badge size="medium"></bq-badge>
    <bq-badge>99+</bq-badge>
    <bq-badge class="success">completed</bq-badge>
    ```

    ```jsx React icon="react" expandable theme={"theme":{"light":"one-light","dark":"night-owl"}}
    import { BqBadge } from "@beeq/react";
    import "./styles.css";
    // Import the CSS override in your global stylesheet

    <BqBadge size="small" />
    <BqBadge size="medium" />
    <BqBadge>99+</BqBadge>
    <BqBadge className="success">completed</BqBadge>
    ```

    ```ts Angular icon="angular" expandable theme={"theme":{"light":"one-light","dark":"night-owl"}}
    import { Component } from "@angular/core";
    import { BqBadge } from "@beeq/angular/standalone";

    @Component({
      selector: "app-root",
      standalone: true,
      imports: [BqBadge],
      template: `
        <bq-badge size="small"></bq-badge>
        <bq-badge size="medium"></bq-badge>
        <bq-badge>99+</bq-badge>
        <bq-badge class="success">completed</bq-badge>
      `,
      styles: [`
        bq-badge.success {
          --bq-badge--background-color: var(--bq-green-400);
          --bq-badge--box-shadow: var(--bq-box-shadow--l);
          --bq-badge--border-color: var(--bq-green-600);
          --bq-badge--border-style: solid;
          --bq-badge--border-width: 1px;
          --bq-badge--border-radius: 4px;
        }
      `],
    })
    export class AppComponent {}
    ```

    ```vue Vue icon="vuejs" expandable theme={"theme":{"light":"one-light","dark":"night-owl"}}
    <script setup lang="ts">
    import { BqBadge } from "@beeq/vue";
    </script>

    <template>
      <BqBadge size="small" />
      <BqBadge size="medium" />
      <BqBadge>99+</BqBadge>
      <BqBadge class="success">completed</BqBadge>
    </template>


    <style>
      bq-badge.success {
        --bq-badge--background-color: var(--bq-green-400);
        --bq-badge--box-shadow: var(--bq-box-shadow--l);
        --bq-badge--border-color: var(--bq-green-600);
        --bq-badge--border-style: solid;
        --bq-badge--border-width: 1px;
        --bq-badge--border-radius: 4px;
      }
    </style>
    ```
  </CodeGroup>
</CodeLivePreview>

***

## Best practices

<CardGroup cols={2}>
  <Card>
    <span className="flex items-center mr-2 text-lg font-medium" role="heading">
      <Icon className="mr-2" icon="check" iconType="solid" size={20} color="var(--bq-stroke--success)" />

      Do
    </span>

    Prefer declarative color variables (`--bq-background--primary`) over primitive values (`--bq-grey-100`) in your custom themes for better consistency and automatic light/dark mode switching.
  </Card>

  <Card>
    <span className="flex items-center mr-2 text-lg font-medium" role="heading">
      <Icon className="mr-2" icon="xmark" iconType="solid" size={20} color="var(--bq-stroke--danger)" />

      Don't
    </span>

    Do not hardcode raw hex values (e.g. `#ffffff`, `#1f2937`) in component overrides — they will not adapt to theme or mode changes automatically.
  </Card>

  <Card>
    <span className="flex items-center mr-2 text-lg font-medium" role="heading">
      <Icon className="mr-2" icon="check" iconType="solid" size={20} color="var(--bq-stroke--success)" />

      Do
    </span>

    Use CSS classes or component selectors to scope component overrides to specific instances and avoid unintended side effects elsewhere in the app.
  </Card>

  <Card>
    <span className="flex items-center mr-2 text-lg font-medium" role="heading">
      <Icon className="mr-2" icon="xmark" iconType="solid" size={20} color="var(--bq-stroke--danger)" />

      Don't
    </span>

    Do not apply a global component override (e.g. `bq-badge { ... }`) unless you intentionally want it to affect every instance across the entire application.
  </Card>

  <Card>
    <span className="flex items-center mr-2 text-lg font-medium" role="heading">
      <Icon className="mr-2" icon="check" iconType="solid" size={20} color="var(--bq-stroke--success)" />

      Do
    </span>

    Always test your component overrides in both light and dark modes to verify proper contrast, readability, and visual consistency.
  </Card>

  <Card>
    <span className="flex items-center mr-2 text-lg font-medium" role="heading">
      <Icon className="mr-2" icon="xmark" iconType="solid" size={20} color="var(--bq-stroke--danger)" />

      Don't
    </span>

    Do not skip contrast validation. WCAG 2.1 Level AA requires a 4.5:1 ratio for normal text and 3:1 for large text — overriding colors without checking can fail these requirements.
  </Card>

  <Card>
    <span className="flex items-center mr-2 text-lg font-medium" role="heading">
      <Icon className="mr-2" icon="check" iconType="solid" size={20} color="var(--bq-stroke--success)" />

      Do
    </span>

    Use the [primitive color palette](/foundations/colors#primitive-color-scales) as the source for custom theme colors. It includes blue, coral, cyan, gold, green, indigo, iris, lime, magenta, orange, purple, red, sky, teal, volcano, and yellow — each with 10 shades (100–1000).
  </Card>

  <Card>
    <span className="flex items-center mr-2 text-lg font-medium" role="heading">
      <Icon className="mr-2" icon="xmark" iconType="solid" size={20} color="var(--bq-stroke--danger)" />

      Don't
    </span>

    Do not invent arbitrary color values outside the palette. Random hex colors break visual harmony and make future theme maintenance much harder.
  </Card>
</CardGroup>
