menu_bookDocumentation

Razor Panels: HTML/CSS UI with C# in s&box PanelComponent System

calendar_today May 20, 2026 schedule ~1 min read person PatrickJr verified 50

s&box Razor Panels use web-like HTML/CSS syntax with C# for UI creation. Panels are rendered natively (not via HTML renderer) — the syntax is a convenience layer.

PanelComponent (Root)

Every UI starts with a PanelComponent on a GameObject with ScreenPanel or WorldPanel:

CSHARP
@using Sandbox;
@using Sandbox.UI;
@inherits PanelComponent

<root>
    <div class="title">@MyStringValue</div>
</root>

@code
{
    [Property, TextArea] public string MyStringValue { get; set; } = "Hello World!";
    protected override int BuildHash() => System.HashCode.Combine( MyStringValue );
}

BuildHash Optimization

Panel contents only rebuild when BuildHash() returns a different value. Include all dynamic values. Force rebuild with StateHasChanged().

Child Panels

Child panels inherit from Panel (default for .razor files):

CSHARP
<MyChildPanel Health=@(30) Armor=@(75) />

Store references with @ref:

CSHARP
<MyChildPanel @ref="PanelReference" />

Two-Way Binds

Sync values between controls and variables:

CSHARP
<SliderEntry Value:bind=@IntValue></SliderEntry>

Key Differences

Was this helpful?