s&box
RustCounter-Strike 2s&boxDeadlock
Wiki
Get s&box on Steam
Browse
OverviewGetting StartedCreating GamesEngine & ToolsDocumentationCommunity GamesResources
s&boxDocumentationUiStyling Panels
SOURCE 2 · C#
Build and play games with s&box.

Facepunch's game engine and creation platform — make games in C#, or jump straight into community games.

Get s&box on Steam

s&box Wiki

  • Overview
  • Getting Started
  • Creating Games
  • Engine & Tools
  • Documentation
  • Community Games
  • Resources

Tools & Community

  • Getting Started
  • Creating Games
  • Engine & Tools
  • Resources

Platforms

  • RustBattle
  • CSBattle
  • Rust Game Wiki
  • CS2 Skins Wiki
  • Deadlock Wiki

About

  • Official Site
  • Developer Wiki
  • GitHub
  • Get on Steam
NOT AFFILIATED WITH FACEPUNCH STUDIOS · © 2026 s&box Wiki (community)
Docs/UI
UI

Styling Panels

:::info It is common to have a file system like this:

  • Health.razor
  • Health.razor.scss

If you do this, the scss file is automatically included by your Health.razor panel.

:::

If you want to specify a different location for the loaded Stylesheet, you can add this to your Panel class:

[StyleSheet("main.scss")]

You can also import a stylesheet from within another stylesheet like so:

@import "buttons.scss";

There are a few ways to style your Panels without a stylesheet. It's really recommended that you use a stylesheet to keep things organized, but there are also valid reasons to use the following methods.

Styling the Element

You can directly style any element just like you can in HTML, but can inject C# when necessary:

<label style="color: red">DANGER!</label>
<div class="progress-bar">
  <div class="fill" style="width: @(Progress * 100f)%"></div>
</div>

Style Block

Before or after your <root> element, you can add a <style> block that is read just like a Stylesheet:

<style>
  MyPanel {
    width: 100%;
    height: 100%;
  }
  .hp { color: red; }
  .armor { color: blue; }
</style>

Styling in Code

You can access a Panel's Style directly and modify the values however you'd like via Tick() or OnUpdate():

myPanel.Style.Width = Length.Percent(Progress * 100f);

Source: Facepunch/sbox-docs (CC-BY-4.0) · updated 2024-09-25. Read it rendered on the official docs.

More in UI

HudPainter
Localization
Razor Components
Razor Panels
Style Properties
UI
UI Interactions
VirtualGrid
← All documentation

Community wiki — not affiliated with Facepunch Studios. For the latest and most authoritative information, see the official developer wiki.