### NPM Installation and Import (Bash)
Source: https://context7.com/color-js/elements/llms.txt
Installs the color-elements package using NPM. This is the recommended method for production builds.
```bash
npm i color-elements
```
--------------------------------
### Install and Import Color Elements via NPM
Source: https://github.com/color-js/elements/blob/main/README.md
These JavaScript snippets show how to install and import Color.js elements using NPM. You can import all elements with `import "color-elements";` or cherry-pick individual components using `import "color-elements/COMPONENT_NAME";`.
```bash
npm i color-elements
```
```javascript
import "color-elements";
```
```javascript
import "color-elements/COMPONENT_NAME";
```
--------------------------------
### Color Swatch Element Usage
Source: https://github.com/color-js/elements/blob/main/src/color-swatch/README.md
Examples demonstrating how to use the color-swatch component with different slot configurations and attributes.
```APIDOC
## Color Swatch Element Examples
### With Slot Content
#### Before and After Slots
```html
```
```html
oklch(70% 0.25 138)
```
#### Large Swatch with Before and After Slots
```html
Tip: Pick a bright medium color.
```
### Adding Text within the Default Swatch
```html
Some text
```
*Note: The text color will automatically switch from black to white to remain readable.*
### Replacing the Whole Swatch with a Custom Element
```html
Some text
```
### Bound to CSS Property
*This section is commented out in the provided text but illustrates binding to a CSS property.*
```html
```
*You can use `scope` to select the closest ancestor (via a CSS selector) on which the CSS property will be read from and written to. If you don’t, the `` element will be used.*
```
--------------------------------
### Color Swatch Element Events and Updates
Source: https://github.com/color-js/elements/blob/main/src/color-swatch/README.md
Examples showing how to handle color change events and update the color programmatically via JavaScript.
```APIDOC
## Events and Updates
### Events
```html
```
### Update via JS
#### Static Update
```html
oklch(70% 0.25 138)
```
#### Editable Update
```html
```
```
--------------------------------
### HTML Color Swatch Component Usage
Source: https://context7.com/color-js/elements/llms.txt
Illustrates various ways to use the `` web component. Examples include displaying a static color, creating an editable swatch with an input field, showing custom color information with labels, and using compact details on hover. It also shows how to handle 'colorchange' events.
```html
oklch(70% 0.25 138)
oklch(70% 0.25 138)
oklch(70% 0.25 138)
```
--------------------------------
### HTML: Compact color scale styling
Source: https://github.com/color-js/elements/blob/main/src/color-scale/README.md
This example shows how to apply compact styling to the color scale by setting the '--details-style' CSS variable. This reduces the amount of information displayed for each color swatch, making the scale more visually condensed. The 'info' attribute is still used to define the data shown.
```html
```
--------------------------------
### Basic HTML: Displaying colors via attribute
Source: https://github.com/color-js/elements/blob/main/src/color-scale/README.md
This example demonstrates the basic usage of the `` component by defining a list of colors directly in the 'colors' attribute. The 'space' attribute specifies the color space for interpolation, which is 'oklch' in this case. This is a fundamental way to render color gradients.
```html
```
--------------------------------
### HTML: Interpolating between two core colors
Source: https://github.com/color-js/elements/blob/main/src/color-scale/README.md
This example illustrates how to specify only two core colors and use the 'steps' attribute to generate a gradient between them. The component will automatically interpolate the specified number of steps in the given color space ('oklch'). This is useful for creating simple gradients.
```html
```
--------------------------------
### Color Swatch Event Handling - HTML
Source: https://github.com/color-js/elements/blob/main/src/color-swatch/README.md
Demonstrates how to handle the `oncolorchange` event to react to color updates. In this example, the event updates the text content of the next sibling element with the new color value.
```html
```
--------------------------------
### Dynamically Update Color Swatch via JavaScript - HTML
Source: https://github.com/color-js/elements/blob/main/src/color-swatch/README.md
Provides examples of how to change the color of a color swatch programmatically using JavaScript. This covers both static and editable swatches, demonstrating direct property assignment.
```html
oklch(70% 0.25 138)
```
```html
```
--------------------------------
### Semi-transparent Color in
Source: https://github.com/color-js/elements/blob/main/src/color-inline/README.md
Provides an example of using a semi-transparent color with the component. The alpha channel is included in the color string, resulting in a partially opaque color swatch.
```html
hsl(340 90% 50% / .25)
```
--------------------------------
### HTML: Customizing color swatch information
Source: https://github.com/color-js/elements/blob/main/src/color-scale/README.md
This example demonstrates how to pass additional information to the individual color swatches generated by the `` component. The 'info' attribute accepts a comma-separated string defining properties like lightness (L), chroma (C), and hue (H) in the specified color space, which will be displayed for each color.
```html
```
--------------------------------
### `label` Attribute Usage in `` (HTML)
Source: https://github.com/color-js/elements/blob/main/src/color-swatch/README.md
Demonstrates the use of the `label` attribute to provide a descriptive name for the color displayed in a ``, showing examples for static and editable swatches.
```html
oklch(65% 0.15 210)oklch(65% 0.15 210)Turquoise
```
--------------------------------
### with Initial Color (HTML)
Source: https://github.com/color-js/elements/blob/main/src/channel-slider/README.md
Illustrates setting an initial color for the component. This sets the other color channels and the starting value of the controlled channel. The component converts the provided color to the target space if necessary.
```html
```
--------------------------------
### Setting Initial `value`
Source: https://github.com/color-js/elements/blob/main/src/color-slider/README.md
Explains how to set an initial color value for the `` using the `value` attribute, allowing the slider to start at a position other than the midpoint.
```html
```
--------------------------------
### HTML: Named colors and interpolation steps
Source: https://github.com/color-js/elements/blob/main/src/color-scale/README.md
This example shows how to define colors with specific names and use interpolation to generate intermediate steps. The 'colors' attribute accepts a string where each color can be optionally prefixed with a name followed by a colon. The 'steps' attribute controls the number of interpolated colors between each defined color.
```html
```
--------------------------------
### Color Picker with Custom Color Space Selector (HTML)
Source: https://github.com/color-js/elements/blob/main/src/color-picker/README.md
Demonstrates how to provide a custom element for selecting the color space using the `color-space` slot. This example uses a `