# Template refs and ids

> useTemplateRef gives client code an element that ref attaches, and useId gives an id that is unique in its app. Every framework gets its own refs and ids.

Some code needs an element itself: to focus it, to measure what it holds, or to clear a field. A template ref gives client code the element. Some markup needs an id that ties two elements together, such as a label and its field. `useId` gives one that is unique in the app that renders it.

## Template refs

`useTemplateRef<T>()` declares a template ref, and `ref={field}` on an element attaches it. Once the element is in the document, client code reads it as `field.value`:

<!-- prettier-ignore -->
```tsx [SearchToggle.uf.tsx]
import { useTemplateRef } from "@uxfront/unframework";

export default function SearchToggle() {
  const field = useTemplateRef<HTMLInputElement>();
  const trigger = useTemplateRef<HTMLButtonElement>();

  function focusField() {
    field.value?.focus();
  }

  function returnFocus(event: KeyboardEvent) {
    if (event.key === "Escape") trigger.value?.focus();
  }

  return (
    <div class="search-toggle" role="search">
      <button type="button" ref={trigger} onClick={focusField}>
        Search
      </button>
      <input name="query" aria-label="Search the docs" ref={field} onKeydown={returnFocus} />
    </div>
  );
}
```

Each framework gets its own refs:

::framework-switcher
#react

<!-- prettier-ignore -->
```tsx [SearchToggle.tsx]
import { type CSSProperties, type KeyboardEvent, useRef } from "react";

export interface SearchToggleAttributes {
  className?: string;
  style?: CSSProperties;
}

export default function SearchToggle({ className, style, ...attributes }: SearchToggleAttributes) {
  const field = useRef<HTMLInputElement>(null);
  const trigger = useRef<HTMLButtonElement>(null);

  function focusField() {
    field.current?.focus();
  }

  function returnFocus(event: KeyboardEvent) {
    if (event.key === "Escape") trigger.current?.focus();
  }

  return (
    <div
      className={cx("search-toggle", className)}
      role="search"
      style={style}
      {...scopeAttributes(attributes)}
    >
      <button type="button" ref={trigger} onClick={focusField}>
        Search
      </button>
      <input name="query" aria-label="Search the docs" ref={field} onKeyDown={returnFocus} />
    </div>
  );
}

/** Joins class names, and the keys of an object's truthy entries, into one `className`. */
function cx(...parts: unknown[]): string {
  const names: string[] = [];
  for (const part of parts) {
    if (typeof part === "string") {
      if (part) names.push(part);
    } else if (part && typeof part === "object") {
      for (const [key, on] of Object.entries(part)) {
        if (on) names.push(key);
      }
    }
  }
  return names.join(" ");
}

/** The scope attributes of the styled parents that render this component, for its root. */
function scopeAttributes(props: object): Record<string, ""> {
  const scope: Record<string, ""> = {};
  for (const key of Object.keys(props)) {
    if (key.startsWith("data-uf-")) scope[key] = "";
  }
  return scope;
}
```

#vue

<!-- prettier-ignore -->
```vue [SearchToggle.vue]
<script setup lang="ts">
import { useTemplateRef } from "vue";

const field = useTemplateRef<HTMLInputElement>("field");
const trigger = useTemplateRef<HTMLButtonElement>("trigger");

function focusField() {
  field.value?.focus();
}

function returnFocus(event: KeyboardEvent) {
  if (event.key === "Escape") trigger.value?.focus();
}
</script>

<template>
  <div class="search-toggle" role="search">
    <button ref="trigger" type="button" @click="focusField">Search</button>
    <input ref="field" name="query" aria-label="Search the docs" @keydown="returnFocus" />
  </div>
</template>
```

#svelte

<!-- prettier-ignore -->
```svelte [SearchToggle.svelte]
<svelte:options runes={true} preserveWhitespace={false} />

<script lang="ts">
  import type { ClassValue } from "svelte/elements";

  type Props = { class?: ClassValue; style?: string };

  let { class: className, style, ...attributes }: Props = $props();

  let field: HTMLInputElement | null = null;
  let trigger: HTMLButtonElement | null = null;

  function focusField() {
    field?.focus();
  }

  function returnFocus(event: KeyboardEvent) {
    if (event.key === "Escape") trigger?.focus();
  }

  /** The scope attributes of the styled parents that render this component, for its root. */
  function scopeAttributes(props: object): Record<string, ""> {
    const scope: Record<string, ""> = {};
    for (const name of Object.keys(props)) if (name.startsWith("data-uf-")) scope[name] = "";
    return scope;
  }
</script>

<div class={["search-toggle", className]} role="search" {style} {...scopeAttributes(attributes)}>
  <button type="button" bind:this={trigger} onclick={focusField}>Search</button
  ><input name="query" aria-label="Search the docs" bind:this={field} onkeydown={returnFocus} />
</div>
```

#angular

<!-- prettier-ignore -->
```ts [search-toggle.ts]
import {
  Component,
  Directive,
  ElementRef,
  type OnInit,
  Renderer2,
  inject,
  input,
  viewChild,
} from "@angular/core";

/** The scope attributes taken off each host, for the roots its component renders later. */
const scopes = new WeakMap<Element, string[]>();

/**
 * Gives a root node of its component the scope attributes the component's styled parents put on
 * its host (ADR-0063), and takes them off the host, which keeps only `display: contents`.
 */
@Directive({ selector: "[ufScope]" })
export class ScopeAttributes implements OnInit {
  readonly ufScope = input.required<HTMLElement>();
  private readonly element = inject<ElementRef<Element>>(ElementRef);
  private readonly renderer = inject(Renderer2);

  ngOnInit(): void {
    const host = this.ufScope();
    let names = scopes.get(host);
    if (!names) {
      names = host.getAttributeNames().filter((name) => name.startsWith("data-uf-"));
      for (const name of names) this.renderer.removeAttribute(host, name);
      scopes.set(host, names);
    }
    for (const name of names) this.renderer.setAttribute(this.element.nativeElement, name, "");
  }
}

@Component({
  selector: "uf-search-toggle",
  imports: [ScopeAttributes],
  host: { "[attr.class]": "null", "[attr.style]": "'display: contents;'" },
  preserveWhitespaces: false,
  template: `
    <div
      class="search-toggle"
      role="search"
      [class]="this.class()"
      [style]="this.style()"
      [ufScope]="this.host"
    >
      <button type="button" #trigger (click)="focusField()">Search</button>
      <input name="query" aria-label="Search the docs" #field (keydown)="returnFocus($event)" />
    </div>
  `,
})
export default class SearchToggle {
  readonly class = input<string>();
  readonly style = input<Record<string, string | null | undefined>>();
  private readonly field = viewChild<ElementRef<HTMLInputElement>>("field");
  private readonly trigger = viewChild<ElementRef<HTMLButtonElement>>("trigger");

  protected focusField() {
    this.field()?.nativeElement.focus();
  }

  protected returnFocus(event: KeyboardEvent) {
    if (event.key === "Escape") this.trigger()?.nativeElement.focus();
  }
  protected readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
}
```

#solid

<!-- prettier-ignore -->
```tsx [SearchToggle.tsx]
import { type JSX, onCleanup } from "solid-js";

export default function SearchToggle(props: { class?: string; style?: JSX.CSSProperties }) {
  let field: HTMLInputElement | null = null;
  let trigger: HTMLButtonElement | null = null;

  function focusField() {
    field?.focus();
  }

  function returnFocus(event: KeyboardEvent) {
    if (event.key === "Escape") trigger?.focus();
  }

  return (
    <div
      class={props.class ? `search-toggle ${props.class}` : "search-toggle"}
      role="search"
      style={props.style}
      {...scopeAttributes(props)}
    >
      <button
        type="button"
        ref={(element) => {
          trigger = element;
          onCleanup(() => {
            trigger = null;
          });
        }}
        onClick={focusField}
      >
        Search
      </button>
      <input
        name="query"
        aria-label="Search the docs"
        ref={(element) => {
          field = element;
          onCleanup(() => {
            field = null;
          });
        }}
        onKeyDown={returnFocus}
      />
    </div>
  );
}

/** The scope attributes of the styled parents that render this component, for its root. */
function scopeAttributes(props: object): Record<string, ""> {
  const scope: Record<string, ""> = {};
  for (const name of Object.keys(props)) if (name.startsWith("data-uf-")) scope[name] = "";
  return scope;
}
```

#qwik

<!-- prettier-ignore -->
```tsx [SearchToggle.tsx]
import { $, type CSSProperties, type ClassList, component$, useSignal } from "@qwik.dev/core";

export default component$<{ class?: ClassList; style?: CSSProperties }>(
  ({ class: className, style, ...attributes }) => {
    const field = useSignal<HTMLInputElement>();
    const trigger = useSignal<HTMLButtonElement>();

    const focusField = $(() => {
      field.value?.focus();
    });

    const returnFocus = $((event: KeyboardEvent) => {
      if (event.key === "Escape") trigger.value?.focus();
    });

    return (
      <div
        class={["search-toggle", className]}
        role="search"
        {...scopeAttributes(attributes)}
        style={style}
      >
        <button type="button" ref={trigger} onClick$={focusField}>
          Search
        </button>
        <input name="query" aria-label="Search the docs" ref={field} onKeyDown$={returnFocus} />
      </div>
    );
  },
);

/** The scope attributes of the styled parents that render this component, for its root. */
function scopeAttributes(props: object): Record<string, ""> {
  const scope: Record<string, ""> = {};
  for (const key of Object.keys(props)) {
    if (key.startsWith("data-uf-")) scope[key] = "";
  }
  return scope;
}
```

#astro

<!-- prettier-ignore -->
```astro [SearchToggle.astro]
---
interface Props {
  class?: string;
  style?: Record<string, string | number | undefined>;
}

const { class: className, style } = Astro.props;

/** The scope attributes of the styled parents that render this component, for its root. */
function scopeAttributes(props: object): Record<string, ""> {
  const scope: Record<string, ""> = {};
  for (const name of Object.keys(props)) if (name.startsWith("data-uf-")) scope[name] = "";
  return scope;
}
---

<div
  class:list={["search-toggle", className]}
  role="search"
  style={style}
  {...scopeAttributes(Astro.props)}
>
  <button type="button">Search</button>
  <input name="query" aria-label="Search the docs" />
</div>
```

::

- React declares `useRef<T>(null)`, read as `field.current`.
- Vue declares `useTemplateRef<T>("field")`, keyed by the binding's name, and writes `ref="field"` on the element.
- Svelte declares a `let`, `T | null` and `null` at first, and binds it with `bind:this`, which writes `null` once the element is gone. Where the element is inside a conditional, the `let` is `$state`, as Svelte asks.
- Angular declares `viewChild<ElementRef<T>>("field")` and writes `#field` on the element. Code reads `this.field()?.nativeElement`, and `?? null` where it keeps or passes the element.
- Solid declares a `let`, `T | null` and `null` at first, which the element's ref callback sets, and empties to `null` when the element is removed.
- Qwik declares `useSignal<T>()`, attached with `ref={field}`. Qwik's signal holds `undefined` while it is empty, so code that keeps or passes the element reads `field.value ?? null`.
- Astro drops the refs with the code that reads them: nothing runs in the browser.

A template ref is empty before its element is mounted, and again once the element is removed, as when a conditional hides it. An empty template ref is `null` on every target, as its type, `T | null`, says, so any test of it reads alike: `field.value?.focus()`, `if (el)`, `el !== null`. A test narrows it as any nullable value: Angular, which reads it through a call, asserts the read that the test shows present ([State](/docs/components/state#narrowing)).

Every framework renders the element from state, so client code never changes its structure or its text through the ref: `textContent`, `innerHTML`, `append`, `remove`, `replaceWith` and the like are [UF3028](/docs/reference/diagnostics#UF3028). Nor does it change the classes of an element whose `class` the template binds, or the style of one whose `style` it binds: each framework patches what its template binds its own way. A class, a style or an attribute that the template does not bind is the code's own on every target, as an autosizing field's height is:

<!-- prettier-ignore -->
```tsx [TaskBoard.uf.tsx]
function resize() {
  const field = notes.value;
  if (!field) return;
  const lines = field.value.split("\n").length;
  field.style.height = `${Math.max(lines, 2) * 1.5}em`;
  field.classList.toggle("tall", lines > 3);
}
```

Its other properties and methods, `focus()`, `scrollTop`, a field's `value` or `childElementCount`, are fine.

### Where to read one

Only client code reads a template ref: a handler, a watcher's callback, a lifecycle hook, or a function they call. A template ref is never a reactive dependency on any target, so a template, a getter, an initial value, a watcher's source or `watchEffect` that reads one is [UF2010](/docs/reference/diagnostics#UF2010). What a `watchEffect` hands on to run later, such as a frame's callback, may read one. Teardown code reads none ([UF2026](/docs/reference/diagnostics#UF2026), [Lifecycle](/docs/components/lifecycle#onunmounted)).

- In `onMounted`, the element is in the document ([Lifecycle](/docs/components/lifecycle#onmounted)).
- After a write that renders the element, `await nextTick()` first ([Lifecycle](/docs/components/lifecycle#nexttick)).
- In a watcher, add `{ flush: "post" }`, so that it calls back after the DOM updates ([UF2018](/docs/reference/diagnostics#UF2018), [Effects](/docs/components/effects#reading-the-dom)).

To focus an element when the component mounts, focus it from `onMounted` through a template ref: `autofocus` is [UF1002](/docs/reference/diagnostics#UF1002), because the targets apply it differently.

### Attaching one

One element attaches each template ref, outside every list: in a list, Vue fills a ref with an array of the elements, and the other targets with the last one. A `ref` whose value is no template ref (a string, as Vue writes it, a callback or another binding), a template ref attached twice, one inside a list and one that no element attaches are [UF3027](/docs/reference/diagnostics#UF3027). `ref` is written in lower case: `REF` is [UF3004](/docs/reference/diagnostics#UF3004), with a fix.

On a component, `ref` holds what the component exposes, rather than an element ([Expose and component refs](/docs/components/expose-and-refs)).

## Ids

`useId()` gives an id that is unique in the app that renders it. Two apps mounted apart on one page count their ids apart, so they may repeat each other's. Use it for `for`, `aria-describedby` and the other attributes that refer to an element by its id:

<!-- prettier-ignore -->
```tsx [EmailField.uf.tsx]
import { useId } from "@uxfront/unframework";

export interface EmailFieldProps {
  label: string;
  hint: string;
}

export default function EmailField({ label, hint }: EmailFieldProps) {
  const inputId = useId();
  const hintId = useId();

  return (
    <div class="email-field">
      <label for={inputId}>{label}</label>
      <input id={inputId} name="email" type="email" aria-describedby={hintId} />
      <p id={hintId}>{hint}</p>
    </div>
  );
}
```

::framework-switcher
#react

<!-- prettier-ignore -->
```tsx [EmailField.tsx]
import { type CSSProperties, useId } from "react";

export interface EmailFieldProps {
  label: string;
  hint: string;
}

export interface EmailFieldAttributes {
  className?: string;
  style?: CSSProperties;
}

export default function EmailField({
  label,
  hint,
  className,
  style,
  ...attributes
}: EmailFieldProps & EmailFieldAttributes) {
  const inputId = `uf-id-${useId()}`;
  const hintId = `uf-id-${useId()}`;

  return (
    <div className={cx("email-field", className)} style={style} {...scopeAttributes(attributes)}>
      <label htmlFor={inputId}>{label}</label>
      <input id={inputId} name="email" type="email" aria-describedby={hintId} />
      <p id={hintId}>{hint}</p>
    </div>
  );
}

/** Joins class names, and the keys of an object's truthy entries, into one `className`. */
function cx(...parts: unknown[]): string {
  const names: string[] = [];
  for (const part of parts) {
    if (typeof part === "string") {
      if (part) names.push(part);
    } else if (part && typeof part === "object") {
      for (const [key, on] of Object.entries(part)) {
        if (on) names.push(key);
      }
    }
  }
  return names.join(" ");
}

/** The scope attributes of the styled parents that render this component, for its root. */
function scopeAttributes(props: object): Record<string, ""> {
  const scope: Record<string, ""> = {};
  for (const key of Object.keys(props)) {
    if (key.startsWith("data-uf-")) scope[key] = "";
  }
  return scope;
}
```

#vue

<!-- prettier-ignore -->
```vue [EmailField.vue]
<script setup lang="ts">
import { useId } from "vue";

export interface EmailFieldProps {
  label: string;
  hint: string;
}

const { label, hint } = defineProps<EmailFieldProps>();

const inputId = `uf-id-${useId()}`;
const hintId = `uf-id-${useId()}`;
</script>

<template>
  <div class="email-field">
    <label :for="inputId">{{ label }}</label>
    <input :id="inputId" name="email" type="email" :aria-describedby="hintId" />
    <p :id="hintId">{{ hint }}</p>
  </div>
</template>
```

#svelte

<!-- prettier-ignore -->
```svelte [EmailField.svelte]
<svelte:options runes={true} preserveWhitespace={false} />

<script lang="ts" module>
  export interface EmailFieldProps {
    label: string;
    hint: string;
  }
</script>

<script lang="ts">
  import type { ClassValue } from "svelte/elements";

  type Props = EmailFieldProps & { class?: ClassValue; style?: string };

  let { label, hint, class: className, style, ...attributes }: Props = $props();

  const uid = $props.id();
  const inputId = `uf-id-${uid}-0`;
  const hintId = `uf-id-${uid}-1`;

  /** The scope attributes of the styled parents that render this component, for its root. */
  function scopeAttributes(props: object): Record<string, ""> {
    const scope: Record<string, ""> = {};
    for (const name of Object.keys(props)) if (name.startsWith("data-uf-")) scope[name] = "";
    return scope;
  }
</script>

<div class={["email-field", className]} {style} {...scopeAttributes(attributes)}>
  <label for={inputId}>{label}</label
  ><input id={inputId} name="email" type="email" aria-describedby={hintId}
  /><p id={hintId}>{hint}</p>
</div>
```

#angular

<!-- prettier-ignore -->
```ts [email-field.ts]
import {
  Component,
  Directive,
  ElementRef,
  InjectionToken,
  type OnInit,
  Renderer2,
  inject,
  input,
} from "@angular/core";

export interface EmailFieldProps {
  label: string;
  hint: string;
}

const idCounter = new InjectionToken<{ next: number }>("idCounter", {
  factory: () => ({ next: 0 }),
});

/** The scope attributes taken off each host, for the roots its component renders later. */
const scopes = new WeakMap<Element, string[]>();

/**
 * Gives a root node of its component the scope attributes the component's styled parents put on
 * its host (ADR-0063), and takes them off the host, which keeps only `display: contents`.
 */
@Directive({ selector: "[ufScope]" })
export class ScopeAttributes implements OnInit {
  readonly ufScope = input.required<HTMLElement>();
  private readonly element = inject<ElementRef<Element>>(ElementRef);
  private readonly renderer = inject(Renderer2);

  ngOnInit(): void {
    const host = this.ufScope();
    let names = scopes.get(host);
    if (!names) {
      names = host.getAttributeNames().filter((name) => name.startsWith("data-uf-"));
      for (const name of names) this.renderer.removeAttribute(host, name);
      scopes.set(host, names);
    }
    for (const name of names) this.renderer.setAttribute(this.element.nativeElement, name, "");
  }
}

@Component({
  selector: "uf-email-field",
  imports: [ScopeAttributes],
  host: { "[attr.class]": "null", "[attr.style]": "'display: contents;'" },
  preserveWhitespaces: false,
  template: `
    @let label = this.label();
    @let hint = this.hint();
    <div class="email-field" [class]="this.class()" [style]="this.style()" [ufScope]="this.host">
      <label [attr.for]="inputId">{{ label }}</label>
      <input [attr.id]="inputId" name="email" type="email" [attr.aria-describedby]="hintId" />
      <p [attr.id]="hintId">{{ hint }}</p>
    </div>
  `,
})
export default class EmailField {
  readonly label = input.required<string>();
  readonly hint = input.required<string>();
  readonly class = input<string>();
  readonly style = input<Record<string, string | null | undefined>>();
  protected readonly inputId = `uf-id-email-field-${inject(idCounter).next++}`;
  protected readonly hintId = `uf-id-email-field-${inject(idCounter).next++}`;
  protected readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
}
```

#solid

<!-- prettier-ignore -->
```tsx [EmailField.tsx]
import { type JSX, createUniqueId } from "solid-js";

export interface EmailFieldProps {
  label: string;
  hint: string;
}

export default function EmailField(
  props: EmailFieldProps & { class?: string; style?: JSX.CSSProperties },
) {
  const inputId = `uf-id-${createUniqueId()}`;
  const hintId = `uf-id-${createUniqueId()}`;

  return (
    <div
      class={props.class ? `email-field ${props.class}` : "email-field"}
      style={props.style}
      {...scopeAttributes(props)}
    >
      <label for={inputId}>{props.label}</label>
      <input id={inputId} name="email" type="email" aria-describedby={hintId} />
      <p id={hintId}>{props.hint}</p>
    </div>
  );
}

/** The scope attributes of the styled parents that render this component, for its root. */
function scopeAttributes(props: object): Record<string, ""> {
  const scope: Record<string, ""> = {};
  for (const name of Object.keys(props)) if (name.startsWith("data-uf-")) scope[name] = "";
  return scope;
}
```

#qwik

<!-- prettier-ignore -->
```tsx [EmailField.tsx]
import { type CSSProperties, type ClassList, component$, useId } from "@qwik.dev/core";

export interface EmailFieldProps {
  label: string;
  hint: string;
}

export default component$<EmailFieldProps & { class?: ClassList; style?: CSSProperties }>(
  ({ label, hint, class: className, style, ...attributes }) => {
    const inputId = "uf-id-" + useId();
    const hintId = "uf-id-" + useId();

    return (
      <div class={["email-field", className]} {...scopeAttributes(attributes)} style={style}>
        <label for={inputId}>{label}</label>
        <input id={inputId} name="email" type="email" aria-describedby={hintId} />
        <p id={hintId}>{hint}</p>
      </div>
    );
  },
);

/** The scope attributes of the styled parents that render this component, for its root. */
function scopeAttributes(props: object): Record<string, ""> {
  const scope: Record<string, ""> = {};
  for (const key of Object.keys(props)) {
    if (key.startsWith("data-uf-")) scope[key] = "";
  }
  return scope;
}
```

#astro

<!-- prettier-ignore -->
```astro [EmailField.astro]
---
export interface EmailFieldProps {
  label: string;
  hint: string;
}

interface Props extends EmailFieldProps {
  class?: string;
  style?: Record<string, string | number | undefined>;
}

const { label, hint, class: className, style } = Astro.props;

function uniqueId(): string {
  const locals = Astro.locals as { ufIdCount?: number };
  locals.ufIdCount = (locals.ufIdCount ?? 0) + 1;
  return `uf-id-${locals.ufIdCount}`;
}

/** The scope attributes of the styled parents that render this component, for its root. */
function scopeAttributes(props: object): Record<string, ""> {
  const scope: Record<string, ""> = {};
  for (const name of Object.keys(props)) if (name.startsWith("data-uf-")) scope[name] = "";
  return scope;
}

const inputId = uniqueId();
const hintId = uniqueId();
---

<div class:list={["email-field", className]} style={style} {...scopeAttributes(Astro.props)}>
  <label for={inputId}>{label}</label>
  <input id={inputId} name="email" type="email" aria-describedby={hintId} />
  <p id={hintId}>{hint}</p>
</div>
```

::

- React and Vue call their `useId()`, and Solid `createUniqueId()`.
- Qwik calls `useId()` outside a template literal, `"uf-id-" + useId()`, which its lint asks for.
- Svelte calls `$props.id()`, which a component may call once, and derives every id from it with a suffix of its own: `uf-id-${uid}-0`, `uf-id-${uid}-1`. So `${id}-1` of one id never spells another.
- Angular has no id API, so a counter makes each instance's ids, with the component's name in them, as Angular Material makes its own (`use-id`, emulated). The counter is one per application, so the server and the browser that hydrates its HTML count the same ids.
- Astro counts on `Astro.locals`, which lives for one request: two instances on a page get different ids, and every request starts again at 1 (`use-id`, emulated).

Every id starts with `uf-id-`, followed by what the framework makes, which differs from target to target. So use an id only to tie elements together: never parse it, compare it or show it. An id may name a radio group, and give each row an id of its own:

<!-- prettier-ignore -->
```tsx [SizePicker.uf.tsx]
{sizes.map((size, index) => (
  <div key={size} class="size">
    <input
      type="radio"
      id={`${group}-${index}`}
      name={group}
      value={size}
      onChange={() => choose(size)}
    />
    <label for={`${group}-${index}`}>{size}</label>
  </div>
))}
```

An id is bound by a `const` at the top level of the setup ([UF2006](/docs/reference/diagnostics#UF2006)), and read as a string, in the template as in code. An id written by hand never starts with `uf-id-` ([UF3005](/docs/reference/diagnostics#UF3005)): the compiler's ids own the prefix.

## Hydration

On React, Vue, Svelte, Solid and Angular, a browser that hydrates the server's HTML keeps the server's ids, and the tests check it on every case (L12). Qwik resumes the server's page instead of hydrating it, which the tests don't check yet. Astro runs nothing in the browser.

The decisions behind this page are [ADR-0049](https://github.com/uxfront-com/unframework/blob/main/docs/adrs/0049-template-refs-and-ids.md) and [ADR-0095](https://github.com/uxfront-com/unframework/blob/main/docs/adrs/0095-hydration.md).
