BlazorColorPicker 4.5.1

dotnet add package BlazorColorPicker --version 4.5.1
                    
NuGet\Install-Package BlazorColorPicker -Version 4.5.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BlazorColorPicker" Version="4.5.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BlazorColorPicker" Version="4.5.1" />
                    
Directory.Packages.props
<PackageReference Include="BlazorColorPicker" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BlazorColorPicker --version 4.5.1
                    
#r "nuget: BlazorColorPicker, 4.5.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BlazorColorPicker@4.5.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BlazorColorPicker&version=4.5.1
                    
Install as a Cake Addin
#tool nuget:?package=BlazorColorPicker&version=4.5.1
                    
Install as a Cake Tool

Blazor-Color-Picker

NuGet BlazorColorPicker Nuget Package GitHub

Sometimes HTML5 colorpicker doesn't suit me for an application. I prefer to offer the user a predefined color palette

DEMO : https://tossnet.github.io/Blazor-Color-Picker/

Opens a palette with the Material colors

Blazor Color Picker

<img width="864" height="672" alt="Enregistrement 2026-11-16 111506" src="https://github.com/user-attachments/assets/866d2f96-c6fa-4650-bad1-7dcbf722eb39" />

Installation

The implementation has been improved: version 4.0 uses a service declared via dependency injection

Latest version in here: NuGet

To Install

Install-Package BlazorColorPicker

or

dotnet add package BlazorColorPicker

For client-side and server-side Blazor - add script section to index.html or _Host.cshtml (head section)

<link href="_content/BlazorColorPicker/colorpicker.css" rel="stylesheet" />

In program.cs, declare

builder.Services.AddColorPicker();

ColorPicker are rendered by the <BlazorColorPicker.ColorPicker />. This component needs to be added to the main layout of your application/site. You typically do this in the MainLayout.razor file at the end of the <main> section.

Usage

@page "/"
@using BlazorColorPicker

@inject IColorPickerService ColorPickerService

<button class="btn btn-primary" @onclick="OpenModal">
    <div style="background-color:@color" class="buttonColor"></div> Select a Color
</button>

@code {
    private string color = "#F1F7E9";

    private async Task OpenModal()
    {
        var parameters = new ColorPickerParameters
        {
        	ColorSelected = color,
        };
        color = await ColorPickerService.ShowColorPicker(parameters);
    }
}

Z-Index

By default the color picker modal uses z-index: 9999. If your app has a parent element with a higher z-index, the palette may appear behind it. Two override options are available:

Option 1 — CSS custom property (global, no code change needed):

:root {
    --color-picker-z-index: 999999;
}

Option 2 — ZIndex parameter (per call):

var parameters = new ColorPickerParameters
{
    ColorSelected = color,
    ZIndex = 999999,
};
color = await ColorPickerService.ShowColorPicker(parameters);

Find Closest Color

When the selected color doesn't exist in the palette, you can enable automatic matching to the closest available color using the FindClosestIfNotFound parameter:

var parameters = new ColorPickerParameters
{
    ColorSelected = "#8B4513",  // SaddleBrown - not in the default palette
    FindClosestIfNotFound = true,
};
color = await ColorPickerService.ShowColorPicker(parameters);

The algorithm uses a weighted Euclidean distance in RGB color space, which accounts for human color perception (green differences are more noticeable than red or blue).

Color comparison is case-insensitive: #ec407a will match #EC407A in the palette.

Intensity & Hue sliders

Two optional sliders adjust the whole Material palette live (HSL, computed in C#, no JS interop). Both are off by default and can be enabled independently:

  • ShowIntensitySlider (vertical, 0..200, neutral 100): up = more vivid and slightly darker, down = greyer and lighter.
  • ShowHueSlider (horizontal, -180..+180, neutral 0): rotates the hue; pure greys don't move.

Near the neutral position (±4 intensity, ±7 hue), the mouse snaps back to neutral. The keyboard doesn't snap. Adjust the sliders first, then click a cell: the cell's adjusted color is returned.

Sliders only apply to the default palette. They are ignored when MyColorPallet is set.

Restoring the palette exactly

An adjusted color can't be mapped back to slider positions from its hex alone, so store the palette state with your setting. Use ShowPaletteChoice, which returns a PaletteChoice(BaseHex, Intensity, Hue, Hex). The cell is identified by its original Material color (BaseHex), so the stored JSON stays readable:

{"BaseHex":"#673BB7","Intensity":99,"Hue":61,"Hex":"#634EE1"}
private string color = "#2196F3";
private string? state; // JSON stored with the setting

var parameters = new ColorPickerParameters
{
    ColorSelected = color,
    ShowIntensitySlider = true,
    ShowHueSlider = true,
    PaletteChoice = PaletteChoice.Resolve(state, color), // state if present, else FromHex(color)
};

var choice = await ColorPickerService.ShowPaletteChoice(parameters);
if (choice is not null)
{
    color = choice.Hex;
    state = choice.ToJson();
}
  • PaletteChoice.Create("#2196F3") creates a state from a palette color (sliders at neutral, or pass intensity / hue).
  • PaletteChoice.FromHex(hex) finds the closest cell + slider combination. It returns null if the closest one is more than 12 apart (RGB distance). Then no cell is checked and the sliders stay neutral.
  • OnPaletteChoiceChanged (optional) is called each time the state changes while the palette is open.

<a name="ReleaseNotes"></a>Release Notes

<details open="open"><summary>Version 4.5.0</summary>

  • Optional Intensity and Hue sliders (ShowIntensitySlider, ShowHueSlider), off by default
  • PaletteChoice state, ShowPaletteChoice, FromHex and JSON persistence to restore the palette exactly
  • IColorPickerService gains ShowPaletteChoice (custom implementations of the interface must add it) </details>

<details><summary>Version 4.4.0</summary>

  • Configurable z-index via ZIndex parameter or CSS custom property --color-picker-z-index (default: 9999) </details>

<details><summary>Version 4.2.0</summary>

  • New feature: FindClosestIfNotFound parameter - when the selected color is not in the palette, automatically highlights the closest matching color
  • Color comparison is now case-insensitive (#ec407a matches #EC407A)
  • Uses weighted Euclidean distance algorithm for perceptually accurate color matching </details>

<details><summary>Version 4.1.1</summary>

  • Performance & memory optimization: default colors are now static and shared across all instances
  • Fixed memory leak in OnParametersSet() that caused unbounded list growth
  • Zero allocations when using default color palette </details>

<details><summary>Version 4.0.2</summary>

  • Added AddColorPicker() to simplify declaration </details>

<details><summary>Version 4.0.1</summary>

  • increase the z-index to 9999 </details>

<details><summary>Version 4.0.0</summary>

  • the implementation has been improved: version 4.0 uses a service declared via dependency injection </details>

⚠️ Breaking changes ⚠️

<details><summary>Version 3.1.0</summary>

  • you can customise the size of the palette using your CSS styles
  • A red colour of the first column was not correct
  • Re-addition of .NET7 compatibility </details>

<details><summary>Version 2.2.0</summary>

  • Remove the internal use of IJSRuntime </details>

<details><summary>Version 2.1.0</summary>

  • no need to declare the _content/BlazorColorPicker/colorpicker.js file </details>
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on BlazorColorPicker:

Package Downloads
PrototyperThemeRCL

Do not use yet. A Razor Class Library that provides user built themes to attach to pages and components. Themes are divided into 'Sets' and a set is applied to a page or component. No knowledge of CSS is required to set up a Theme.

PrototyperMenuRCL

Do not try to use this yet. A Razor Class Library that provides data driven menus. The current version only allows very graphical menu buttons. Menu 'Sets' contain menu 'Rows' which in turn contain 'buttons'. Clicking on a button can (1) go to another menu set (2) go to a page in the host app (3) load a component from the host or the RCL. Provides easy maintence of the data and easy to implement.

KristofferStrube.Blazor.SVGEditor

A SVG Editor that is implemented in and for Blazor.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on BlazorColorPicker:

Repository Stars
KristofferStrube/Blazor.SVGEditor
A basic SVG editor written in Blazor.
Version Downloads Last Updated
4.5.1 154 11/16/2026
4.4.0 9,389 6/10/2026
4.3.0 7,797 2/6/2026
4.2.0 1,178 1/23/2026
4.1.1 392 1/17/2026
4.1.0 216 1/14/2026
4.0.2 15,471 3/16/2025
4.0.1 339 3/15/2025
4.0.0 399 3/15/2025
3.1.2 10,219 11/15/2024
3.1.1 18,487 3/31/2024
3.1.0 660 3/30/2024
3.0.0 2,011 1/26/2024
2.3.1 5,080 11/15/2023
2.3.0 18,272 12/2/2022
2.2.0 5,163 10/22/2022
2.1.0 44,727 4/4/2022
2.0.1 1,796 2/16/2022
2.0.0 4,762 12/16/2021
Loading failed

4.5.1: republish of 4.5.0, whose package mistakenly contained the 4.4 binaries.
     Optional Intensity and Hue sliders (ShowIntensitySlider, ShowHueSlider) on the Material palette, PaletteChoice state (ShowPaletteChoice, FromHex, JSON) to restore the palette exactly. IColorPickerService gains ShowPaletteChoice.