Typeset

Styles for content you don't write the markup of — rendered markdown, a chat answer — in a typeset container, and the same look for a heading, a paragraph or a quote on its own. One CSS file, started from shadcn's and tuned by variables; components inside keep their look, your classes win.

Data DisplayExperimental

Usage

Import the rules and your style's variables in your global stylesheet, after Tailwind: @import '@semantic-components/styles/typeset.css'; and @import '@semantic-components/styles/nova/typeset-variables.css'; (your style's). Then put your content in a typeset container.

import { Component, ViewEncapsulation } from '@angular/core';
/** Rendered content in a typeset container: plain elements, no directives. */@Component({  selector: 'app-typeset-usage-demo',  template: `    <article class="typeset max-w-prose">      <h2>The Joke Tax</h2>      <p>        Once upon a time, in a far-off land, there was a very lazy king who        spent all day lounging on his throne. One day, his advisors came to him        with a problem: the kingdom was running out of money.      </p>      <h3>The King's Plan</h3>      <p>        The king thought long and hard, and finally came up with        <a href="/docs/guides/typeset">a brilliant plan</a>: he would tax the        jokes in the kingdom. The tax was <strong>one gold coin</strong> per        joke, collected by <code>jokeTax()</code>.      </p>      <blockquote>        “After all,” he said, “everyone enjoys a good joke, so it’s only fair        that they should pay for the privilege.”      </blockquote>      <ul>        <li>1st level of puns: 5 gold coins</li>        <li>2nd level of jokes: 10 gold coins</li>        <li>3rd level of one-liners: 20 gold coins</li>      </ul>      <p>        As a result, people stopped telling jokes, and the kingdom fell into a        gloom.      </p>    </article>  `,  host: { class: 'flex w-full justify-center' },  encapsulation: ViewEncapsulation.None,})export class TypesetUsageDemo {}

Anatomy

A class on the container, for content you don't write; one directive, on any element, for text that stands on its own.

import { ScTypeset } from '@semantic-components/ui';
<!-- Content you don't write: plain elements --><article class="typeset">…</article>
<!-- Text on its own --><h2 scTypeset>…</h2><p scTypeset>… <code scTypeset>…</code> …</p>

Two ways

The same rules reach your text in two ways; pick by what the text is.

  • A container (class="typeset"): its plain elements are set — headings, paragraphs, lists, quotes, code, tables — with no directive on any. Components inside keep their look; not-typeset opts out the rest.
  • The directive (scTypeset): on one element with no container around it, set by its tag. What depends on its children isn't — the items of a list, code inside a heading.

Our recommendation: a container for reading text — content you don't write the markup of (markdown, a CMS, a chat answer) and long-form pages (an article, a blog post, a docs page): one class, and every element in it follows, lists and all. The directive for a few pieces of text placed among UI — a dashboard's title, a settings section's heading, a paragraph in a card — where a container would also set the layout's own lists and links. In a container, the directive changes nothing.

Either way, the variables tune it — on the container, on a style class of yours (.typeset-chat) or on :root for the whole app.

Leaving something out

In a container, every plain element is set. To keep one as it is — a link, a list, a block:

  • All of it:class="not-typeset" (or data-not-typeset, where your renderer can't add a class). The element and everything in it lose Typeset's rules — a link its underline, weight, hover and focus outline — and keep only your classes. On a wrapper, a whole region is left out.
  • Part of it: a utility on the element — class="no-underline font-normal". The rules are in @layer components with :where(), so your classes win; the rest of Typeset's look stays.
  • Components: anything with a data-slot keeps its own look with nothing to add — a button, a card, a link with a button's look (scLink variant="button"). A plain text link (scLink) has none: it's set as a link in the text, as it should be.

In rendered markdown you can rarely put a class on one element: a hook in your renderer adds it, or not-typeset goes on a wrapper around the region.

Not shadcn's Typeset

We started from shadcn's typeset.css and no longer follow it exactly. What's ours:

  • The variables are the style's, on :root (shadcn sets them on .typeset in its file): each style's own typeset-variables.css — optional — or your values.
  • An element on its own is set like one in a container: scTypeset marks it.
  • The style's corners: code blocks and images as its Code Block; inline code, keys and highlights as its Kbd (shadcn's highlight has a fixed 0.2em).
  • Headings h1 to h4 take the style's weight, tracking and case — --sc-typeset-heading-weight, --sc-typeset-heading-tracking, --sc-typeset-heading-case; shadcn's Typeset has none. 600, normal and none in every style but sera (uppercase, 0.05em: its titles).

Writing your own values? Set the three heading variables too: they have no fallback, and without --sc-typeset-heading-weight headings lose their bold.

Accessibility

  • Native elements only: headings keep the page's outline, lists and quotes are read as such. Keep heading levels in order.
  • A wide table in typeset-scroll scrolls in its own box: give the box tabindex="0", role="region" and a name, so the keyboard can reach and scroll it.

Examples

Whole page

Taxing Laughter

Story A tale of a king, his treasury, and the jokes of his people.

The Plan

The king's advisors had a problem: the treasury was empty. The king's answer was a tax on jokes.

  • Puns: 5 gold coins
  • One-liners: 20 gold coins

The People

The people stopped telling jokes, and the kingdom fell into a gloom — until a jester found a loophole.

import { Component, ViewEncapsulation } from '@angular/core';import { RouterLink } from '@angular/router';import { ScBadge, ScButton } from '@semantic-components/ui';
/** * A whole page in one container: its plain elements set, no directive on any; * components keep their look (a data-slot), and the bits of layout that aren't * reading text opt out (not-typeset). */@Component({

Headings

This is an H1 Heading

This is an H2 Heading

This is an H3 Heading

This is an H4 Heading

import { Component, ViewEncapsulation } from '@angular/core';import { ScTypeset } from '@semantic-components/ui';
@Component({  selector: 'app-headings-typeset-demo',  imports: [ScTypeset],  template: `    <div class="space-y-4">      <h1 scTypeset>This is an H1 Heading</h1>      <h2 scTypeset>This is an H2 Heading</h2>

Text

The People of the Kingdom

The king thought long and hard, and finally came up with a brilliant plan: he would tax the jokes in the kingdom.

“After all,” he said, “everyone enjoys a good joke, so it’s only fair that they should pay for the privilege.”

The people stopped telling jokes, and the kingdom fell into a gloom.

import { Component, ViewEncapsulation } from '@angular/core';import { ScTypeset } from '@semantic-components/ui';
/** Typeset's text without a container: each element marks itself. */@Component({  selector: 'app-text-typeset-demo',  imports: [ScTypeset],  template: `    <article class="max-w-prose">      <h2 scTypeset>The People of the Kingdom</h2>

Tuning

Docs

The defaults: roomy, for reading a page from top to bottom.

Each block keeps its distance from the last.

Chat

Smaller and tighter, for an answer in a narrow panel.

Each block closer to the last.

import { Component, ViewEncapsulation } from '@angular/core';
/** * Three variables tune it: the size, the line height and the space between * blocks. Here set on the container (a one-off); a style class of yours * (`.typeset-chat { --typeset-size: … }`) does the same for every use. */@Component({  selector: 'app-tuning-typeset-demo',  template: `

Components inside

A button in the text keeps its look; the paragraphs around it don't change it.

A note opted out with not-typeset: no paragraph spacing, your classes only.

Back in the content: the flow goes on.

import { Component, ViewEncapsulation } from '@angular/core';import { ScButton } from '@semantic-components/ui';
/** * Components in the content keep their own look (they have a data-slot); * `not-typeset` opts anything else out. */@Component({  selector: 'app-components-typeset-demo',  imports: [ScButton],

Wide table

The king's treasury, joke by joke:

King's TreasuryPeople's happinessJokes toldCoins collectedMonth
EmptyOverflowing1,2040January
ModestSatisfied8064,030February
FullEcstatic12240March
import { Component, ViewEncapsulation } from '@angular/core';
/** * A wide table in `typeset-scroll`: it scrolls across in its own box, the * page doesn't. Reached and scrolled by the keyboard: a named region. */@Component({  selector: 'app-table-typeset-demo',  template: `    <article class="typeset w-full max-w-prose">

RTL

ضريبة النكات

كان يا ما كان، في أرض بعيدة، ملك كسول جدًا يقضي يومه كله مستلقيًا على عرشه. وذات يوم جاءه مستشاروه بمشكلة: خزينة المملكة تكاد تفرغ.

«في النهاية، الجميع يحب النكتة الجيدة، فمن العدل أن يدفعوا ثمن هذا الامتياز».
  • المستوى الأول من التورية: خمس قطع ذهبية
  • المستوى الثاني من النكات: عشر قطع ذهبية
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';
/** Right to left: the text from the right, the quote's rule and the bullets on the right. */@Component({  selector: 'app-rtl-typeset-demo',  imports: [Dir],  template: `    <div dir="rtl" lang="ar">      <article class="typeset max-w-prose">

API reference

Directive

Each takes class; your classes win over its rules.

PartSelectorDescription
ScTypeset[scTypeset] An element on its own — a heading, a paragraph, a quote, inline code, a rule — set by its tag, as in a container: it marks itself data-typeset. For the container itself, class="typeset".

Variables

VariableDefaultDescription
--typeset-size1em The text's size; headings follow (in em). A container's text is 1.125× it on a phone.
--typeset-leading1.75 The line height of the text.
--typeset-flow1.25em The space between blocks; headings take more above them.
--typeset-font-bodyinherit The text's font.
--typeset-font-headingvar(--font-heading) The headings' font.
--typeset-font-monovar(--font-mono) Code's font.
--sc-typeset-radiusthe style's Code Block The corners of code blocks and images.
--sc-typeset-radius-inlinethe style's Kbd The corners of inline code, keys and highlights.
--sc-typeset-heading-weight600 The weight of headings h1 to h4.
--sc-typeset-heading-trackingnormal (sera: 0.05em, as its titles) The letter spacing of headings h1 to h4.
--sc-typeset-heading-casenone (sera: uppercase, as its titles) The case of headings h1 to h4 (text-transform).

Classes

ClassDescription
typeset The container: its plain elements set — headings, paragraphs, lists, quotes, code, tables. Components in it (a data-slot) keep their look.
not-typeset Opts an element and what it holds out of the container (data-not-typeset too).
typeset-scroll Wraps a wide table: it scrolls across in its own box.