Opens a modal palette with the Material colors for Blazor Application
$ dotnet add package BlazorColorPickerSometimes 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

[!WARNING] The implementation has been improved: version 4.0 uses a service declared via dependency injection
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
@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);
}
}
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).
[!NOTE] Color comparison is case-insensitive:
#ec407awill match#EC407Ain the palette.
- New feature:
FindClosestIfNotFoundparameter - when the selected color is not in the palette, automatically highlights the closest matching color- Color comparison is now case-insensitive (
#ec407amatches#EC407A)- Uses weighted Euclidean distance algorithm for perceptually accurate color matching
- 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
- Remove the internal use of IJSRuntime
- no need to declare the _content/BlazorColorPicker/colorpicker.js file