# Blazor ColorPicker Overview

The <a href="https://www.telerik.com/blazor-ui/colorpicker" target="_blank">Telerik UI ColorPicker for Blazor</a> is an interactive component that allows users to select colors from a popup palette or a [Hue, Saturation, Value (HSV) canvas](https://en.wikipedia.org/wiki/HSL_and_HSV), and also manually type a specific RGB or HEX color value.

Practically, the ColorPicker is identical to the [Telerik UI for Blazor FlatColorPicker component](https://www.telerik.com/blazor-ui/documentation/components/flatcolorpicker/overview) with the only difference that the ColorPicker takes up less space and displays the color selection UI in a popup.

## Creating Blazor ColorPicker

1. Add the `TelerikColorPicker` tag.
2. Set its `string` `Value` parameter to any of the [supported HEX or RGB formats](https://www.telerik.com/blazor-ui/documentation/components/colorpicker/overview#supported-value-formats). The parameter supports two-way binding or [one-way binding with a `ValueChanged` handler](https://www.telerik.com/blazor-ui/documentation/components/colorpicker/events#valuechanged).
3. (optional) If your app expects a specific color format, set the `ValueFormat` to `ColorFormat.Hex` or `ColorFormat.Rgb`.

> caption A basic ColorPicker with two-way value binding

```CSHTML
<TelerikColorPicker @bind-Value="@MyColor" ValueFormat="ColorFormat.Hex"/>

<p>Selected color: <span style="color: @MyColor">@MyColor</span></p>

@code {
    string MyColor { get; set; }
}
```

## Views

The Blazor [ColorPicker component comes with the Palette and Gradient views](https://www.telerik.com/blazor-ui/documentation/components/colorpicker/views) which allow users to select a color from an interface that matches their preferences.

## Interface

The image below shows the supported Blazor ColorPicker interface elements, including:

* (Outside the popup) Main component button with the current value and a drop-down arrow.
* (Top left) View selectors.
* (Top right) Color preview box.
* (Below the color preview) Current color box.
* (Top) **Clear** button.
* (Middle) Palette tiles or HSV canvas with hue and opacity sliders.
* (Bottom) RGBA or HEX value textboxes with a **Toggle** button.
* (Bottom) **Apply** and **Cancel** buttons.

Clicking outside the ColorPicker popup applies an **Apply** button behavior.

![ColorPicker component](https://www.telerik.com/blazor-ui/documentation/assets/dc91abd8ec5cd5f03fbb398fc24ae948/colorpicker-overview.gif)

## Events

The Blazor ColorPicker fires a set of events that you can handle to further customize its behavior. [Read more about the Telerik UI for Blazor ColorPicker events](https://www.telerik.com/blazor-ui/documentation/components/colorpicker/events).

## Supported Value Formats

The Blazor ColorPicker accepts values by the application code in the following formats:

* Hexadecimal
  * 3 digits - `#f00`
  * 6 digits - `#ff0000`
  * 8 digits, including alpha opacity - `#ff000080`
* RGB or RGBA
  * integer color values - `rgb(255, 0, 0)`
  * percentage color values - `rgb(100%, 0%, 0%)`
  * the alpha opacity must always be a decimal number between 0 and 1 - `rgba(100%, 0%, 0%, 0.5)`. Note the `rgba()` notation, compared to `rgb()` above.

Users can type values in the following formats:

* All hexadecimal
* RGB and RGBA with integer color values

The ColorPicker does not support color keywords.

Make sure that the initial `Value` uses one of the supported formats. For example, `#ebebeff` is not a valid hexadecimal value because it contains seven hexadecimal digits after the `#` character. Use a 6-digit hexadecimal value such as `#ebebef`, or an 8-digit hexadecimal value that includes alpha opacity, such as `#ebebefff`.

## Adaptive Rendering

<demo metaUrl="client/colorpicker/adaptive/" height="555"></demo>

The component supports different popup rendering depending on the screen size. [Read more about the Adaptive Rendering functionality and how to enable it...](https://www.telerik.com/blazor-ui/documentation/common-features/adaptive-rendering)

## ColorPicker Parameters

The Blazor ColorPicker provides various parameters to configure the component. For more configuration options, see the [public Telerik UI for Blazor ColorPicker API](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.telerikcolorpicker).

The ColorPicker tag exposes the following features through its attributes:

| Parameter          | Type and Default Value                     | Description                                                                                                                                                                                                                                                                                                                                                    |
| ------------------ | ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `AdaptiveMode`     | `AdaptiveMode` <br /> (`None`)             | The [adaptive mode](https://www.telerik.com/blazor-ui/documentation/common-features/adaptive-rendering) of the component.                                                                                                                                                                                                                                      |
| `Value`            | `string`                                   | The ColorPicker value in a few [different color formats](https://www.telerik.com/blazor-ui/documentation/components/colorpicker/overview#supported-value-formats). Supports two-way binding.                                                                                                                                                                   |
| `ValueFormat`      | `ColorFormat` enum <br /> (`Rgb`)          | Sets the color format, which the component will return in the application code - `Rgb` or `Hex`.                                                                                                                                                                                                                                                               |
| `ColorPickerViews` | `RenderFragment`                           | A nested container to list the [ColorPicker views](https://www.telerik.com/blazor-ui/documentation/components/colorpicker/views). All views are enabled by default and the user can switch between them with the buttons. Each view tag has its own configuration attributes.                                                                                  |
| `View`             | `ColorPickerView` enum <br /> (`Gradient`) | The default selected [view](https://www.telerik.com/blazor-ui/documentation/components/colorpicker/views). Supports two-way binding.                                                                                                                                                                                                                           |
| `ShowPreview`      | `bool` <br /> (`true`)                     | Toggles the visibility of the [current color box and the color preview box](https://www.telerik.com/blazor-ui/documentation/components/colorpicker/overview#interface) in the popup.                                                                                                                                                                           |
| `Class`            | `string`                                   | A custom CSS class for the `span.k-colorpicker` element.                                                                                                                                                                                                                                                                                                       |
| `Enabled`          | `bool` <br /> (`true`)                     | Determines if the user can open the popup and change the value.                                                                                                                                                                                                                                                                                                |
| `ShowButtons`      | `bool` <br /> (`true`)                     | Controls the visibility of the **Apply** and **Cancel** buttons.                                                                                                                                                                                                                                                                                               |
| `ShowClearButton`  | `bool` <br /> (`true`)                     | Sets the visibility of the **Clear** button.                                                                                                                                                                                                                                                                                                                   |
| `Icon`             | `object`                                   | Adds a font icon inside the [main component button](https://www.telerik.com/blazor-ui/documentation/components/colorpicker/overview#interface). You can find more information on adding a font icon to a Telerik Component in the [Telerik Font and Svg Icons article](https://www.telerik.com/blazor-ui/documentation/common-features/icons#icon-namespaces). |
| `IconVariant`      | `string`                                   | Selects the [SVG icon variant](https://www.telerik.com/blazor-ui/documentation/common-features/icons#use-svg-icon-variants).                                                                                                                                                                                                                                   |

### Styling and Appearance

The following parameters enable you to customize the appearance of the Blazor ColorPicker:

| Parameter  | Type                                                 | Description                                     |
| ---------- | ---------------------------------------------------- | ----------------------------------------------- |
| `Size`     | `Telerik.Blazor.ThemeConstants.ColorPicker.Size`     | Adjusts the size of the ColorPicker.            |
| `Rounded`  | `Telerik.Blazor.ThemeConstants.ColorPicker.Rounded`  | Affects the `border-radius` of the ColorPicker. |
| `FillMode` | `Telerik.Blazor.ThemeConstants.ColorPicker.FillMode` | Controls how the ColorPicker is filled.         |

For more information on customizing the ColorPicker styling, see the article about [setting the appearance of the ColorPicker](https://www.telerik.com/blazor-ui/documentation/components/colorpicker/appearance).

## ColorPicker Reference and Methods

To use the [methods of the Blazor ColorPicker](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.telerikcolorpicker), add a reference to the component instance.

<style>
    .article table {
        table-layout: auto;
        word-break: normal;
    }
</style>

| Method       | Description                                                                                       |
| ------------ | ------------------------------------------------------------------------------------------------- |
| `Close`      | Closes the component popup.                                                                       |
| `FocusAsync` | Focuses the main element of the component. Always `await` this call, as it relies on `JSInterop`. |
| `Open`       | Opens the component popup.                                                                        |

<demo metaUrl="client/colorpicker/methods/" height="220"></demo>

## Next Steps

* [Explore the Telerik UI for Blazor ColorPicker Views](https://www.telerik.com/blazor-ui/documentation/components/colorpicker/views)
* [Handle the Blazor ColorPicker Events](https://www.telerik.com/blazor-ui/documentation/components/colorpicker/events)

## See Also

* [Blazor ColorPicker Overview (Live Demo)](https://demos.telerik.com/blazor-ui/colorpicker/overview)
* [Blazor ColorPicker API Reference](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.telerikcolorpicker)
