Skip to main content

The <slot> Element

As defined in the HTML Living Standard, the <slot> element is a placeholder inside a web component that you can fill with your own custom markup, which lets you create separate DOM trees and present them together.

Conceptual Visualization:
<simple-card>
  <h2 slot="title">My Card</h2>
  <p>This content goes into the default slot</p>
</simple-card>

The component defines where the "title" slot and the default slot appear in its internal template.

<template> <header> <slot name="title">Default Title</slot> </header> <main> <slot></slot> <!-- Default slot --> </main> </template> View HTML Living Standard: The slot element

Accessibility: The Flattened Tree

A major concern with Web Components is how assistive technology perceives content that is split between the "Light DOM" (user markup) and "Shadow DOM" (internal template).

WCAG Requirement: Info and Relationships

Success Criterion 1.3.1 (Level A): Information, structure, and relationships conveyed through presentation can be programmatically determined.

Browsers resolve the relationship between content and its container by creating a flattened accessibility tree. Even though the <h2> in the example above is technically a child of the <simple-card> in the main DOM, it is announced as being inside the component's <header> because of the <slot> placement. This ensures that the structural relationships remain perceivable for screen reader users.

Understand SC 1.3.1: Info and Relationships

Technical Patterns

<!-- Template fallback example --> <slot name="icon"> <img src="default-icon.png" alt="Informational icon"> </slot>

Best Practices

A11y Tip: Logical Focus

Ensure that slotting content doesn't break the natural reading or tab order. When content is "moved" into a slot, it should still make sense within the sequential flow of the component's internal design, satisfying WCAG SC 2.4.3 (Focus Order).