Media directives embed external content like videos, code playgrounds, and terminal recordings into your documentation. All embeds are privacy-respecting by default and meet WCAG 2.1 AA accessibility requirements.
Quick Reference
| Directive | Purpose | Required Options |
|---|---|---|
{youtube} |
YouTube video | :title: |
{vimeo} |
Vimeo video | :title: |
{video} |
Self-hosted video | :title: |
{figure} |
Image with caption | :alt: |
{audio} |
Self-hosted audio | :title: |
{gist} |
GitHub Gist | — |
{codepen} |
CodePen embed | :title: |
{codesandbox} |
CodeSandbox embed | :title: |
{stackblitz} |
StackBlitz embed | :title: |
{asciinema} |
Terminal recording | :title: |
Video Embeds
YouTube
Embed YouTube videos with privacy-enhanced mode enabled by default (youtube-nocookie.com).
Syntax:
1 2 3 | |
Options:
| Option | Default | Description |
|---|---|---|
:title: |
(required) | Accessible title for the iframe |
:privacy: |
true |
Useyoutube-nocookie.com |
:start: |
— | Start time in seconds |
:end: |
— | End time in seconds |
:autoplay: |
false |
Auto-start video |
:muted: |
false |
Start muted (required with autoplay) |
:loop: |
false |
Loop video |
:controls: |
true |
Show player controls |
:aspect: |
16/9 |
Aspect ratio (16/9,4/3,21/9) |
:class: |
— | Additional CSS classes |
Example: Examples
Basic embed:
1 2 3 | |
With start time and custom aspect ratio:
1 2 3 4 5 | |
Background video (autoplay, muted, looped, no controls):
1 2 3 4 5 6 7 | |
Vimeo
Embed Vimeo videos with Do Not Track enabled by default.
Syntax:
1 2 3 | |
Options:
| Option | Default | Description |
|---|---|---|
:title: |
(required) | Accessible title for the iframe |
:dnt: |
true |
Enable Do Not Track mode |
:color: |
— | Player accent color (hex without#) |
:background: |
false |
Background mode (no controls) |
:autoplay: |
false |
Auto-start video |
:muted: |
false |
Start muted |
:loop: |
false |
Loop video |
:aspect: |
16/9 |
Aspect ratio |
:class: |
— | Additional CSS classes |
Example: Examples
Basic embed:
1 2 3 | |
With custom color:
1 2 3 4 | |
Self-Hosted Video
Embed videos from your own server using HTML5<video>.
Syntax:
1 2 3 | |
Options:
| Option | Default | Description |
|---|---|---|
:title: |
(required) | Accessible title |
:poster: |
— | Poster image path |
:autoplay: |
false |
Auto-start video |
:muted: |
false |
Start muted |
:loop: |
false |
Loop video |
:controls: |
true |
Show player controls |
:preload: |
metadata |
Preload strategy (none,metadata,auto) |
:aspect: |
16/9 |
Aspect ratio |
:class: |
— | Additional CSS classes |
Supported formats:.mp4,.webm,.ogg,.mov
Example: Examples
Basic embed:
1 2 3 | |
With poster and options:
1 2 3 4 5 | |
Figure (Images with Captions)
Create semantic<figure>elements with optional captions, links, and alignment.
Syntax:
1 2 3 4 | |
Options:
| Option | Default | Description |
|---|---|---|
:alt: |
(required) | Alt text (empty for decorative images) |
:caption: |
— | Caption text below image |
:width: |
— | Image width (80%,500px) |
:height: |
— | Image height |
:align: |
— | Alignment (left,center,right) |
:link: |
— | URL to link image to |
:target: |
— | Link target (_blankfor new tab) |
:loading: |
lazy |
Loading strategy (lazy,eager) |
:class: |
— | Additional CSS classes |
Supported formats:.png,.jpg,.jpeg,.gif,.webp,.svg,.avif
Example: Examples
Basic figure with alt text:
1 2 3 | |
With caption and alignment:
1 2 3 4 5 6 | |
Linked image opening in new tab:
1 2 3 4 5 | |
Decorative image (empty alt):
1 2 3 | |
Audio
Embed self-hosted audio files using HTML5<audio>.
Syntax:
1 2 3 | |
Options:
| Option | Default | Description |
|---|---|---|
:title: |
(required) | Accessible title |
:autoplay: |
false |
Auto-start audio |
:loop: |
false |
Loop audio |
:controls: |
true |
Show player controls |
:preload: |
metadata |
Preload strategy |
:class: |
— | Additional CSS classes |
Supported formats:.mp3,.ogg,.wav,.m4a
Example: Examples
Basic audio:
1 2 3 | |
Background audio:
1 2 3 4 5 6 | |
Code Playground Embeds
GitHub Gist
Embed GitHub Gists with optional file selection.
Syntax:
1 2 3 | |
Options:
| Option | Default | Description |
|---|---|---|
:file: |
— | Specific file from multi-file gist |
Example: Examples
Basic gist:
1 2 | |
Specific file:
1 2 3 | |
CodePen
Embed CodePen pens.
Syntax:
1 2 3 | |
Options:
| Option | Default | Description |
|---|---|---|
:title: |
(required) | Accessible title |
:default-tab: |
result |
Default tab (html,css,js,result) |
:theme: |
dark |
Theme (dark,light) |
:height: |
400 |
Embed height in pixels |
:class: |
— | Additional CSS classes |
Example: Examples
Basic embed:
1 2 3 | |
With HTML tab visible:
1 2 3 4 5 | |
CodeSandbox
Embed CodeSandbox projects.
Syntax:
1 2 3 | |
Options:
| Option | Default | Description |
|---|---|---|
:title: |
(required) | Accessible title |
:module: |
— | Initial file to open (/src/App.js) |
:view: |
split |
View mode (editor,preview,split) |
:height: |
500 |
Embed height in pixels |
:class: |
— | Additional CSS classes |
Example: Examples
Basic embed:
1 2 3 | |
With specific file:
1 2 3 4 5 | |
StackBlitz
Embed StackBlitz projects.
Syntax:
1 2 3 | |
Options:
| Option | Default | Description |
|---|---|---|
:title: |
(required) | Accessible title |
:file: |
— | Initial file to open |
:view: |
both |
View mode (editor,preview,both) |
:height: |
500 |
Embed height in pixels |
:class: |
— | Additional CSS classes |
Example: Examples
Basic embed:
1 2 3 | |
With specific file:
1 2 3 4 5 | |
Terminal Recordings
Asciinema
Embed terminal recordings from asciinema.org.
Syntax:
1 2 3 | |
Options:
| Option | Default | Description |
|---|---|---|
:title: |
(required) | Accessible ARIA label |
:cols: |
— | Terminal width in columns |
:rows: |
— | Terminal height in rows |
:speed: |
1.0 |
Playback speed multiplier |
:autoplay: |
false |
Auto-start playback |
:loop: |
false |
Loop recording |
:preload: |
false |
Preload recording data |
:class: |
— | Additional CSS classes |
Example: Examples
Basic embed:
1 2 3 | |
With custom size and speed:
1 2 3 4 5 6 7 | |
Accessibility Requirements
All media embeds follow WCAG 2.1 AA guidelines:
- Required titles: All iframes require a
:title:option for screen readers - Alt text: Figures require
:alt:text (use empty string for decorative images) - Fallback content: All embeds include
<noscript>fallbacks with direct links - Keyboard navigation: Video/audio players support keyboard controls
- ARIA labels: Terminal recordings use
role="img"andaria-label
Privacy Features
Media embeds are privacy-respecting by default:
- YouTube: Uses
youtube-nocookie.com(disable with:privacy: false) - Vimeo: Enables Do Not Track (disable with
:dnt: false) - No third-party tracking: Self-hosted options available for video, audio, figures
Security
All media directives validate inputs to prevent:
- XSS attacks: ID/URL validation rejects malicious input
- Path traversal: Local paths cannot escape content directory
- Iframe sandboxing: External embeds use restricted sandbox attributes
Responsive Design
All embeds use CSSaspect-ratiofor fluid responsive layouts:
1 2 3 4 | |
Override the aspect ratio with the:aspect:option or custom CSS classes.
Related
- Layout Directives - Cards, tabs, grids
- Interactive Directives - Code tabs, data tables
- Hugo Migration - Migrating from Hugo shortcodes