# Use CSS Variables

[Web Components](/web/component.md) ⟩ [Shadow DOM](/web/component/shadow-dom.md) ⟩ [Styling](/web/component/shadow-dom/styles.md) ⟩

{% tabs %}
{% tab title="📗 參考" %}

* Google ⟩ Web Component ⟩ [Creating style hooks using CSS custom properties](https://developers.google.com/web/fundamentals/web-components/shadowdom#stylehooks)
  {% endtab %}

{% tab title="👉 相關" %}

* [Styling Slotted Content](/web/component/template/slot/slotted-elements.md#styling-slotted-content)
* [CSS Variables](/web/css/var.md)
  {% endtab %}
  {% endtabs %}

{% hint style="info" %}

* ⭐️ use **CSS variables**: \
  CSS variables exist **on all levels**, **both in light and shadow**.\
  📗 JS.info ⟩ [CSS hooks with custom properties](https://javascript.info/shadow-dom-style#css-hooks-with-custom-properties)
  {% endhint %}

{% tabs %}
{% tab title="html" %}

```markup
<style>
  fancy-tabs {
    margin-bottom: 32px;
    --fancy-tabs-bg: black;  <!-- ⭐️ css var -->
  }
</style>
<fancy-tabs background>...</fancy-tabs>
```

{% endtab %}

{% tab title="shadow DOM" %}

```css
/* inside shadow DOM */
:host([background]) {
  background: var(--fancy-tabs-bg, #9E9E9E);    /* ⭐️ css hook */
  border-radius: 10px;
  padding: 10px;
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/web/component/shadow-dom/styles/css-vars.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
