AccessibleColors 1.0.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package AccessibleColors --version 1.0.5                
NuGet\Install-Package AccessibleColors -Version 1.0.5                
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="AccessibleColors" Version="1.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AccessibleColors --version 1.0.5                
#r "nuget: AccessibleColors, 1.0.5"                
#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.
// Install AccessibleColors as a Cake Addin
#addin nuget:?package=AccessibleColors&version=1.0.5

// Install AccessibleColors as a Cake Tool
#tool nuget:?package=AccessibleColors&version=1.0.5                

AccessibleColors

NuGet NuGet Downloads Build License

AccessibleColors is a lightweight C# library that provides O(1) methods to compute WCAG-compliant contrast colors. Given a background color, it instantly returns a suitable foreground color that meets or exceeds the standard WCAG 2.2 contrast ratio of 4.5:1 for normal text.

Key Features

  • WCAG Compliance: Ensures at least a 4.5:1 contrast ratio by default, helping you create accessible user interfaces.
  • O(1) Performance: Uses a precomputed lookup table (LUT) for sRGB-to-linear conversions, allowing instant calculations.
  • No External Dependencies: Relies only on System.Drawing types for colors, making integration straightforward.
  • Simple API: A single GetContrastColor extension method on Color and an IsCompliant method let you easily ensure accessibility.

Getting Started

  1. Install: Add the library as a reference to your project. Since it�s published on NuGet:

    dotnet add package AccessibleColors
    
  2. Use:

    using System.Drawing;
    using AccessibleColors;
    
    // Suppose you have a background color:
    var background = Color.FromArgb(255, 0, 0); // Bright red
    
    // Get a compliant foreground color:
    Color foreground = background.GetContrastColor();
    
    // Check compliance explicitly if needed:
    bool isAccessible = WcagContrastColor.IsCompliant(background, foreground);
    
  3. Integrate Into Your UI:
    Use GetContrastColor anywhere you need to select text or icon colors based on a dynamically changing background�custom theming, responsive UI adjustments, or design tools.

Example

using System.Drawing;
using AccessibleColors;

var bg = Color.FromArgb(128,128,128); // Mid-gray background
var fg = bg.GetContrastColor();

Console.WriteLine($"Foreground: {fg}");

// Verify compliance
bool compliant = WcagContrastColor.IsCompliant(bg, fg);
Console.WriteLine($"Is compliant: {compliant}");

Why This Matters

Accessibility is not just a nice-to-have; it's an essential part of building inclusive applications. Ensuring proper contrast ratios improves readability for everyone, including users with visual impairments. With AccessibleColors, you can enforce these standards automatically and efficiently.

Contributing

Contributions are welcome! Feel free to open issues, suggest features, or submit pull requests.

License

This project is licensed under the MIT License. See the LICENSE file for 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.10 85 12/8/2024
1.0.9 80 12/8/2024
1.0.8 85 12/8/2024
1.0.7 91 12/8/2024
1.0.6 77 12/8/2024
1.0.5 84 12/7/2024
1.0.4 82 12/7/2024