Skip to Content
rehype-code-group

HTML output

The exact markup the plugin generates and the attributes the client changes, for styling, testing and custom clients.

The generated markup is the contract between the plugin, the client and your CSS. This rich group:

:::: code-group label="Runtime" default="bun" sync="runtime" persist="local"

::: code-tab label="Node.js" value="node"

```sh
node app.js
```

:::

::: code-tab label="Bun" value="bun"

```sh
bun app.ts
```

:::

::::

becomes this HTML, formatted here for reading:

<div
  class="rehype-code-group"
  data-rcg-sync="runtime"
  data-rcg-persist="local"
>
  <div class="rcg-tab-container" role="tablist" aria-label="Runtime">
    <button
      type="button"
      class="rcg-tab"
      role="tab"
      aria-selected="false"
      aria-controls="rcg-0-block-0"
      data-rcg-value="node"
      id="rcg-0-tab-0"
      tabindex="-1"
    >
      Node.js
    </button>
    <button
      type="button"
      class="rcg-tab active"
      role="tab"
      aria-selected="true"
      aria-controls="rcg-0-block-1"
      data-rcg-value="bun"
      id="rcg-0-tab-1"
      tabindex="0"
    >
      Bun
    </button>
  </div>
  <div
    class="rcg-block"
    role="tabpanel"
    aria-labelledby="rcg-0-tab-0"
    data-rcg-label="Node.js"
    id="rcg-0-block-0"
  >
    <pre><code class="language-sh">node app.js</code></pre>
  </div>
  <div
    class="rcg-block active"
    role="tabpanel"
    aria-labelledby="rcg-0-tab-1"
    data-rcg-label="Bun"
    id="rcg-0-block-1"
  >
    <pre><code class="language-sh">bun app.ts</code></pre>
  </div>
</div>

A compact group produces the same structure, without the data-rcg-sync, data-rcg-persist and data-rcg-orientation attributes, and with aria-label="Code examples".

Attributes on the group

AttributeSet byMeaning
data-rcg-syncpluginThe sync key.
data-rcg-persistpluginlocal or url.
data-rcg-orientationpluginhorizontal or vertical. The tab list also gets a matching aria-orientation.
data-rcg-active-tab-classespluginPresent when activeTabClass is customized. The classes the client toggles.
data-rcg-active-block-classespluginPresent when activeBlockClass is customized.
data-rcg-enhancedclientAdded once the client has set the group up.

Attributes on tabs and panels

AttributeOnMeaning
data-rcg-valuetabThe value used by default, sync, persist, and the change event.
aria-selected, tabindextabSet by the plugin for the default tab, then kept current by the client.
data-rcg-labelpanelThe tab's label, shown above each panel when printing.
hiddenpanelAdded by the client to every panel except the selected one.

What the client changes

The client never adds or removes elements. On setup and on every selection, it only updates:

  • aria-selected and tabindex on tabs,
  • the active classes on tabs and panels,
  • hidden on panels,
  • data-rcg-enhanced on the group, once.

The selected value is also written to local storage or the URL when persist is set.

Edit on GitHub