CodePen
Embed CodePen projects into VitePress pages.
Installation
sh
pnpm add vitepress-plugin-codepensh
npm install vitepress-plugin-codepensh
bun add vitepress-plugin-codepensh
deno add vitepress-plugin-codepensh
yarn add vitepress-plugin-codepenUsage
vitepress-tuck Mode Recommended
ts
import { defineConfig } from 'vitepress-tuck'
import codepen from 'vitepress-plugin-codepen'
export default defineConfig({
plugins: [codepen()],
})Learn more about vitepress-tuck
Native Mode
ts
import { defineConfig } from 'vitepress'
import { codepenPlugin } from 'vitepress-plugin-codepen'
export default defineConfig({
markdown: {
config: (md) => {
md.use(codepenPlugin)
},
},
})ts
import type { Theme } from 'vitepress'
import { enhanceAppWithCodepen } from 'vitepress-plugin-codepen/client'
import DefaultTheme from 'vitepress/theme'
export default {
extends: DefaultTheme,
enhanceApp(ctx) {
enhanceAppWithCodepen(ctx)
},
} satisfies ThemeSyntax
Basic Usage
md
@[codepen](user/slash)With Options
md
@[codepen preview editable title="Example" height="400px" tab="css,result" theme="dark"](leimapapa/RwOZQOW)Attribute Reference
| Attribute | Type | Default | Description |
|---|---|---|---|
title | string | - | Title |
user | string | - | CodePen username (parsed from link) |
slash | string | - | Pen identifier (parsed from link) |
tab | string | 'result' | Default tab to display |
theme | string | - | Theme |
preview | boolean | false | Preview mode |
editable | boolean | false | Editable mode |
width | string | '100%' | Width |
height | string | - | Height |
Example
md
@[codepen](leimapapa/RwOZQOW)