Meta

Opt-in bundle of validated Hotwire meta tags with practical defaults

View documentation

The umbrella tag

Conceptual

One tag states everything the page opts into. A prop you leave out renders nothing, so the head never claims a behaviour the application did not ask for. The output below is this component rendered for real, on this request.

Rendered into the head

<meta name="turbo-prefetch" content="true">
<meta name="turbo-refresh-method" content="morph">
<meta name="turbo-refresh-scroll" content="preserve">
<meta name="csrf-token" content="VrQ84b2Qs3VUf1k3QykTOcEFL2M3IhXZ1bgLZVYp">

Overriding a default

Conceptual

A bare attribute takes the granular component's own default; passing a value overrides it. prefetch is the exception to false meaning "leave it out" — there, false is the value the meta exists to state, so it renders and disables link prefetching.

Rendered into the head

<meta name="turbo-prefetch" content="false">
<meta name="turbo-cache-control" content="no-cache">
<meta name="turbo-root" content="/app">
<meta name="csrf-token" content="VrQ84b2Qs3VUf1k3QykTOcEFL2M3IhXZ1bgLZVYp">

refresh and scroll are one component

Conceptual

Two props over a single tag pair: writing either renders both metas. If one half is false while the other asks for the pair, the false half falls back to its default rather than disappearing.

Three separate renders, in order

<meta name="turbo-refresh-method" content="morph">
<meta name="turbo-refresh-scroll" content="preserve">


<meta name="turbo-refresh-method" content="morph">
<meta name="turbo-refresh-scroll" content="reset">


<meta name="turbo-refresh-method" content="replace">
<meta name="turbo-refresh-scroll" content="preserve">

Granular components

Conceptual

Each tag also stands on its own, with the same default the umbrella uses. Reach for these when a layout composes the head from more than one place.

Rendered into the head

<meta name="turbo-prefetch" content="false">
<meta name="turbo-refresh-method" content="morph">
<meta name="turbo-refresh-scroll" content="preserve">
<meta name="turbo-cache-control" content="no-cache">
<meta name="turbo-visit-control" content="reload">
<meta name="turbo-root" content="/app">
<meta name="view-transition" content="same-origin">
<meta name="csrf-token" content="VrQ84b2Qs3VUf1k3QykTOcEFL2M3IhXZ1bgLZVYp">

color-scheme brings the pre-paint script

Conceptual

On the umbrella, color-scheme also renders <hw:color-scheme.script />, so data-theme is applied before CSS paints and the page never flashes the wrong theme. The granular components stay single-purpose and emit only their own tag.

Rendered into the head

<script>
    (() => {
        const storageKey = "hotwire.colorScheme";
        const defaultMode = "system";
        const attribute = "data-theme";
        let mode = defaultMode;

        try {
            mode = localStorage.getItem(storageKey) || defaultMode;
        } catch (error) {}

        if (!['light', 'dark', 'system'].includes(mode)) {
            mode = defaultMode;
        }

        const scheme = mode === 'system'
            ? (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
            : mode;

        document.documentElement.setAttribute(attribute, scheme);
        document.documentElement.setAttribute('data-color-scheme-mode', mode);
        document.documentElement.style.colorScheme = scheme;
    })();
</script>
<meta name="color-scheme" content="light dark">

Values are validated, not silently ignored

Conceptual

A wrong value throws instead of rendering a meta the browser would quietly drop. The message names what is supported — this is the real exception, caught and printed.

InvalidArgumentException

Unsupported meta.refresh method value. Supported values: replace, morph.