---
title: "Getting started with OneUI"
url: https://recursiveai.org/oneui/docs/getting-started/
description: "Write a markup component, mount it on the in-memory reference document, click it and see what changed. Then build a small screen with the C# builder and…"
version: "1.0.0"
---

# Getting started with OneUI

Write a markup component, mount it on the in-memory reference document, click it and see what changed. Then build a small screen with the C# builder and print the display list it paints. This guide was run on RecursiveAI.OneUI 1.0.0 from NuGet, in a .NET 10 console app on Linux, with no window: the window and browser backends are in [OneApp](https://recursiveai.org/oneapp/).

## Install

You need the .NET 10 SDK. Make a console project and add the package:

```shell
dotnet new console -n Hello
cd Hello
dotnet add package RecursiveAI.OneUI --version 1.0.0
```

The package carries the markup compiler. Every `.html` file in the project, and the `.css` file next to it, is a component template.

## A markup component

A component is a template, an optional stylesheet and a partial class with the same name. Add three files.

`Counter.html`:

```html
<button class="btn" on:click="Increment">Clicked {Count} times</button>
```

`Counter.css`:

```css
.btn { padding: 4px 12px; }
```

`Counter.cs`:

```csharp
using OneUI.Components;

public partial class Counter
{
    [State]
    public partial int Count { get; set; }

    private void Increment() => Count++;
}
```

The compiler adds the base class, the state property and the code that creates and updates the button. A misspelled name in the template, or a CSS property the renderer can’t draw, is a build error with an `OUI` id (see [Diagnostics](https://recursiveai.org/oneui/docs/diagnostics/)).

## Run it, then build a screen in C#

Replace `Program.cs` with:

```csharp
using OneUI;
using OneUI.Components;
using OneUI.Components.Reference;
using OneUI.Kit;

// 1. A markup component, mounted on the in-memory reference document.
var dom = new ReferenceDocument();
var ctx = new UiContext(dom);
dom.Context = ctx;
ctx.Mount(new Counter());

Console.WriteLine(dom.ToHtml());
dom.Click(".btn");
dom.Click(".btn");
Console.WriteLine(dom.ToHtml());

// The last click's change set: one text node rewritten.
foreach (Change c in dom.Commits[^1].Changes)
    Console.WriteLine($"{c.Kind} node {c.Node}: \"{c.Value}\"");

// 2. The C# builder: build, lay out and paint a tree.
var tree = new UiTree();
tree.SetViewport(640, 360, 1);
var kit = new KitHost(tree);
tree.Root.Add(kit.AttachTo(Ui.Column(
    Ui.Label("Hello"),
    UiKit.Button("Count", () => Console.WriteLine("clicked"), "count"))
    .Padding(16).Gap(8)));
DisplayList list = tree.Frame();
Console.Write(list.ToText());
tree.Invoke(tree.Find("count")!);
```

Run it:

```shell
dotnet run
```

```text
<button class="btn" data-oui-fc0f33c3>Clicked 0 times</button>
<button class="btn" data-oui-fc0f33c3>Clicked 2 times</button>
SetText node 3: "Clicked 2 times"
Text 'Hello' #e8eaf0 size=14 [16,16 Hello]
Rect (16,40.8 72x32) #2b303a radii=4,4,4,4
Border (16,40.8 72x32) #3a4050 widths=1,1,1,1 radii=4,4,4,4
Text 'Count' #e8eaf0 size=14 [31,48.4 Count]
clicked
```

What happened:

- `ReferenceDocument` applies the component’s change sets to an in-memory DOM. `Click`, `Input` and `Press` drive events the way a browser does, and `ToHtml` prints the result, so the same calls work in a unit test.
- The `data-oui-…` attribute scopes `Counter.css` to the component’s own elements.
- After a click, the commit holds one change: the text node that reads `Count` is rewritten and nothing else is.
- `UiTree.Frame()` styles and lays out the tree and returns the display list a host paints: text runs, rectangles and borders with their boxes. The kit button comes with the theme’s colors.
- `tree.Invoke` clicks the button as a pointer or the confirm button would, without hit testing, and its callback prints `clicked`.

## Next

- [Markup components](https://recursiveai.org/oneui/docs/markup/): bindings, events, two-way binding, conditionals, keyed lists, child components, slots, focus and SVG.
- [Change sets](https://recursiveai.org/oneui/docs/change-sets/): the protocol between components and a document, and what the reference document simulates.
- [CSS support](https://recursiveai.org/oneui/docs/css-support/): what a component stylesheet accepts.
