# cssVariables

**Import:** `import { cssVariables } from '@reuters-graphics/graphics-components'`

## Documentation

# `cssVariables`

An action you can use to easily set [CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties) on HTML elements. Useful for passing JavaScript values to your component SCSS like this:

```svelte
<script>
  import { cssVariables } from '@reuters-graphics/graphics-components';

  let { height = 300, textColour = 'red' } = $props();

  // Create an object of variable names and CSS values...
  let variables = $derived({
    height: height + 'px',
    textColour: textColour,
  });
</script>

<!-- Attach it to a parent element with the action -->
<div use:cssVariables={variables}>
  <p>My text...</p>
</div>

<style lang="scss">
  /**
   * Now use your variables in your SCSS!
   */
  div {
    height: var(--height);
    p {
      color: var(--textColour);
    }
  }
</style>
```
