# Templates

> The JSX a component returns is its template. Its expressions, text, conditionals, lists and fragments compile to each framework's own template syntax.

A component returns its template: one element, or one fragment that holds several. The compiler lowers that JSX to each framework's template. Vue, Svelte, Angular and Astro have template languages of their own, so the compiler accepts the JSX that all seven read alike, and reports anything else with a code that names the reason.

A component is an exported function declaration. One written as an arrow function in a `const` is [UF1102](/docs/reference/diagnostics#UF1102), with a fix that declares it as a function. A returned conditional or list is UF1102 too, with a fix that wraps it in `<>…</>`, which renders the same, and so is an empty fragment.

## Expressions

An expression in braces can be a child, an attribute's value, a condition, a list's source or key, a part of a `class` or a `style`, or the source of a spread. It can read:

- the component's props;
- the setup's bindings: state and derived values as `count.value`, constants, ids, and calls of local functions that change nothing ([State](/docs/components/state));
- the item and the index of each list around it;
- the parameters of the arrow functions inside it, as in `items.filter((item) => item.done)`;
- a few pure globals: `undefined`, `NaN`, `Infinity`, `Math`, `Number`, `String`, `Boolean`, `Array`, `Object`, `JSON`, `parseInt`, `parseFloat`, `isNaN`, `isFinite`, `encodeURIComponent`, `decodeURIComponent`, `encodeURI` and `decodeURI`.

Any other name is [UF3020](/docs/reference/diagnostics#UF3020): Angular's templates see only the component's members, and the outputs may run where `window` does not exist. A template reads no template ref and no setup `let`, which are not reactive ([UF2010](/docs/reference/diagnostics#UF2010)), and calls only local functions that write, emit and await nothing ([UF2014](/docs/reference/diagnostics#UF2014)). Listeners are on [Events](/docs/components/events).

A list's or an arrow function's parameter cannot take a name the outputs rewrite or declare ([UF3024](/docs/reference/diagnostics#UF3024)): a prop's, a setup binding's, the props parameter's, an outer list variable's or a global's, `props`, `rawProps`, `Fragment`, or a name that starts with `$`, or with `_` and more (`_` alone is accepted). Nor can it take one of Angular's expression keywords, such as `as`, which its templates cannot read as a name.

<!-- prettier-ignore -->
```tsx [OrderSummary.uf.tsx]
<h2>Order {String(orderNumber).padStart(6, "0")}</h2>
<p>Customer: {customer.trim().toUpperCase()}</p>
<p>{`${quantity} item${quantity === 1 ? "" : "s"} at ${unitPrice.toFixed(2)} each`}</p>
<p>Subtotal: {(unitPrice * quantity).toFixed(2)}</p>
<p>Discount: {Math.min(Math.max(discount, 0), 50)}%</p>
```

Each target rewrites the names an expression reads, and keeps the rest as you wrote it:

::framework-switcher
#react

<!-- prettier-ignore -->
```tsx [OrderSummary.tsx]
<h2>Order {String(orderNumber).padStart(6, "0")}</h2>
<p>Customer: {customer.trim().toUpperCase()}</p>
<p>{`${quantity} item${quantity === 1 ? "" : "s"} at ${unitPrice.toFixed(2)} each`}</p>
<p>Subtotal: {(unitPrice * quantity).toFixed(2)}</p>
<p>Discount: {Math.min(Math.max(discount, 0), 50)}%</p>
```

#vue

<!-- prettier-ignore -->
```vue [OrderSummary.vue]
<h2>Order {{ String(orderNumber).padStart(6, "0") }}</h2>
<p>Customer: {{ customer.trim().toUpperCase() }}</p>
<p>{{ `${quantity} item${quantity === 1 ? "" : "s"} at ${unitPrice.toFixed(2)} each` }}</p>
<p>Subtotal: {{ (unitPrice * quantity).toFixed(2) }}</p>
<p>Discount: {{ Math.min(Math.max(discount, 0), 50) }}%</p>
```

#svelte

<!-- prettier-ignore -->
```svelte [OrderSummary.svelte]
<h2>Order {String(orderNumber).padStart(6, "0")}</h2
><p>Customer: {customer.trim().toUpperCase()}</p
><p>{`${quantity} item${quantity === 1 ? "" : "s"} at ${unitPrice.toFixed(2)} each`}</p
><p>Subtotal: {(unitPrice * quantity).toFixed(2)}</p
><p>Discount: {Math.min(Math.max(discount, 0), 50)}%</p
```

#angular

<!-- prettier-ignore -->
```ts [order-summary.ts]
<h2>Order {{ String(orderNumber).padStart(6, "0") }}</h2>
<p>Customer: {{ customer.trim().toUpperCase() }}</p>
<p>{{ quantity + " item" + (quantity === 1 ? "" : "s") + " at " + unitPrice.toFixed(2) + " each" }}</p>
<p>Subtotal: {{ (unitPrice * quantity).toFixed(2) }}</p>
<p>Discount: {{ Math.min(Math.max(discount, 0), 50) }}%</p>
```

#solid

<!-- prettier-ignore -->
```tsx [OrderSummary.tsx]
<h2>Order {String(props.orderNumber).padStart(6, "0")}</h2>
<p>Customer: {props.customer.trim().toUpperCase()}</p>
<p>{`${props.quantity} item${props.quantity === 1 ? "" : "s"} at ${props.unitPrice.toFixed(2)} each`}</p>
<p>Subtotal: {(props.unitPrice * props.quantity).toFixed(2)}</p>
<p>Discount: {Math.min(Math.max(props.discount, 0), 50)}%</p>
```

#qwik

<!-- prettier-ignore -->
```tsx [OrderSummary.tsx]
<h2>Order {String(orderNumber).padStart(6, "0")}</h2>
<p>Customer: {customer.trim().toUpperCase()}</p>
<p>{`${quantity} item${quantity === 1 ? "" : "s"} at ${unitPrice.toFixed(2)} each`}</p>
<p>Subtotal: {(unitPrice * quantity).toFixed(2)}</p>
<p>Discount: {Math.min(Math.max(discount, 0), 50)}%</p>
```

#astro

<!-- prettier-ignore -->
```astro [OrderSummary.astro]
<h2>Order {String(orderNumber).padStart(6, "0")}</h2>
<p>Customer: {customer.trim().toUpperCase()}</p>
<p>{`${quantity} item${quantity === 1 ? "" : "s"} at ${unitPrice.toFixed(2)} each`}</p>
<p>Subtotal: {(unitPrice * quantity).toFixed(2)}</p>
<p>Discount: {Math.min(Math.max(discount, 0), 50)}%</p>
```

::

Solid reads a prop as `props.name`, because its props are reactive getters. Angular's template sits inside a TypeScript template literal, so its output writes a template literal as a concatenation, and it declares each global an expression reads as a member of the component:

<!-- prettier-ignore -->
```ts [order-summary.ts]
protected readonly Math = Math;
protected readonly String = String;
```

Angular's output also writes literals in the spellings its template lexer reads. In a regular expression, for example, `'` becomes `\x27` and `;` becomes `\x3b`.

### The syntax every target reads

- Literals: strings, decimal numbers, booleans, `null`, regular expressions and template literals.
- Member access (`a.b`, `a[b]`, `a?.b`), calls and optional calls.
- Array literals, and object literals with identifier or string keys, both with spreads.
- Arrow functions, as a call's argument, with plain parameters and an expression body.
- The unary operators `!`, `-`, `+` and `typeof`, the arithmetic, equality and comparison operators, `&&`, `||` and `??`, the conditional operator and parentheses.

Angular's template parser rejects or misreads most of the rest, so it waits as [UF1002](/docs/reference/diagnostics#UF1002). Where a rewrite is mechanical, the diagnostic carries a fix:

| Not yet                                                        | Why                                                     | Fix                         |
| -------------------------------------------------------------- | ------------------------------------------------------- | --------------------------- |
| An arrow function with a block body                            | Angular: "Multi-line arrow functions are not supported" | `{ return e; }` becomes `e` |
| Arrow parameters with patterns, defaults, types or rest        | Angular's parser rejects each                           |                             |
| `as`, `!`, `satisfies` and type arguments                      | Angular's templates have no TypeScript syntax           |                             |
| `0x10`, `0o7` and `0b1`                                        | Angular: "Unexpected token"                             | The decimal value           |
| `\u{…}` escapes                                                | Angular: "Invalid unicode escape"                       | `\uXXXX` pairs              |
| Holes in arrays, and `Array(…)`                                | Angular rejects holes, and holes iterate differently    |                             |
| Computed keys, methods, getters and setters in object literals | Angular rejects them                                    |                             |
| Names outside ASCII                                            | Angular's lexer reads ASCII only                        |                             |
| `new` and the bitwise operators                                | Angular rejects `new`, and `\|` is its pipe             |                             |
| `in`, `instanceof`, tagged templates and BigInt literals       | No case needs them yet                                  |                             |

### Narrowing

A condition narrows what it tests, as TypeScript does. In the branch of `member && …`, an optional `member` is present, so the branch reads `member.email`:

<!-- prettier-ignore -->
```tsx [AccountSummary.uf.tsx]
{member && <p>Signed in as {member.email}</p>}
```

A union narrows the same way, by `Array.isArray`, `typeof` or a discriminant:

<!-- prettier-ignore -->
```tsx [FilterSummary.uf.tsx]
<p>Tags: {Array.isArray(tags) ? tags.join(", ") : tags}</p>
<p>Limit: {typeof limit === "number" ? limit.toFixed(0) : limit.toLowerCase()}</p>
{result.ok ? <p>Found {result.match}</p> : <p>No match: {result.error}</p>}
```

::framework-switcher
#react

<!-- prettier-ignore -->
```tsx [FilterSummary.tsx]
<p>Tags: {Array.isArray(tags) ? tags.join(", ") : tags}</p>
<p>Limit: {typeof limit === "number" ? limit.toFixed(0) : limit.toLowerCase()}</p>
{result.ok ? <p>Found {result.match}</p> : <p>No match: {result.error}</p>}
```

#vue

<!-- prettier-ignore -->
```vue [FilterSummary.vue]
<p>Tags: {{ Array.isArray(tags) ? tags.join(", ") : tags }}</p>
<p>Limit: {{ typeof limit === "number" ? limit.toFixed(0) : limit.toLowerCase() }}</p>
<p v-if="result.ok">Found {{ result.match }}</p>
<p v-else>No match: {{ result.error }}</p>
```

#svelte

<!-- prettier-ignore -->
```svelte [FilterSummary.svelte]
<p>Tags: {Array.isArray(tags) ? tags.join(", ") : tags}</p
><p>Limit: {typeof limit === "number" ? limit.toFixed(0) : limit.toLowerCase()}</p
>{#if result.ok}
  <p>Found {result.match}</p>
{:else}
  <p>No match: {result.error}</p>
{/if}
```

#angular

<!-- prettier-ignore -->
```ts [filter-summary.ts]
<p>Tags: {{ Array.isArray(tags) ? tags.join(", ") : tags }}</p>
<p>Limit: {{ typeof limit === "number" ? limit.toFixed(0) : limit.toLowerCase() }}</p>
@if (result.ok) {
  <p>Found {{ result.match }}</p>
} @else {
  <p>No match: {{ result.error }}</p>
}
```

#solid

<!-- prettier-ignore -->
```tsx [FilterSummary.tsx]
<p>Tags: {Array.isArray(props.tags) ? props.tags.join(", ") : props.tags}</p>
<p>
  Limit:{" "}
  {typeof props.limit === "number" ? props.limit.toFixed(0) : props.limit.toLowerCase()}
</p>
<Switch>
  <Match when={props.result.ok ? { result: props.result } : undefined}>
    {(narrowed) => <p>Found {narrowed().result.match}</p>}
  </Match>
  <Match when={props.result.ok ? undefined : { result: props.result }}>
    {(narrowed) => <p>No match: {narrowed().result.error}</p>}
  </Match>
</Switch>
```

#qwik

<!-- prettier-ignore -->
```tsx [FilterSummary.tsx]
<p>Tags: {Array.isArray(tags) ? tags.join(", ") : tags}</p>
<p>Limit: {typeof limit === "number" ? limit.toFixed(0) : limit.toLowerCase()}</p>
{result.ok ? <p>Found {result.match}</p> : <p>No match: {result.error}</p>}
```

#astro

<!-- prettier-ignore -->
```astro [FilterSummary.astro]
<p>Tags: {Array.isArray(tags) ? tags.join(", ") : tags}</p>
<p>Limit: {typeof limit === "number" ? limit.toFixed(0) : limit.toLowerCase()}</p>
{result.ok ? (
  <p>Found {result.match}</p>
) : (
  <p>No match: {result.error}</p>
)}
```

::

Every target's checker narrows as TypeScript narrows the source, and the compiler follows the same tests: a test of the value itself, through `!`, `&&` and `||`, a comparison with `null`, `undefined` or a value, `typeof`, a member read through `?.`, `Array.isArray`, and a discriminant of a union, as `plan.kind === "paid"` narrows `plan`. Where a value can be neither `null` nor `undefined`, by its type or by such a test, `a?.b` and `a ?? b` do nothing, and Angular's compiler rejects them: [UF3023](/docs/reference/diagnostics#UF3023), with a fix that removes the operator.

A destructured prop that a conditional child narrows stays narrowed in that branch's lists and arrow functions, on every target. TypeScript forgets a property's narrowing inside a callback, though, where Angular's loops keep it. So where the checkers read a value apart, a use that relies on a narrowing some of them do not see is [UF1002](/docs/reference/diagnostics#UF1002):

- a member, or a prop of the object form, that a condition outside a list narrows, used inside the list's callback: test it inside the callback;
- a prop that a conditional inside an expression narrows, used in an arrow function in that expression: read it through `?.`, or give it a value with `??`, as in `item.includes(query ?? "")`;
- a narrowed prop that a list's key uses, because Angular's `track` reads the input again: give it a value where it may be absent, as in `(count ?? 0) + index`.

Testing the value, reading it through `?.`, giving it a value with `??`, comparing it for equality and writing it into a string read alike everywhere, so those uses are accepted. An equality with a value that is no literal (`box.inner?.title === label`) is a test the compiler does not follow: a `?.` or `??` that Angular may then reject is UF1002 too. A relational comparison or a call narrows nothing on any checker, so the source's own type check judges what follows it.

### Pure and deterministic

A component renders on the server and again in the browser, and a framework renders when it decides to, sometimes twice. So an expression must not change anything, and must give the same result everywhere:

- [UF3021](/docs/reference/diagnostics#UF3021): no assignment, `++`, `delete`, `void`, comma operator, `await`, `yield`, `this`, function or class expression, and no call of a method that changes its receiver (`sort`, `reverse`, `splice`, `push`, …). The fix writes `toSorted`, `toReversed` and `toSpliced`.
- [UF3019](/docs/reference/diagnostics#UF3019): no `Date`, `Intl`, `crypto`, `performance`, `globalThis` or `Math.random`, and no locale methods (`toLocaleString`, `localeCompare`, …). Pass such a value in as a prop.

## Text

An expression child renders its value as text: a string as it is, and a number as `String(n)`. `null` and `undefined` render nothing, and so do `{""}` and a comment, `{/* … */}`.

A boolean, an array or an object is [UF3016](/docs/reference/diagnostics#UF3016): JSX and the template languages render them differently. Turn the value into text first: `done ? "Done" : "Open"`, `tags.join(", ")`, or a member of the object.

### Whitespace

Text between tags follows JSX's rules: each line is trimmed, lines that hold only whitespace are dropped, and the lines that remain join with one space. Character references decode as JSX decodes them: the named references of XHTML 1.0 (`&amp;`, `&nbsp;`) and numeric ones. A reference only HTML knows, such as `&check;`, stays as written and warns ([UF3011](/docs/reference/diagnostics#UF3011)).

A string literal child is a JavaScript string: it is neither trimmed nor decoded. Write a significant space or line break as one, `{" "}` or `{"\n"}`:

<!-- prettier-ignore -->
```tsx [ShippingLabel.uf.tsx]
<span class="shipping-label-city">{city}</span>{" "}
<span class="shipping-label-postcode">{postcode}</span>{" "}
<span class="shipping-label-country">United Kingdom</span>
```

Each target writes that space the way its compiler keeps it:

::framework-switcher
#react

<!-- prettier-ignore -->
```tsx [ShippingLabel.tsx]
<span className="shipping-label-city">{city}</span>{" "}
<span className="shipping-label-postcode">{postcode}</span>{" "}
<span className="shipping-label-country">United Kingdom</span>
```

#vue

<!-- prettier-ignore -->
```vue [ShippingLabel.vue]
<span class="shipping-label-city">{{ city }}</span> <span
  class="shipping-label-postcode"
>{{ postcode }}</span> <span class="shipping-label-country">United Kingdom</span>
```

#svelte

<!-- prettier-ignore -->
```svelte [ShippingLabel.svelte]
<span class="shipping-label-city">{city}</span> <span
  class="shipping-label-postcode"
>{postcode}</span> <span class="shipping-label-country">United Kingdom</span>
```

#angular

<!-- prettier-ignore -->
```ts [shipping-label.ts]
<span class="shipping-label-city">{{ city }}</span>&ngsp;<span
  class="shipping-label-postcode"
>{{ postcode }}</span>&ngsp;<span class="shipping-label-country">United Kingdom</span>
```

#solid

<!-- prettier-ignore -->
```tsx [ShippingLabel.tsx]
<span class="shipping-label-city">{props.city}</span>{" "}
<span class="shipping-label-postcode">{props.postcode}</span>{" "}
<span class="shipping-label-country">United Kingdom</span>
```

#qwik

<!-- prettier-ignore -->
```tsx [ShippingLabel.tsx]
<span class="shipping-label-city">{city}</span>{" "}
<span class="shipping-label-postcode">{postcode}</span>{" "}
<span class="shipping-label-country">United Kingdom</span>
```

#astro

<!-- prettier-ignore -->
```astro [ShippingLabel.astro]
<span class="shipping-label-city">{city}</span> <span
  class="shipping-label-postcode"
>{postcode}</span> <span class="shipping-label-country">United Kingdom</span>
```

::

Each output breaks its lines only where its framework drops the whitespace. Svelte keeps the whitespace between tags, so its output closes a tag at the start of the next line (`</p` and then `><p>`), which adds no text to the page.

A line feed that starts the text of a `<pre>`, a `<textarea>` or a `<listing>` is [UF3017](/docs/reference/diagnostics#UF3017): the HTML parser drops it, and React's server renderer adds one. So is a line feed after a conditional or a list that can render nothing: when it does, React's and Astro's servers write nothing before the text, and the other targets a comment.

### Escaping

Text and strings render exactly as written, on every target. The compiler escapes what a template language would read as its own syntax, such as `{{`, `{#if}`, `@if` or `<`:

<!-- prettier-ignore -->
```tsx [TemplateTip.uf.tsx]
<p>Mustache: {"{{ " + path + " }}"}</p>
```

::framework-switcher
#react

<!-- prettier-ignore -->
```tsx [TemplateTip.tsx]
<p>Mustache: {"{{ " + path + " }}"}</p>
```

#vue

<!-- prettier-ignore -->
```vue [TemplateTip.vue]
<p>Mustache: {{ "{{ " + path + " \u007d\u007d" }}</p>
```

#svelte

<!-- prettier-ignore -->
```svelte [TemplateTip.svelte]
><p>Mustache: {"{{ " + path + " }}"}</p
```

#angular

<!-- prettier-ignore -->
```ts [template-tip.ts]
<p>Mustache: {{ "\\u007b\\u007b " + path + " \\u007d\\u007d" }}</p>
```

#solid

<!-- prettier-ignore -->
```tsx [TemplateTip.tsx]
<p>Mustache: {"{{ " + props.path + " }}"}</p>
```

#qwik

<!-- prettier-ignore -->
```tsx [TemplateTip.tsx]
<p>Mustache: {"{{ " + path + " }}"}</p>
```

#astro

<!-- prettier-ignore -->
```astro [TemplateTip.astro]
<p>Mustache: {"{{ " + path + " }}"}</p>
```

::

Vue would end the interpolation at the first `}}`, so its output writes the braces as escapes. Angular's template is a TypeScript template literal, so its backslashes are doubled.

## Conditionals

`c && <A />` renders `<A />` when `c` is truthy. The test is truthiness, as `v-if` does it: `0`, `""` and `NaN` render nothing, never the value. Plain JSX would render the `0` on React, Solid and Astro, but the source means what `v-if` means, on every target.

<!-- prettier-ignore -->
```tsx [InboxSummary.uf.tsx]
{unread && <p>{unread} unread</p>}
```

::framework-switcher
#react

<!-- prettier-ignore -->
```tsx [InboxSummary.tsx]
{unread ? <p>{unread} unread</p> : null}
```

#vue

<!-- prettier-ignore -->
```vue [InboxSummary.vue]
<p v-if="unread">{{ unread }} unread</p>
```

#svelte

<!-- prettier-ignore -->
```svelte [InboxSummary.svelte]
>{#if unread}
  <p>{unread} unread</p>
{/if}{#if flagged}
```

#angular

<!-- prettier-ignore -->
```ts [inbox-summary.ts]
@if (unread) {
  <p>{{ unread }} unread</p>
}
```

#solid

<!-- prettier-ignore -->
```tsx [InboxSummary.tsx]
<Show when={props.unread}>
  <p>{props.unread} unread</p>
</Show>
```

#qwik

<!-- prettier-ignore -->
```tsx [InboxSummary.tsx]
<>{unread ? <p>{unread} unread</p> : null}</>
```

#astro

<!-- prettier-ignore -->
```astro [InboxSummary.astro]
{unread ? (
  <p>{unread} unread</p>
) : null}
```

::

Qwik wraps a conditional that a sibling follows in a fragment, `<>…</>`: its diff inserts a new branch before the one it replaces and moves the siblings after it, which would take a focused sibling's focus.

`c ? <A /> : <B />` chooses between two branches, and a conditional in the else branch extends the chain:

<!-- prettier-ignore -->
```tsx [OrderStatus.uf.tsx]
export interface OrderStatusProps {
  status: "pending" | "shipped" | "delivered" | "cancelled";
  carrier?: string;
  eta?: string;
}

export default function OrderStatus({ status, carrier, eta }: OrderStatusProps) {
  return (
    <p class="order-status">
      {status === "pending" ? (
        "Waiting for payment."
      ) : status === "shipped" ? (
        <>
          <strong>Shipped</strong> with {carrier ?? "our courier"}, arriving {eta ?? "soon"}.
        </>
      ) : status === "delivered" ? (
        <strong>Delivered</strong>
      ) : (
        <em>Cancelled</em>
      )}
    </p>
  );
}
```

::framework-switcher
#react

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

export interface OrderStatusProps {
  status: "pending" | "shipped" | "delivered" | "cancelled";
  carrier?: string;
  eta?: string;
}

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

export default function OrderStatus({
  status,
  carrier,
  eta,
  className,
  style,
  ...attributes
}: OrderStatusProps & OrderStatusAttributes) {
  return (
    <p className={cx("order-status", className)} style={style} {...scopeAttributes(attributes)}>
      {status === "pending" ? (
        "Waiting for payment."
      ) : status === "shipped" ? (
        <>
          <strong>Shipped</strong> with {carrier ?? "our courier"}, arriving {eta ?? "soon"}.
        </>
      ) : status === "delivered" ? (
        <strong>Delivered</strong>
      ) : (
        <em>Cancelled</em>
      )}
    </p>
  );
}

/** 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 [OrderStatus.vue]
<script setup lang="ts">
export interface OrderStatusProps {
  status: "pending" | "shipped" | "delivered" | "cancelled";
  carrier?: string;
  eta?: string;
}

const { status, carrier = undefined, eta = undefined } = defineProps<OrderStatusProps>();
</script>

<template>
  <p class="order-status">
    <template v-if="status === 'pending'">Waiting for payment.</template>
    <template
      v-else-if="status === 'shipped'"
    ><strong>Shipped</strong> with {{ carrier ?? "our courier" }}, arriving {{ eta ?? "soon" }}.</template>
    <strong v-else-if="status === 'delivered'">Delivered</strong>
    <em v-else>Cancelled</em>
  </p>
</template>
```

#svelte

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

<script lang="ts" module>
  export interface OrderStatusProps {
    status: "pending" | "shipped" | "delivered" | "cancelled";
    carrier?: string;
    eta?: string;
  }
</script>

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

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

  let { status, carrier, eta, class: className, style, ...attributes }: Props = $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;
  }
</script>

<p class={["order-status", className]} {style} {...scopeAttributes(attributes)}>
  {#if status === "pending"}Waiting for payment.{:else if status === "shipped"}<strong>Shipped</strong> with {carrier ?? "our courier"}, arriving {eta ?? "soon"}.{:else if status === "delivered"}<strong>Delivered</strong>{:else}<em>Cancelled</em>{/if}
</p>
```

#angular

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

export interface OrderStatusProps {
  status: "pending" | "shipped" | "delivered" | "cancelled";
  carrier?: string;
  eta?: string;
}

/** 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-order-status",
  imports: [ScopeAttributes],
  host: { "[attr.class]": "null", "[attr.style]": "'display: contents;'" },
  preserveWhitespaces: false,
  template: `
    @let status = this.status();
    @let carrier = this.carrier();
    @let eta = this.eta();
    <p class="order-status" [class]="this.class()" [style]="this.style()" [ufScope]="this.host">
      @if (status === "pending") {Waiting for payment.} @else if (status === "shipped") {<strong>Shipped</strong> with {{ carrier ?? "our courier" }}, arriving {{ eta ?? "soon" }}.} @else if (status === "delivered") {<strong>Delivered</strong>} @else {<em>Cancelled</em>}
    </p>
  `,
})
export default class OrderStatus {
  readonly status = input.required<"pending" | "shipped" | "delivered" | "cancelled">();
  readonly carrier = input<string>();
  readonly eta = input<string>();
  readonly class = input<string>();
  readonly style = input<Record<string, string | null | undefined>>();
  protected readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
}
```

#solid

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

export interface OrderStatusProps {
  status: "pending" | "shipped" | "delivered" | "cancelled";
  carrier?: string;
  eta?: string;
}

export default function OrderStatus(
  props: OrderStatusProps & { class?: string; style?: JSX.CSSProperties },
) {
  return (
    <p
      class={props.class ? `order-status ${props.class}` : "order-status"}
      style={props.style}
      {...scopeAttributes(props)}
    >
      <Switch fallback={<em>Cancelled</em>}>
        <Match when={props.status === "pending"}>Waiting for payment.</Match>
        <Match when={props.status === "shipped"}>
          <strong>Shipped</strong> with {props.carrier ?? "our courier"}, arriving{" "}
          {props.eta ?? "soon"}.
        </Match>
        <Match when={props.status === "delivered"}>
          <strong>Delivered</strong>
        </Match>
      </Switch>
    </p>
  );
}

/** 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 [OrderStatus.tsx]
import { type CSSProperties, type ClassList, component$ } from "@qwik.dev/core";

export interface OrderStatusProps {
  status: "pending" | "shipped" | "delivered" | "cancelled";
  carrier?: string;
  eta?: string;
}

export default component$<OrderStatusProps & { class?: ClassList; style?: CSSProperties }>(
  ({ status, carrier, eta, class: className, style, ...attributes }) => {
    return (
      <p class={["order-status", className]} {...scopeAttributes(attributes)} style={style}>
        {status === "pending" ? (
          "Waiting for payment."
        ) : status === "shipped" ? (
          <>
            <strong>Shipped</strong> with {carrier ?? "our courier"}, arriving {eta ?? "soon"}.
          </>
        ) : status === "delivered" ? (
          <strong>Delivered</strong>
        ) : (
          <em>Cancelled</em>
        )}
      </p>
    );
  },
);

/** 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 [OrderStatus.astro]
---
export interface OrderStatusProps {
  status: "pending" | "shipped" | "delivered" | "cancelled";
  carrier?: string;
  eta?: string;
}

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

const { status, carrier, eta, 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;
}
---

<p class:list={["order-status", className]} style={style} {...scopeAttributes(Astro.props)}>
  {status === "pending" ? "Waiting for payment." : status === "shipped" ? <><strong>Shipped</strong> with {carrier ?? "our courier"}, arriving {eta ?? "soon"}.</> : status === "delivered" ? <strong>Delivered</strong> : <em>Cancelled</em>}
</p>
```

::

A branch can be text, an element or several nodes in a fragment. A conditional between two strings, `c ? "a" : "b"`, has no JSX, so it is an expression: it renders text.

A branch often reads what its condition tests. Solid's `<Show>` and `<Match>` take the condition as a prop, by which TypeScript does not narrow their children, so Solid's output hands the narrowed value to the branch through a callback: an accessor of the value itself, or of an object of the values the branch reads, `narrowed`, built inside the source's own condition. Solid calls the callback once while the condition holds, so the branch keeps its elements, and their focus, when the value changes, and reads the latest value through the accessor. A branch whose expressions narrow the value further, as `member.admin ? … : …` does, stays keyed, because TypeScript does not narrow a call: it renders again when its value changes. Here the second `<Show>` is keyed:

<!-- prettier-ignore -->
```tsx [AccountSummary.uf.tsx]
{member && <p>Signed in as {member.email}</p>}
{member ? <p>Role: {member.admin ? "administrator" : "member"}</p> : <p>Role: guest</p>}
{!member ? <p>No profile</p> : <p>Profile of {member.name}</p>}
{member && member.team && <p>Team: {member.team.name}</p>}
{uptime !== undefined && <p>Uptime {uptime.toFixed(1)}%</p>}
```

<!-- prettier-ignore -->
```tsx [AccountSummary.tsx]
<Show when={props.member}>{(member) => <p>Signed in as {member().email}</p>}</Show>
<Show keyed when={props.member} fallback={<p>Role: guest</p>}>
  {(member) => <p>Role: {member.admin ? "administrator" : "member"}</p>}
</Show>
<Show when={props.member} fallback={<p>No profile</p>}>
  {(member) => <p>Profile of {member().name}</p>}
</Show>
<Show when={props.member && props.member.team ? { team: props.member.team } : undefined}>
  {(narrowed) => <p>Team: {narrowed().team.name}</p>}
</Show>
<Show when={props.uptime !== undefined ? { uptime: props.uptime } : undefined}>
  {(narrowed) => <p>Uptime {narrowed().uptime.toFixed(1)}%</p>}
</Show>
```

`x || <B />` and `x ?? <B />` are [UF3025](/docs/reference/diagnostics#UF3025): they render either the value of `x` or an element, which no template language writes as one conditional. Write `x ? x : <B />` for `||`, and `x != null ? x : <B />` for `??`, which renders `0` and `""` as `??` does. Where `x` is a prop rendered as text, the fix writes it.

## Lists

A list is a `.map` child whose callback returns one element with a `key`:

<!-- prettier-ignore -->
```tsx [StepList.uf.tsx]
export interface StepListProps {
  title: string;
  steps: string[];
}

export default function StepList({ title, steps }: StepListProps) {
  return (
    <ol class="step-list" aria-label={title}>
      {steps.map((step, index) => (
        <li key={index} data-step={index + 1}>
          Step {index + 1}: {step}
        </li>
      ))}
    </ol>
  );
}
```

::framework-switcher
#react

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

export interface StepListProps {
  title: string;
  steps: string[];
}

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

export default function StepList({
  title,
  steps,
  className,
  style,
  ...attributes
}: StepListProps & StepListAttributes) {
  return (
    <ol
      className={cx("step-list", className)}
      aria-label={title}
      style={style}
      {...scopeAttributes(attributes)}
    >
      {steps.map((step, index) => (
        <li key={index} data-step={index + 1}>
          Step {index + 1}: {step}
        </li>
      ))}
    </ol>
  );
}

/** 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 [StepList.vue]
<script setup lang="ts">
export interface StepListProps {
  title: string;
  steps: string[];
}

const { title, steps } = defineProps<StepListProps>();
</script>

<template>
  <ol class="step-list" :aria-label="title">
    <li
      v-for="(step, index) in steps"
      :key="index"
      :data-step="index + 1"
    >Step {{ index + 1 }}: {{ step }}</li>
  </ol>
</template>
```

#svelte

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

<script lang="ts" module>
  export interface StepListProps {
    title: string;
    steps: string[];
  }
</script>

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

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

  let { title, steps, class: className, style, ...attributes }: Props = $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;
  }
</script>

<ol class={["step-list", className]} aria-label={title} {style} {...scopeAttributes(attributes)}>
  {#each steps as step, index (index)}
    <li data-step={index + 1}>Step {index + 1}: {step}</li>
  {/each}
</ol>
```

#angular

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

export interface StepListProps {
  title: string;
  steps: string[];
}

/** 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-step-list",
  imports: [ScopeAttributes],
  host: { "[attr.class]": "null", "[attr.style]": "'display: contents;'" },
  preserveWhitespaces: false,
  template: `
    @let title = this.title();
    @let steps = this.steps();
    <ol
      class="step-list"
      [attr.aria-label]="title"
      [class]="this.class()"
      [style]="this.style()"
      [ufScope]="this.host"
    >
      @for (step of steps; track index; let index = $index) {
        <li [attr.data-step]="index + 1">Step {{ index + 1 }}: {{ step }}</li>
      }
    </ol>
  `,
})
export default class StepList {
  readonly title = input.required<string>();
  readonly steps = input.required<string[]>();
  readonly class = input<string>();
  readonly style = input<Record<string, string | null | undefined>>();
  protected readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
}
```

#solid

<!-- prettier-ignore -->
```tsx [StepList.tsx]
import { For, type JSX, createMemo, untrack } from "solid-js";

export interface StepListProps {
  title: string;
  steps: string[];
}

export default function StepList(
  props: StepListProps & { class?: string; style?: JSX.CSSProperties },
) {
  return (
    <ol
      class={props.class ? `step-list ${props.class}` : "step-list"}
      aria-label={props.title}
      style={props.style}
      {...scopeAttributes(props)}
    >
      <KeyedFor each={props.steps} by={(step, index) => index}>
        {(step) => (
          <li data-step={step.index + 1}>
            Step {step.index + 1}: {step.value}
          </li>
        )}
      </KeyedFor>
    </ol>
  );
}

/** 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;
}

/** A list whose rows follow their keys, so a row keeps its element while the list reorders and while its item is replaced. */
function KeyedFor<T>(props: {
  each: readonly T[];
  by: (item: T, index: number) => unknown;
  children: (row: { readonly value: T; readonly index: number }) => JSX.Element;
}): JSX.Element {
  const items = createMemo(() => {
    const rows = new Map<unknown, T>();
    props.each.forEach((item, index) => {
      const key = props.by(item, index);
      rows.set(rows.has(key) ? {} : key, item);
    });
    return rows;
  });
  return (
    <For each={[...items().keys()]}>
      {(key, index) => {
        const item = createMemo(() => items().get(key) as T);
        return untrack(() =>
          props.children({
            get value() {
              return item();
            },
            get index() {
              return index();
            },
          }),
        );
      }}
    </For>
  );
}
```

#qwik

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

export interface StepListProps {
  title: string;
  steps: string[];
}

export default component$<StepListProps & { class?: ClassList; style?: CSSProperties }>(
  ({ title, steps, class: className, style, ...attributes }) => {
    return (
      <ol
        class={["step-list", className]}
        aria-label={title}
        {...scopeAttributes(attributes)}
        style={style}
      >
        {steps.map((step, index) => (
          <li key={index} data-step={index + 1}>
            Step {index + 1}: {step}
          </li>
        ))}
      </ol>
    );
  },
);

/** 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 [StepList.astro]
---
export interface StepListProps {
  title: string;
  steps: string[];
}

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

const { title, steps, 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;
}
---

<ol
  class:list={["step-list", className]}
  aria-label={title}
  style={style}
  {...scopeAttributes(Astro.props)}
>
  {steps.map((step, index) => (
    <li data-step={index + 1}>Step {index + 1}: {step}</li>
  ))}
</ol>
```

::

- The callback is an arrow function with one or two plain parameters: the item, and its index. Read the item's members as `item.name`, rather than destructuring it, and an entry of `Object.entries` as `entry[0]` and `entry[1]` ([UF3015](/docs/reference/diagnostics#UF3015)).
- It returns one element. Filter out an item that renders nothing first: `items.filter((item) => item.done).map(…)`. An item that renders one element or another keeps one keyed element that holds the conditional, and several elements are wrapped in one.
- The element has a `key` that reads the item or its index ([UF3013](/docs/reference/diagnostics#UF3013), [UF3018](/docs/reference/diagnostics#UF3018)). It is a string or a number, unique in the list. It is written `key`, in lower case: in JSX, `KEY` is an attribute ([UF3004](/docs/reference/diagnostics#UF3004), with a fix). A second `key` is [UF3007](/docs/reference/diagnostics#UF3007), and `key` anywhere else is [UF3014](/docs/reference/diagnostics#UF3014).
- The source is an array. When it can be absent, default it: `(items ?? []).map(…)`. For `items?.map(…)`, the compiler reports [UF3018](/docs/reference/diagnostics#UF3018) with a fix that writes the default, or, where `items` is never absent, [UF3023](/docs/reference/diagnostics#UF3023) with a fix that writes `.map`.

<!-- prettier-ignore -->
```tsx [BuildLog.uf.tsx]
{(warnings ?? []).map((warning) => (
  <li key={warning}>{warning}</li>
))}
```

::framework-switcher
#react

<!-- prettier-ignore -->
```tsx [BuildLog.tsx]
{(warnings ?? []).map((warning) => (
  <li key={warning}>{warning}</li>
))}
```

#vue

<!-- prettier-ignore -->
```vue [BuildLog.vue]
<li v-for="warning in warnings ?? []" :key="warning">{{ warning }}</li>
```

#svelte

<!-- prettier-ignore -->
```svelte [BuildLog.svelte]
{#each warnings ?? [] as warning (warning)}
  <li>{warning}</li>
{/each}
```

#angular

<!-- prettier-ignore -->
```ts [build-log.ts]
@for (warning of warnings ?? []; track warning) {
  <li>{{ warning }}</li>
}
```

#solid

<!-- prettier-ignore -->
```tsx [BuildLog.tsx]
<KeyedFor each={props.warnings ?? []} by={(warning) => warning}>
  {(warning) => <li>{warning.value}</li>}
</KeyedFor>
```

#qwik

<!-- prettier-ignore -->
```tsx [BuildLog.tsx]
{(warnings ?? []).map((warning) => (
  <li key={warning}>{warning}</li>
))}
```

#astro

<!-- prettier-ignore -->
```astro [BuildLog.astro]
{(warnings ?? []).map((warning) => (
  <li>{warning}</li>
))}
```

::

Each target writes its own list. Solid's `<For>` follows the items themselves, so its list goes through an inline helper, `KeyedFor`, which keys each row by the source's `key`, as `by`, and passes each row an object of getters, `warning.value` and `warning.index`, which TypeScript narrows as it narrows a prop. Astro renders on the server only, so its output leaves the key out. An unread index is left out too.

A list renders its items' content in the array's order on every target, and a keyed item keeps its element, with what was typed into it, while the array reorders or replaces it. Its focus stays where it keeps its place ([Semantics](/docs/reference/semantics#keyed-lists)). Astro renders a list once, on the server.

## Fragments

A fragment groups nodes without an element. It can be the component's root, a branch of a conditional, or a run of children, which it flattens into its parent:

<!-- prettier-ignore -->
```tsx [ArticleHeader.uf.tsx]
export interface ArticleHeaderProps {
  title: string;
  subtitle?: string;
  draft: boolean;
  tags: string[];
}

export default function ArticleHeader({ title, subtitle, draft, tags }: ArticleHeaderProps) {
  return (
    <>
      <h2>{title}</h2>
      {subtitle && <p class="article-subtitle">{subtitle}</p>}
      {draft ? (
        <>
          <p class="article-badge">Draft</p>
          <p>Only editors can see this article.</p>
        </>
      ) : (
        <>
          <p class="article-badge">Published</p>
          <p>Everyone can read this article.</p>
        </>
      )}
      <p>
        Tagged <>{tags.join(", ")}</>
      </p>
    </>
  );
}
```

Each target groups a branch's nodes its own way:

::framework-switcher
#react

<!-- prettier-ignore -->
```tsx [ArticleHeader.tsx]
{draft ? (
  <>
    <p className="article-badge">Draft</p>
    <p>Only editors can see this article.</p>
  </>
) : (
  <>
    <p className="article-badge">Published</p>
    <p>Everyone can read this article.</p>
  </>
)}
```

#vue

<!-- prettier-ignore -->
```vue [ArticleHeader.vue]
<template v-if="draft">
  <p class="article-badge">Draft</p>
  <p>Only editors can see this article.</p>
</template>
<template v-else>
  <p class="article-badge">Published</p>
  <p>Everyone can read this article.</p>
</template>
```

#svelte

<!-- prettier-ignore -->
```svelte [ArticleHeader.svelte]
>{#if subtitle}
  <p class="article-subtitle">{subtitle}</p>
{/if}{#if draft}
  <p class="article-badge">Draft</p
  ><p>Only editors can see this article.</p>
{:else}
  <p class="article-badge">Published</p
  ><p>Everyone can read this article.</p>
{/if}<p>Tagged {tags.join(", ")}</p>
```

#angular

<!-- prettier-ignore -->
```ts [article-header.ts]
@if (draft) {
  <p class="article-badge">Draft</p>
  <p>Only editors can see this article.</p>
} @else {
  <p class="article-badge">Published</p>
  <p>Everyone can read this article.</p>
}
```

#solid

<!-- prettier-ignore -->
```tsx [ArticleHeader.tsx]
<Show
  when={props.draft}
  fallback={
    <>
      <p class="article-badge">Published</p>
      <p>Everyone can read this article.</p>
    </>
  }
>
  <p class="article-badge">Draft</p>
  <p>Only editors can see this article.</p>
</Show>
```

#qwik

<!-- prettier-ignore -->
```tsx [ArticleHeader.tsx]
{draft ? (
  <>
    <p class="article-badge">Draft</p>
    <p>Only editors can see this article.</p>
  </>
) : (
  <>
    <p class="article-badge">Published</p>
    <p>Everyone can read this article.</p>
  </>
)}
```

#astro

<!-- prettier-ignore -->
```astro [ArticleHeader.astro]
{draft ? (
  <>
    <p class="article-badge">Draft</p>
    <p>Only editors can see this article.</p>
  </>
) : (
  <>
    <p class="article-badge">Published</p>
    <p>Everyone can read this article.</p>
  </>
)}
```

::

On Angular, a root fragment renders inside the component's host element, which is styled `display: contents` (see [Targets](/docs/reference/targets#the-angular-host)).

## Where nodes can go

The HTML parser repairs some markup, and server-rendered HTML then differs from a client's DOM. The nesting rules ([UF3003](/docs/reference/diagnostics#UF3003)) look through conditionals, lists and fragments:

- rows that a `.map` renders directly in a `<table>` would get a `<tbody>`: write it;
- an expression renders text, so it cannot sit where text cannot, such as a table part, a `<select>` or a `<datalist>`;
- a `<textarea>`'s content is its value, so it holds only static text: bind its value with `v-model` ([Models](/docs/components/models#form-controls));
- an `<iframe>`'s content is raw text, which the servers would escape and a browser never shows: remove it.

## Values outside the contract

The outputs render the same DOM for every value a prop's type allows, with these exceptions. Avoid them: the compiler cannot see them, and the targets render them differently.

- Two items with the same key in one list, and arrays with holes.
- `NaN` and the infinities, wherever they would render: as text, in an attribute or in a style. (As a condition, `NaN` is falsy everywhere.)
- A number outside a numeric attribute's range, such as `rows={0}`.
- An empty string bound to a URL attribute, and a bound `javascript:` or `data:` URL.
- A string that starts with a line feed as the first child of a `<pre>` or a `<listing>`, or after an expression that renders `""` there.
- A class name that two parts of one `class` both produce.
- A style value that holds `;` or `!important`.
- An object passed to a spread with keys its type does not declare: they are not rendered.

The decisions behind this page are [ADR-0002](https://github.com/uxfront-com/unframework/blob/main/docs/adrs/0002-control-flow-is-plain-js.md), [ADR-0030](https://github.com/uxfront-com/unframework/blob/main/docs/adrs/0030-jsx-text-and-bare-attributes.md), [ADR-0035](https://github.com/uxfront-com/unframework/blob/main/docs/adrs/0035-render-expressions.md), [ADR-0036](https://github.com/uxfront-com/unframework/blob/main/docs/adrs/0036-control-flow-children-and-lists.md) and [ADR-0046](https://github.com/uxfront-com/unframework/blob/main/docs/adrs/0046-state-and-derived-values-on-every-target.md).
