On this page
@addTagHelper *, Webority.Ui.RazorLanguages
Pick the language the code is written in, so its tokens take the right colours.
One block per language
Plain text, shown as written.
Indentation is kept.{
"event": "invoice.paid",
"id": "evt_01HZX",
"amountPaise": 1250000,
"paid": true,
"note": null
}async function load(id) {
const res = await fetch(`/api/invoices/${id}`);
if (!res.ok) throw new Error("Not found");
return res.json(); // 200
}public sealed record Invoice(string Number, long AmountPaise)
{
public bool IsLarge => AmountPaise > 1_000_000;
}SELECT TOP 10 Number, AmountPaise
FROM Invoices
WHERE Status = 'Paid' AND CreatedDateTimeUtc >= @since
ORDER BY AmountPaise DESC; -- biggest first# Deploy the staging build
export ENV=staging
curl -X POST "$API/deploy/staging/build" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" --data '{"env":"staging","notify":["ops@example.com"],"rollbackOnFailure":true}'POST /api/webhooks HTTP/1.1
Host: api.example.com
Content-Type: application/json
{ "url": "https://example.com/hook", "active": true }<!-- A card -->
<div class="card" id="plan">
<a href="/pricing" disabled>Pricing & plans</a>
</div><app-button tone="primary">Save</app-button>.card:hover {
color: #0a7;
margin: 0 12px;
z-index: 200 !important;
}Line numbers
Number the lines when a reader must point at one, such as a line of a query that failed.
Numbered paid invoices query
SELECT TOP 10 Number, AmountPaise
FROM Invoices
WHERE Status = 'Paid' AND CreatedDateTimeUtc >= @since
ORDER BY AmountPaise DESC; -- biggest firstWrapped lines
Wrap a long command or payload when scrolling sideways would hide the part a reader needs to copy.
A long shell command
# Deploy the staging build
export ENV=staging
curl -X POST "$API/deploy/staging/build" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" --data '{"env":"staging","notify":["ops@example.com"],"rollbackOnFailure":true}'Every option
Every value of every prop, one cell each.
code: any string
code="corepack pnpm add @webority/ui-react"
corepack pnpm add @webority/ui-reactlanguage: text, json, js, cs, sql, bash, http, html, razor or css
language="text" (default)
Plain text, shown as written.
Indentation is kept.language="json"
{
"event": "invoice.paid",
"id": "evt_01HZX",
"amountPaise": 1250000,
"paid": true,
"note": null
}language="js"
async function load(id) {
const res = await fetch(`/api/invoices/${id}`);
if (!res.ok) throw new Error("Not found");
return res.json(); // 200
}language="cs"
public sealed record Invoice(string Number, long AmountPaise)
{
public bool IsLarge => AmountPaise > 1_000_000;
}language="sql"
SELECT TOP 10 Number, AmountPaise
FROM Invoices
WHERE Status = 'Paid' AND CreatedDateTimeUtc >= @since
ORDER BY AmountPaise DESC; -- biggest firstlanguage="bash"
# Deploy the staging build
export ENV=staging
curl -X POST "$API/deploy/staging/build" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" --data '{"env":"staging","notify":["ops@example.com"],"rollbackOnFailure":true}'language="http"
POST /api/webhooks HTTP/1.1
Host: api.example.com
Content-Type: application/json
{ "url": "https://example.com/hook", "active": true }language="html"
<!-- A card -->
<div class="card" id="plan">
<a href="/pricing" disabled>Pricing & plans</a>
</div>language="razor"
<app-button tone="primary">Save</app-button>language="css"
.card:hover {
color: #0a7;
margin: 0 12px;
z-index: 200 !important;
}lineNumbers: true or false
line-numbers="true"
SELECT TOP 10 Number, AmountPaise
FROM Invoices
WHERE Status = 'Paid' AND CreatedDateTimeUtc >= @since
ORDER BY AmountPaise DESC; -- biggest firstline-numbers="false" (default)
SELECT TOP 10 Number, AmountPaise
FROM Invoices
WHERE Status = 'Paid' AND CreatedDateTimeUtc >= @since
ORDER BY AmountPaise DESC; -- biggest firstwrap: true or false
wrap="true"
# Deploy the staging build
export ENV=staging
curl -X POST "$API/deploy/staging/build" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" --data '{"env":"staging","notify":["ops@example.com"],"rollbackOnFailure":true}'wrap="false" (default)
# Deploy the staging build
export ENV=staging
curl -X POST "$API/deploy/staging/build" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" --data '{"env":"staging","notify":["ops@example.com"],"rollbackOnFailure":true}'label: any string
label="webhook.json"
{
"event": "invoice.paid",
"id": "evt_01HZX",
"amountPaise": 1250000,
"paid": true,
"note": null
}label left out, the header names the language
{
"event": "invoice.paid",
"id": "evt_01HZX",
"amountPaise": 1250000,
"paid": true,
"note": null
}copyLabel: any string
copy-label="Copy" (default)
{
"event": "invoice.paid",
"id": "evt_01HZX",
"amountPaise": 1250000,
"paid": true,
"note": null
}copy-label="Copy query"
{
"event": "invoice.paid",
"id": "evt_01HZX",
"amountPaise": 1250000,
"paid": true,
"note": null
}copiedLabel: any string
copied-label="Copied" (default, shown after a copy)
{
"event": "invoice.paid",
"id": "evt_01HZX",
"amountPaise": 1250000,
"paid": true,
"note": null
}copied-label="Done" (shown after a copy)
{
"event": "invoice.paid",
"id": "evt_01HZX",
"amountPaise": 1250000,
"paid": true,
"note": null
}className: any string
class="extra-class": extra class on the root, no look of its own (React: className)
{
"event": "invoice.paid",
"id": "evt_01HZX",
"amountPaise": 1250000,
"paid": true,
"note": null
}Guidance
What to do, and what to avoid.
Use it when
- A code sample, request, response or payload people read and copy.
- An API key or command to paste.
Reach for something else when
- A short value in a sentence. → the code element
- Copying a single value with no code around it. → AppCopyButton
- Editing code. → a code editor
Reference
Try every prop, read the full list, and check keyboard and screen reader behaviour.
7 props. The 5 most used come first.
Used on most screens 5 props
| Prop | Type | Default | Description |
|---|---|---|---|
| codedefault tag content | string | tag content | The source text. A single trailing newline is dropped. |
| languagedefault text | text | json | js | cs | sql | bash | http | html | razor | css | text | What to colour; text shows it as written. |
| line-numbersdefault false | bool | false | Number the lines. The numbers are not copied or selected. |
| wrapdefault false | bool | false | Wrap long lines instead of scrolling sideways. |
| labeldefault - | string | - | The header title, such as webhook.json, and the code region's accessible name. Without it the header names the language. |
Less common 2 props
| Prop | Type | Default | Description |
|---|---|---|---|
| copy-labeldefault Copy | string | Copy | The copy button's label. It reads Copy when left out. |
| copied-labeldefault Copied | string | Copied | The copy button's label for two seconds after a copy. It reads Copied when left out. |
Screen reader
3 notes- The label is the code region's accessible name; without it the header names the language.
- The copy button reads copyLabel, and for two seconds after a copy it reads copiedLabel.
- Line numbers are not copied or selected.