<!-- Source: https://scoped.svelte.page/examples/explicit-literal -->

# Explicit Literal

> A literal scoped:class example where a parent-scoped class reaches a child component only when the call site opts in.

**Source:** [https://scoped.svelte.page/examples/explicit-literal](https://scoped.svelte.page/examples/explicit-literal)

**Markdown mirror:** [https://scoped.svelte.page/examples/explicit-literal.md](https://scoped.svelte.page/examples/explicit-literal.md)

---

This mirror preserves the prose, implementation notes, and runnable Svelte source behind the live example page.

## FIG-001: explicit literal.

The smallest useful proof: a native element and a child component both use the same parent-owned class, but the child only gets the parent hash through `scoped:class`.

**Metadata:** tag: `SCOPED CLASS` | syntax: `scoped:class` | value: `string literal` | status: `passing`

### Source

#### ExplicitLiteral.svelte

Source file: [src/lib/examples/scoped-props/demos/ExplicitLiteral.svelte](https://github.com/humanspeak/svelte-scoped-props/blob/main/docs/src/lib/examples/scoped-props/demos/ExplicitLiteral.svelte)

```svelte
<script lang="ts">
    import ChildCard from './components/ChildCard.svelte'
</script>

<article class="scoped-proof passed dk-demo-shell">
    <div class="render-grid">
        <div class="render-example">
            <span class="example-label">Native element</span>
            <div class="demo-card parent-owned">This div receives the scoped parent class.</div>
        </div>
        <div class="render-example">
            <span class="example-label">Child component</span>
            <ChildCard scoped:class="parent-owned" />
        </div>
    </div>

    <div class="example-grid">
        <div class="example-block">
            <span class="example-label">Source</span>
            <code>&lt;div class="demo-card parent-owned"&gt;</code>
            <code>&lt;ChildCard scoped:class="parent-owned" /&gt;</code>
        </div>
        <div class="example-block">
            <span class="example-label">Current result</span>
            <ul class="result-list">
                <li>
                    <span>Native element</span>
                    <code>demo-card parent-owned svelte-parent</code>
                    <strong>baseline</strong>
                </li>
                <li>
                    <span>Child component</span>
                    <code>child-card parent-owned svelte-parent svelte-child</code>
                    <strong>has parent hash</strong>
                </li>
            </ul>
        </div>
    </div>
</article>

<style>
    .parent-owned {
        border-color: var(--proof-parent-border, purple);
        color: var(--proof-parent-ink, purple);
        background: var(--proof-parent-bg, pink);
    }
</style>
```

#### ChildCard.svelte

Source file: [src/lib/examples/scoped-props/demos/components/ChildCard.svelte](https://github.com/humanspeak/svelte-scoped-props/blob/main/docs/src/lib/examples/scoped-props/demos/components/ChildCard.svelte)

```svelte
<script lang="ts">
    import type { ClassValue } from '@humanspeak/svelte-scoped-props/runtime'
    import { describeClass } from './classValue'

    type Props = {
        class?: ClassValue
        'scoped:class'?: ClassValue
    }

    let { class: className }: Props = $props()
    let classText = $derived(describeClass(className))
</script>

<div class={['child-card', className]}>
    Child receives <code>class="{classText}"</code>.
</div>

<style>
    .child-card {
        min-height: 116px;
        display: grid;
        place-items: center;
        padding: 18px;
        border: 2px dashed var(--proof-card-border, gray);
        border-radius: 6px;
        color: var(--proof-card-ink, black);
        text-align: center;
        background: var(--proof-card-bg, white);
    }

    code {
        padding: 2px 5px;
        border-radius: 4px;
        overflow-wrap: anywhere;
        background: var(--proof-code-bg, #eef2f7);
        color: var(--proof-code-ink, #111111);
        font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
        font-size: 0.95em;
    }
</style>
```
