AngleSharp.Css 1.0.0-beta.216

logo

AngleSharp.Css

CI GitHub Tag NuGet Count Issues Open Gitter Chat StackOverflow Questions CLA Assistant

AngleSharp.Css extends the core AngleSharp library with some more powerful CSS capabilities. This repository is the home of the source for the AngleSharp.Css NuGet package.

Basic Configuration

If you just want a configuration that works (as close as possible to real browsers) you should use the following code:

var config = Configuration.Default
    .WithCss(); // from AngleSharp.Css

This will register a parser for CSS related content. The CSS parsing options and more could be set with parameters of the WithCss method. Alternatively, all the (desired) parts may be registered individually as well. That mostly boils down to three elementary parts:

  • A CSS parser (implementing the ICssParser interface, e.g., CssParser)
  • A factory for creating CSS declarations (IDeclarationFactory)
  • The styling service that can handle CSS documents, see CssStylingService

For an interactive DOM (i.e., to handle style attribute changes in the HTML document) an observer needs to be registered as well.

Furthermore, for some CSSOM features (e.g., media queries) a render device is required.

var config = Configuration.Default
    .WithCss()
    .WithRenderDevice(new DefaultRenderDevice
    {
        DeviceHeight = 768,
        DeviceWidth = 1024,
    });

If no specific IRenderDevice (e.g., via creating an DefaultRenderDevice object) instance is created a default implementation will be set.

Going a bit further it is possible to Render the current document. This render tree information can then be used to retrieve or other information, e.g.,

var tree = document.DefaultView.Render();
var node = tree.Find(document.QuerySelector("div"));
await node.DownloadResources();

The previous snippet renders the current document. Afterwards it retrieves a particular render tree node, which is related to the first found div. Then all (CSS introduced) resources are downloaded for the node, if visible.

Advantages of AngleSharp.Css

The core library already contains the CSS selector parser and the most basic classes and interfaces for dealing with the CSSOM. AngleSharp.Css brings the following advantages and use cases to life:

  • Correct identification of edge cases
  • A live CSSOM model, i.e., callbacks and everything
  • Computing the styling of certain elements
  • Cascades of stylesheets
  • Validation (and property-based exposure) of CSS declarations
  • Responsive design considerations
  • Full access to the value with different converters

The main idea behind AngleSharp.Css is to expose the CSSOM as it would be in the browser (and potentially beyond, i.e., useful for being used by editors). Originally, most of the code found here was embedded in the AngleSharp.Core library, however, due to the overhead for HTML use cases it was decided to transfer the code into its own repository.

Features

  • Feature validators (e.g., for @supports)
  • Document functions (e.g., for domain)
  • Pseudo elements (e.g., ::before)
  • Declarations (e.g., display) incl. knowledge of their values
  • Dynamic DOM coupling (i.e., to react to style attribute changes)
  • CSS custom properties (also known as CSS variables) with extensibility
  • Media queries and all other commonly implemented rules
  • Calculated values (i.e., calc(20px + 50%))
  • Window-based declaration calculations, see window.GetComputedStyle

Benchmarks

The AngleSharp.Performance.Css project uses BenchmarkDotNet to compare CSS parsing performance across libraries. Run the benchmarks in Release mode:

dotnet run --project src/AngleSharp.Performance.Css/AngleSharp.Performance.Css.csproj -c Release --framework net10.0

To run a quick smoke test instead of a full benchmark:

dotnet run --project src/AngleSharp.Performance.Css/AngleSharp.Performance.Css.csproj -c Release --framework net10.0 -- --job short

Participating

Participation in the project is highly welcome. For this project the same rules as for the AngleSharp core project may be applied.

If you have any question, concern, or spot an issue then please report it before opening a pull request. An initial discussion is appreciated regardless of the nature of the problem.

Live discussions can take place in our Gitter chat, which supports using GitHub accounts.

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community.

For more information see the .NET Foundation Code of Conduct.

.NET Foundation

This project is supported by the .NET Foundation.

License

AngleSharp.Css is released using the MIT license. For more information see the license file.

Showing the top 20 packages that depend on AngleSharp.Css.

Packages Downloads
HtmlSanitizer
Cleans HTML from constructs that can be used for cross site scripting (XSS)
26
HtmlSanitizer
Cleans HTML from constructs that can be used for cross-site scripting (XSS)
26
HtmlSanitizer
Cleans HTML from constructs that can be used for cross-site scripting (XSS)
25
HtmlSanitizer
Cleans HTML from constructs that can be used for cross-site scripting (XSS)
24
HtmlSanitizer
Cleans HTML from constructs that can be used for cross-site scripting (XSS)
23
HtmlSanitizer
Cleans HTML from constructs that can be used for cross-site scripting (XSS)
22
HtmlSanitizer
Cleans HTML from constructs that can be used for cross site scripting (XSS)
22
HtmlSanitizer
Cleans HTML from constructs that can be used for cross site scripting (XSS)
21
HtmlSanitizer
Cleans HTML from constructs that can be used for cross-site scripting (XSS)
21

Any 0.0

Version Downloads Last updated
1.0.0-beta.216 1 05/14/2026
1.0.0-beta.213 15 04/01/2026
1.0.0-beta.211 21 03/29/2026
1.0.0-beta.209 17 03/29/2026
1.0.0-beta.204 19 03/29/2026
1.0.0-beta.202 17 03/29/2026
1.0.0-beta.199 18 03/29/2026
1.0.0-beta.197 18 03/29/2026
1.0.0-beta.195 18 03/29/2026
1.0.0-beta.189 18 03/29/2026
1.0.0-beta.186 20 03/29/2026
1.0.0-beta.184 16 03/29/2026
1.0.0-beta.178 22 03/28/2026
1.0.0-beta.176 17 03/29/2026
1.0.0-beta.167 28 01/17/2026
1.0.0-beta.164 20 12/10/2025
1.0.0-beta.159 17 12/10/2025
1.0.0-beta.157 18 12/13/2025
1.0.0-beta.154 26 12/09/2025
1.0.0-beta.151 16 12/13/2025
1.0.0-beta.149 23 12/12/2025
1.0.0-beta.147 19 12/09/2025
1.0.0-beta.144 18 12/13/2025
1.0.0-beta.139 21 12/10/2025
1.0.0-beta.137 22 12/13/2025
1.0.0-beta.130 18 01/01/2026
1.0.0-beta.127 16 12/09/2025
1.0.0-beta.122 18 12/22/2025
1.0.0-alpha-99 17 12/10/2025
1.0.0-alpha-98 25 12/20/2025
1.0.0-alpha-97 16 12/12/2025
1.0.0-alpha-117 28 12/13/2025
1.0.0-alpha-113 17 12/09/2025
1.0.0-alpha-111 21 12/15/2025
1.0.0-alpha-109 18 01/09/2026
1.0.0-alpha-108 17 12/10/2025
1.0.0-alpha-107 19 12/09/2025
1.0.0-alpha-106 15 12/15/2025
1.0.0-alpha-104 21 12/16/2025
1.0.0-alpha-103 16 12/10/2025
1.0.0-alpha-102 16 12/18/2025
1.0.0-alpha-101 17 12/16/2025
1.0.0-alpha-100 18 12/15/2025
0.17.0 25 12/15/2025
0.17.0-alpha-87 19 12/09/2025
0.17.0-alpha-86 30 12/10/2025
0.17.0-alpha-80 20 12/13/2025
0.17.0-alpha-78 20 12/21/2025
0.17.0-alpha-77 16 12/09/2025
0.17.0-alpha-76 14 12/24/2025
0.17.0-alpha-75 20 12/09/2025
0.16.4 18 12/11/2025
0.16.4-alpha-72 17 12/14/2025
0.16.4-alpha-68 16 01/01/2026
0.16.3 19 12/09/2025
0.16.3-alpha-65 18 12/09/2025
0.16.2 18 01/02/2026
0.16.2-alpha-62 16 12/09/2025
0.16.2-alpha-61 19 12/24/2025
0.16.2-alpha-60 14 01/01/2026
0.16.2-alpha-42 19 12/09/2025
0.16.2-alpha-35 17 12/14/2025
0.16.2-alpha-30 13 01/17/2026
0.16.2-alpha-29 22 12/11/2025
0.16.2-alpha-28 16 01/01/2026
0.16.1 19 12/12/2025
0.16.1-alpha-27 19 12/09/2025
0.16.1-alpha-24 15 12/21/2025
0.16.0 13 01/09/2026
0.16.0-alpha-23 16 12/12/2025
0.16.0-alpha-19 24 12/11/2025
0.15.1 18 01/17/2026
0.15.1-alpha-13 18 01/01/2026
0.15.1-alpha-11 18 12/15/2025
0.15.0 15 12/19/2025
0.15.0-alpha-7 18 12/15/2025
0.14.3-alpha-5 15 12/12/2025
0.14.3-alpha-4 15 12/20/2025
0.14.3-alpha-166 19 12/15/2025
0.14.3-alpha-165 24 12/10/2025
0.14.2 15 12/24/2025
0.14.2-alpha-163 16 12/09/2025
0.14.2-alpha-162 19 12/20/2025
0.14.1 18 01/01/2026
0.14.1-alpha-161 25 12/15/2025
0.14.0 20 12/13/2025
0.14.0-alpha-160 23 12/14/2025
0.14.0-alpha-154 19 01/09/2026
0.14.0-alpha-152 19 01/01/2026
0.14.0-alpha-149 22 01/01/2026
0.14.0-alpha-147 18 12/14/2025
0.14.0-alpha-145 21 12/22/2025
0.14.0-alpha-143 20 12/09/2025
0.14.0-alpha-139 18 12/15/2025
0.14.0-alpha-138 19 01/09/2026
0.13.0 15 12/24/2025
0.13.0-alpha-135 15 01/09/2026
0.13.0-alpha-131 23 12/10/2025
0.13.0-alpha-123 17 12/09/2025
0.13.0-alpha-121 15 01/23/2026
0.13.0-alpha-119 16 12/22/2025
0.13.0-alpha-117 19 01/01/2026
0.13.0-alpha-116 19 12/19/2025
0.13.0-alpha-115 16 12/22/2025
0.13.0-alpha-114 18 12/14/2025
0.13.0-alpha-113 20 12/09/2025
0.12.1 16 12/30/2025
0.12.0 23 12/09/2025
0.10.0 21 12/09/2025