Skip to content
// EFFECT DAYS 2026

HtmlHead unstable

The HTML vocabulary's head: meta and link tags, JSON-LD blocks, and the lang, dir, class and data-* attributes of <html> and <body>, on top of the host-neutral Head.title and Head.titleTemplate.

A component on Html returns these entries from its head option, next to Head's. Importing this module registers merge as Html's fold and installs the document head sync, so the runtime folds the placed tree into one HtmlHead, which the browser host diffs against the document and the server prints. An app that never imports HtmlHead folds and syncs only the title and doesn't carry this module.

Merge rules

  • A node's value is its own entries followed by its children's values, so a descendant overrides its ancestors. Children are taken in the order of their paths, never in document order. The node's reduce entries then map the value, in written order.
  • The title, lang, dir and <link rel="canonical"> each have one entry. A meta tag is identified by its key, else its name or property; a link by its key, else rel plus href; a JSON-LD block by its key, else its canonical form. data-* attributes have one entry per name.
  • Siblings that set one of these to the same value pass it up once. When they set different values it's left unset, and reported as a Head.Conflict unless a reduce above them sets it.
  • class tokens are unioned in the order they were first contributed.
  • Titles follow Head's template rule.

Example A layout template and a page

import { Head } from "effect/ui"
import { HtmlHead } from "effect/ui/html"
const head = HtmlHead.merge({
entries: [Head.titleTemplate((title) => `${title} ยท App`), HtmlHead.lang("en")],
children: [{
entries: [Head.title("Ada"), HtmlHead.meta({ name: "description", content: "Ada's page" })],
children: []
}]
})
head.title // => "Ada ยท App"
head.html.lang // => "en"
head.meta.map((meta) => meta.content) // => ["Ada's page"]
32 exports Since v4.2.0 Source

Combinators

merge

unstable
Since v4.2.0

Folds a tree's entries into one HtmlHead, applying each node's reduce entries bottom up. The Html vocabulary installs it as its merge.

Details

A node's value is its own entries, then its children's values ordered by path, so a descendant's entry wins over its ancestor's per identity. The title passes through the titleTemplate of each ancestor of the node that set it, nearest first, as Head.resolveTitle says. A node's HtmlHead.reduce and Head.reduce entries then map its value, in written order. A template or a reduce that throws is reported to its node's onError and skipped.

When siblings set the title, lang, dir, a data-* attribute or a meta, link or JSON-LD entry of one identity to different values, it's left unset. A reduce above them that sets it settles it, under its own node's path. Otherwise onConflict gets a Head.Conflict with every path that set it, sorted.

Signature

declare const merge: (tree: Head.Tree<Entry>, options?: Head.MergeOptions) => HtmlHead

Constants

empty

unstable
Since v4.2.0

The head with no entries.

Signature

declare const empty: HtmlHead

marker

unstable
Since v4.2.0

The marker attribute on every head tag the framework writes.

Signature

declare const marker: "data-eui"

Constructors

bodyClass

unstable
Since v4.2.0

Adds class tokens to <body>. Strings are split on ASCII whitespace.

Signature

declare function bodyClass(tokens: string | readonly Array<string>): BodyClass

bodyData

unstable
Since v4.2.0

Sets a data-* attribute of <body>. "" means present and empty.

Signature

declare function bodyData<N extends string>(name: N & DataName<N>, value: string): BodyData

dir

unstable
Since v4.2.0

Sets the dir attribute of <html>.

Signature

declare function dir(dir: "ltr" | "rtl"): Dir

htmlClass

unstable
Since v4.2.0

Adds class tokens to <html>. Strings are split on ASCII whitespace.

Details

A token becomes the framework's once any entry contributes it, and the browser host removes it once no entry does, even if it was in the shell. Tokens no entry ever contributed are never touched.

Signature

declare function htmlClass(tokens: string | readonly Array<string>): HtmlClass

htmlData

unstable
Since v4.2.0

Sets a data-* attribute of <html>. "" means present and empty.

Details

When the last entry for a name goes away, the browser host removes the attribute, or restores the value the shell had.

Signature

declare function htmlData<N extends string>(name: N & DataName<N>, value: string): HtmlData

jsonLd

unstable
Since v4.2.0

Adds a JSON-LD block.

Details

The value is an object, never a top-level array: use @graph for several nodes. It's identified by key, else by its canonical form, and the host rewrites a block only when its canonical form changes.

The type rejects functions, dates, bigints and symbols one level deep. When the entry is built, deeper levels are checked too: an object whose prototype isn't Object.prototype or null (a Date, Map, Option or class instance), or an array holding NaN, Infinity or undefined, throws an error naming its JSON path. In a head option that fails the instance. The check runs in every build, not only in development: effect has no development switch, and it shares the walk the canonical serialisation makes anyway.

Signature

declare function jsonLd<A extends object>(value: JsonLdValue<A>, options?: {
readonly key?: string;
}): JsonLd

Example Describing a person

import { HtmlHead } from "effect/ui/html"
const entry = HtmlHead.jsonLd({ "@context": "https://schema.org", "@type": "Person", name: "Ada <Lovelace>" })
entry.json // => '{"@context":"https://schema.org","@type":"Person","name":"Ada \\u003cLovelace>"}'

lang

unstable
Since v4.2.0

Sets the lang attribute of <html>.

Signature

declare function lang(code: string): Lang

meta

unstable
Since v4.2.0

Adds a <meta> tag, named by name or by property.

Details

Its identity is key, else the name or property. http-equiv meta tags and <meta charset> belong to the shell and aren't entries.

Signature

declare function meta(options: {
readonly content: string;
readonly key?: string;
readonly name: string;
} | {
readonly content: string;
readonly key?: string;
readonly property: string;
}): Meta

reduce

unstable
Since v4.2.0

Maps the folded head of the instance and everything its view placed, such as deriving og:title from the title that won.

Details

It runs with the node's other reduce entries, Head.reduce's included, in written order, after its own entries and its children's values are merged. Head.merge ignores it.

Signature

declare function reduce(apply: (below: HtmlHead) => HtmlHead): Reduce

Example Deriving og:title

import { Head } from "effect/ui"
import { HtmlHead } from "effect/ui/html"
const ogTitle = HtmlHead.reduce((below) => ({
...below,
meta: [...below.meta, HtmlHead.meta({ property: "og:title", content: below.title ?? "App" })]
}))
const head = HtmlHead.merge({
entries: [Head.titleTemplate((title) => `${title} ยท App`), ogTitle],
children: [{ entries: [Head.title("Ada")], children: [] }]
})
head.meta.map((meta) => meta.content) // => ["Ada ยท App"]

Models

BodyClass

interface unstable
Since v4.2.0

Class tokens for <body>.

Signature

interface BodyClass {
readonly _tag: "BodyClass";
readonly tokens: readonly Array<string>;
}

BodyData

interface unstable
Since v4.2.0

A data-* attribute of <body>.

Signature

interface BodyData {
readonly _tag: "BodyData";
readonly name: `data-${string}`;
readonly value: string;
}

Dir

interface unstable
Since v4.2.0

The dir attribute of <html>.

Signature

interface Dir {
readonly _tag: "Dir";
readonly dir: "ltr" | "rtl";
}

Entry

type unstable
Since v4.2.0

One entry of the HTML vocabulary's head: Head's entries, or one of the HTML ones.

Signature

type Entry = Head.Entry | Reduce | Meta | Link | Lang | Dir | JsonLd | HtmlClass | BodyClass | HtmlData | BodyData

HtmlClass

interface unstable
Since v4.2.0

Class tokens for <html>.

Signature

interface HtmlClass {
readonly _tag: "HtmlClass";
readonly tokens: readonly Array<string>;
}

HtmlData

interface unstable
Since v4.2.0

A data-* attribute of <html>.

Signature

interface HtmlData {
readonly _tag: "HtmlData";
readonly name: `data-${string}`;
readonly value: string;
}

HtmlHead

interface unstable
Since v4.2.0

The folded head of a tree, ready for a host.

Details

title has the templates applied. meta, links and jsonLd hold one entry per identity, in the order each identity was first contributed: a node's own entries as written, then its children's, ordered by path. html and body hold the attributes set on those elements; class lists tokens in the same order.

Signature

interface HtmlHead extends Head {
readonly body: {
readonly class: readonly Array<string>;
readonly data: Readonly<Record<string, string>>;
};
readonly html: {
readonly class: readonly Array<string>;
readonly data: Readonly<Record<string, string>>;
readonly dir: "ltr" | "rtl" | undefined;
readonly lang: string | undefined;
};
readonly jsonLd: readonly Array<JsonLd>;
readonly links: readonly Array<Link>;
readonly meta: readonly Array<Meta>;
readonly title: string | undefined;
}

JsonLd

interface unstable
Since v4.2.0

A JSON-LD block, rendered as <script type="application/ld+json">.

Details

json is the canonical form: keys sorted recursively, undefined properties dropped, and < escaped as \u003c, so it's safe inside a script tag and two equal values always print the same.

Signature

interface JsonLd {
readonly _tag: "JsonLd";
readonly json: string;
readonly key: string | undefined;
readonly value: object;
}

Lang

interface unstable
Since v4.2.0

The lang attribute of <html>.

Signature

interface Lang {
readonly _tag: "Lang";
readonly code: string;
}

LinkAttributes

interface unstable
Since v4.2.0

The attributes a <link> tag may have.

Details

Links have no nonce and no event attributes.

Signature

interface LinkAttributes {
readonly as?: string;
readonly crossorigin?: string;
readonly href: string;
readonly hreflang?: string;
readonly imagesizes?: string;
readonly imagesrcset?: string;
readonly media?: string;
readonly rel: string;
readonly sizes?: string;
readonly type?: string;
}

Meta

interface unstable
Since v4.2.0

A <meta> tag, named by name or by property.

Signature

interface Meta {
readonly _tag: "Meta";
readonly content: string;
readonly key: string | undefined;
readonly name: string | undefined;
readonly property: string | undefined;
}

Reduce

interface unstable
Since v4.2.0

Maps the folded head of its node, its own entries merged with its children's values, with every HTML field in view.

Signature

interface Reduce {
readonly _tag: "HtmlHeadReduce";
readonly apply: (below: HtmlHead) => HtmlHead;
}

Utility Types

DataName

type unstable
Since v4.2.0

A data-* attribute name. data-eui is the framework's marker, so it's excluded.

Signature

type DataName<N extends string> = N extends "data-eui" ? never : N extends `data-${string}` ? N : never

JsonLdValue

type unstable
Since v4.2.0

What a JSON-LD block accepts: an object whose properties aren't functions, dates, bigints or symbols. Deeper levels are checked when the entry is built.

Signature

type JsonLdValue<A extends object> = A & { [K in keyof A]: A[K] extends Function | Date | bigint | symbol ? never : A[K] }

Utils

attributes

unstable
Since v4.2.0

The attributes of a meta or link tag, in a stable order, without the marker.

Signature

declare const attributes: (entry: Meta | Link) => ReadonlyArray<readonly [string, string]>
Since v4.2.0

The canonical JSON of a value: keys sorted recursively, undefined properties dropped and < escaped as \u003c.

Signature

declare function canonicalJson(value: object): string

identity

unstable
Since v4.2.0

The identity of a meta, link or JSON-LD entry: two entries with the same identity are the same entry. In one node's entries the later one wins.

Signature

declare function identity(entry: Meta | Link | JsonLd): string

Vocabulary