Css2Avalonia 1.0.0

dotnet add package Css2Avalonia --version 1.0.0
                    
NuGet\Install-Package Css2Avalonia -Version 1.0.0
                    
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="Css2Avalonia" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Css2Avalonia" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Css2Avalonia" />
                    
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 Css2Avalonia --version 1.0.0
                    
#r "nuget: Css2Avalonia, 1.0.0"
                    
#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 Css2Avalonia@1.0.0
                    
#: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=Css2Avalonia&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Css2Avalonia&version=1.0.0
                    
Install as a Cake Tool

Css2Avalonia

Renders HTML-like node trees with CSS styling to native Avalonia controls. No WebView required.

What it does

Takes a tree of HtmlNode objects (elements with tags, inline styles, and children) and produces Avalonia Control instances. Supports CSS property parsing, stylesheet matching, and variable resolution.

Supported HTML elements

div, p, span, br, a, b, i, em, strong, small, sub, sup, ul, ol, li, table, tr, td, th, thead, tbody, tfoot, ruby, rt, rp, img, details, summary

Supported CSS properties

  • Display: none, block, flex, inline-flex, inline-block
  • Colors: hex, named colors via Color.TryParse
  • Font: font-size (px, em, rem, pt, %), font-weight, font-style, text-decoration
  • Spacing: margin, padding (all sides + shorthand)
  • Borders: border, border-width, border-color, border-style, border-radius, per-side borders
  • Layout: flex-direction, flex-wrap, text-align, vertical-align
  • Sizing: width, height, max-width, max-height, min-width
  • Text: letter-spacing, line-height, white-space, text-indent
  • Other: overflow, CSS variables with var() fallbacks, logical properties (margin-block, padding-inline, etc.)

Usage

Build the node tree

using Css2Avalonia.Parser;

var nodes = new List<HtmlNode>
{
    new HtmlElementNode
    {
        Tag = "div",
        Style = new() { ["color"] = "#ff0000", ["font-weight"] = "bold" },
        Children =
        [
            new HtmlTextNode { Text = "Hello " },
            new HtmlElementNode
            {
                Tag = "span",
                Style = new() { ["font-style"] = "italic" },
                Children = [new HtmlTextNode { Text = "world" }]
            }
        ]
    }
};

Render to Avalonia controls

using Css2Avalonia.Controls;

Control control = StructuredContentRenderer.Render(nodes);
myPanel.Children.Add(control);

With a CSS stylesheet

using Css2Avalonia.Css;

var stylesheet = new CssStylesheet("span[data-sc-headword] { font-weight: bold; font-size: 1.3em; }");
Control control = StructuredContentRenderer.Render(nodes, stylesheet);

CSS utilities standalone

using Css2Avalonia.Css;

IBrush? brush = CssResolver.ParseColor("#ff0000");
double? size = CssResolver.ParseFontSize("1.5em");
Thickness? margin = CssResolver.ParseThickness("4px 8px");
string resolved = CssResolver.ResolveVariables("var(--color, red)"); // "red"

API reference

Class Purpose
StructuredContentRenderer Render(List<HtmlNode>, CssStylesheet?) → Avalonia Control
CssResolver Static CSS value parsers (color, font-size, thickness, etc.)
CssStylesheet Parses CSS text and resolves matching rules for elements
CssStylesheetCache In-memory cache for parsed stylesheets
HtmlNode Abstract base node
HtmlTextNode Text content node (Text property)
HtmlElementNode Element node with Tag, Children, Style, Data, and HTML attributes

Requirements

  • .NET 9.0+
  • Avalonia 11.x
Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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

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.0 78 3/29/2026