---
title: "Get the CSS cursor under the mouse in C#"
url: https://recursiveai.org/onerender/cookbook/read-css-cursor-at-pointer/
description: "Use OneRender to get the CSS cursor at a mouse position in rendered HTML. Read the cursor shape your C# app should display without running a browser."
version: "1.6.1"
---

# Get the CSS cursor under the mouse in C#

**OneRender** is a free, open-source HTML and CSS rendering library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneRender.Image) · [GitHub](https://github.com/recursive-ai-oss/onerender-csharp) · [Docs](https://recursiveai.org/onerender/docs/) · [Download example (.zip)](https://recursiveai.org/onerender/cookbook/read-css-cursor-at-pointer/read-css-cursor-at-pointer.zip)

`GetCursor` reads the CSS cursor for HTML that OneRender renders, not the operating system’s mouse cursor.

```shell
dotnet add package RecursiveAI.OneRender.Image
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OneRender;
using OneRender.Image;
using OneRender.Interaction;

const string html = """
    <button style="cursor:pointer">
      Details
    </button>
    """;
var fonts = FontProviders.CreateDefault();
var page = InteractivePage.Create(
    html, new HtmlPageOptions(fonts));
var cursor = page.GetCursor(12, 12);
Console.WriteLine(cursor.Kind);
```

Paste the code above into Program.cs of a new `dotnet new console` project and `dotnet run`, or unzip [the example](https://recursiveai.org/onerender/cookbook/read-css-cursor-at-pointer/read-css-cursor-at-pointer.zip) and `dotnet run`.

At `(12, 12)`, the pointer is over the button. The program prints:

```text
PointingHand
```

OneRender returns a cursor description. Your app still has to select the matching system cursor or draw its own.

## Variations

**Handle a point outside the viewport.** In the sample, add this line to print `Default`:

```csharp
Console.WriteLine(page.GetCursor(-1, 12).Kind);
```

**Read a custom cursor hint.** Replace the button’s style with this declaration. The sample then prints `Crosshair`. The file name is only a hint; you don’t need a `pen.png` file to query it.

```css
cursor: url('pen.png') 2 3, crosshair;
```

## Related recipes

- [Hit-test rendered HTML and dispatch events](https://recursiveai.org/onerender/cookbook/hit-testing-events/)
- [Click a rendered HTML element in C#](https://recursiveai.org/onerender/cookbook/activate-html-control-with-programmatic-click/)

## The short answer

Call `InteractivePage.GetCursor(x, y)` with the mouse position relative to the HTML viewport and use `CursorInfo.Kind` to choose the cursor in your host UI. This reads the cursor at a point, not the mouse’s position on the screen. For HTML with `cursor: pointer`, the C# result is `CursorKind.PointingHand`.

## How do I use the CSS cursor property in an HTML UI?

Set `cursor` on the element that should suggest the action. Pick `pointer` for a pointing hand or `crosshair` when the user needs to aim precisely. MDN’s [CSS cursor reference](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/cursor) lists the keywords and their meanings. The declaration changes the pointer hint, not what happens on click. A noninteractive box doesn’t become a button because it has `cursor: pointer`.

OneRender looks up the topmost element hit. CSS can pass the value down from a parent, so in a hand-shaped region you don’t need to set the property on every nested label. When the effective value is `auto`, `GetCursor` resolves it to `Text` over text or editable text controls and `Default` elsewhere. A button without a cursor rule can therefore return `Default` even when it’s clickable.

## How do I turn mouse coordinates into a CSS cursor?

Use the position inside the rendered viewport, not the position inside the whole window or on the monitor. If your app draws the HTML in a panel offset from the window origin, subtract that offset first. If it scales the rendered area when displaying it, convert the pointer to the layout’s coordinate scale too. Don’t add the document’s scroll offset: `GetCursor` expects a point in the viewport you’re looking at.

If your host updates `:hover` through pointer input, read the cursor after it handles the move, so the result reflects any hover-dependent rule. See [the pointer shape in the host guide](https://recursiveai.org/onerender/docs/game-hosts/#the-pointer-shape). Also query again when a layout or style change moves a different element under a stationary pointer; a saved cursor describes the hit at the time you asked.

## How do I use a custom cursor image with CSS?

Put the image URL first, optionally give its hotspot (the point inside the image that lines up with the mouse), and end with a fallback keyword. OneRender exposes the first image URL and hotspot through `CursorInfo`; it doesn’t fetch the image or try a list of alternate images. In the variation, the host can use the reported `pen.png` and hotspot `(2, 3)`, or use the reported `Crosshair` kind when it can’t display the image. Relative URLs in linked stylesheets resolve against the stylesheet’s address; the inline example reports `pen.png` as written.
