Embed YouTube, Mermaid & Recharts in Next.js, No Plugins
Complete guide to embedding YouTube, Mermaid, and Recharts in a Next.js blog without plugins. Boost engagement by 52% with consistent styling and dark mode.
๐ Introduction
In the 2026 developer blog landscape, interactive content like videos, diagrams, and charts is key to boosting engagement and SEO. However, most tutorials only cover basic embedding using plugins or iframes, without addressing consistent styling and reader experience. This guide will show you how to:
- Embed YouTube videos without plugins (iframe fallback)
- Create Mermaid diagrams directly from code (diagrams as code)
- Display interactive Recharts with dark/light mode styling
- Implement editor windows for consistent styling (traffic dots, filename, line numbers, copy button)
All of this is done without external plugins, reducing bundle size and improving your blogโs performance.
๐ง Prerequisites
Before you begin, ensure you have: - Next.js 14+ (App Router) - Node.js 20+ - Basic knowledge: React, Markdown, CSS
๐ฅ Embed YouTube Without Plugins
Method: iframe Fallback
You donโt need external libraries to embed YouTube. Simply use an iframe with the right parameters:
<iframe
width="560"
height="315"
src="https://www.youtube.com/embed/VIDEO_ID?rel=0"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>Key parameters: - rel=0: disable
related videos at the end - autoplay=1 (optional): autoplay
video (works in some browsers only)
Responsive Styling
Use this CSS to ensure videos are responsive on all devices:
.responsive-iframe {
position: relative;
width: 100%;
padding-bottom: 56.25%; /* 16:9 aspect ratio */
height: 0;
overflow: hidden;
}
.responsive-iframe iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}Editor Window for YouTube
For consistency with code blocks, use editor window styling:
<div class="editor-window">
<div class="editor-header">
<span class="traffic-dots">
<span class="dot red"></span>
<span class="dot yellow"></span>
<span class="dot green"></span>
</span>
<span class="filename">youtube-embed.mp4</span>
<button class="copy-button">Copy</button>
</div>
<div class="editor-content">
<iframe ...></iframe>
</div>
</div>Example in Markdown:
{{youtube:VIDEO_ID}}๐ Embed Mermaid (Diagrams as Code)
Setup in Next.js
- Install Mermaid:
npm install mermaid- Create a
MermaidDiagramcomponent:
'use client';
import { useEffect } from 'react';
import mermaid from 'mermaid';
export default function MermaidDiagram({ chart }: { chart: string }) {
useEffect(() => {
mermaid.initialize({
startOnLoad: true,
theme: 'default',
darkMode: true,
});
mermaid.contentLoaded();
}, [chart]);
return <div className="mermaid">{chart}</div>;
}
- Use it in your page:
<MermaidDiagram chart={`
graph LR;
A[Start] --> B{Decision};
B -->|Yes| C[Do Something];
B -->|No| D[Do Nothing];
`} />
Basic Mermaid Syntax
| Diagram Type | Example Code |
|---|---|
| Flowchart | graph TD; A-->B; B-->C; |
| Sequence | sequenceDiagram; A->>B: Hello; |
| Gantt | gantt; title Project; section Phase 1; Task 1: 2026-08-01, 7d; |
Editor Window for Mermaid
<div class="editor-window">
<div class="editor-header">
<span class="traffic-dots">
<span class="dot red"></span>
<span class="dot yellow"></span>
<span class="dot green"></span>
</span>
<span class="filename">diagram.mmd</span>
<button class="copy-button">Copy</button>
</div>
<div class="editor-content">
<div class="mermaid">
graph LR;
A-->B;
B-->C;
</div>
</div>
</div>Example in Markdown:
{{mermaid:B64}}Note:
B64is the base64 of the diagram source (without padding). Example in Python:import base64 src = "graph LR; A-->B;" b64 = base64.urlsafe_b64encode(src.encode()).rstrip(b'=').decode()
๐ Embed Recharts (Interactive Charts)
Setup in Next.js
- Install Recharts:
npm install recharts- Create a
CustomChartcomponent:
'use client';
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from 'recharts';
export default function CustomChart({ data }: { data: any[] }) {
return (
<ResponsiveContainer width="100%" height={300}>
<LineChart data={data}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="name" />
<YAxis />
<Tooltip content={<CustomTooltip />} />
<Line type="monotone" dataKey="pv" stroke="#8884d8" />
</LineChart>
</ResponsiveContainer>
);
}
function CustomTooltip({ active, payload, label }: any) {
if (active && payload && payload.length) {
return (
<div className="custom-tooltip">
<p className="label">{`${label} : ${payload[0].value}`}</p>
</div>
);
}
return null;
}
- Use it in your page:
const data = [
{ name: 'Jan', pv: 2400 },
{ name: 'Feb', pv: 1398 },
{ name: 'Mar', pv: 9800 },
];
<CustomChart data={data} />
Supported Chart Types
| Chart Type | Component |
|---|---|
| Line | <LineChart> |
| Bar | <BarChart> |
| Pie | <PieChart> |
| Area | <AreaChart> |
| Scatter | <ScatterChart> |
Editor Window for Recharts
<div class="editor-window">
<div class="editor-header">
<span class="traffic-dots">
<span class="dot red"></span>
<span class="dot yellow"></span>
<span class="dot green"></span>
</span>
<span class="filename">chart-data.json</span>
<button class="copy-button">Copy</button>
</div>
<div class="editor-content">
<div class="recharts-container">
<ResponsiveContainer ...>
<LineChart ...>
...
</LineChart>
</ResponsiveContainer>
</div>
</div>
</div>Example in Markdown:
{{recharts:B64}}Note:
B64is the base64 of the Recharts JSON spec. Example:{ "data": [{"name": "Jan", "pv": 2400}], "xAxis": {"dataKey": "name"}, "series": [{"dataKey": "pv"}] }
๐จ Consistent Styling for Embeds
Editor Windows
Use the following styling for consistency across all embeds:
.editor-window {
border: 1px solid #e2e8f0;
border-radius: 8px;
overflow: hidden;
margin: 1.5rem 0;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.editor-header {
background: #f8fafc;
padding: 0.5rem 1rem;
display: flex;
align-items: center;
gap: 0.5rem;
border-bottom: 1px solid #e2e8f0;
}
.traffic-dots {
display: flex;
gap: 0.25rem;
}
.dot {
width: 12px;
height: 12px;
border-radius: 50%;
}
.dot.red { background: #ef4444; }
.dot.yellow { background: #f59e0b; }
.dot.green { background: #10b981; }
.filename {
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
font-size: 0.875rem;
color: #4a5568;
flex-grow: 1;
}
.copy-button {
background: #3b82f6;
color: white;
border: none;
border-radius: 4px;
padding: 0.25rem 0.5rem;
font-size: 0.75rem;
cursor: pointer;
}
.copy-button:hover {
background: #2563eb;
}
.editor-content {
padding: 1rem;
}
/* Dark mode */
@media (prefers-color-scheme: dark) {
.editor-window {
border-color: #4a5568;
}
.editor-header {
background: #2d3748;
border-bottom-color: #4a5568;
}
.filename {
color: #cbd5e0;
}
}Dark/Light Mode
Use prefers-color-scheme to support dark/light mode:
/* Light mode (default) */
.mermaid { background: white; }
/* Dark mode */
@media (prefers-color-scheme: dark) {
.mermaid { background: #1a202c; }
}โ ๏ธ Security Risks & Mitigations
| Risk | Cause | Solution |
|---|---|---|
| XSS (YouTube) | srcdoc parameter in iframe |
Sanitize input, use direct src |
| Injection (Mermaid) | Diagram code from user | Sanitize input, use CSP (Content Security Policy) |
| Data Leakage (Recharts) | Sensitive data in charts | Validate data before rendering |
Example CSP for Mermaid:
Content-Security-Policy: script-src 'self' https://cdn.jsdelivr.net/npm/mermaid@10;
๐ Case Study: Developer Blog Engagement
2026 Data
| Metric | Before Embed | After Embed | Improvement |
|---|---|---|---|
| Dwell Time | 2.1 minutes | 3.2 minutes | +52% |
| CTR | 3.1% | 4.8% | +55% |
| Bounce Rate | 68% | 52% | -24% |
Source: Developer Educators 2026
Implementation Example
The adityo.web.id blog uses editor windows for code blocks and embeds, resulting in: - 30% increase in dwell time - 18% reduction in bounce rate - 22% increase in social media shares
๐ FAQ
1. How to embed YouTube in Next.js without plugins?
Use an iframe fallback with the rel=0 parameter to
disable related videos. Example:
{{youtube:VIDEO_ID}}2. What are the advantages of Mermaid over other tools?
- Native support in GitHub, GitLab, Notion, Obsidian
- Diagrams as code: easy to maintain and version control
- 87% of developers prefer it (2026 survey, starmorph.com)
3. Is Recharts better than Chart.js?
- Tree-shaken: 30% smaller bundle size
- Interactive: tooltip, zoom, pan out-of-the-box
- Dark mode: built-in support
4. How to ensure consistent styling for embeds?
Use editor windows with: - Traffic dots (red/yellow/green) - Filename (monospace) - Line numbers (for code) - Copy button
5. What are the security risks when embedding external content?
- YouTube: XSS via
srcdocโ sanitize input - Mermaid: injection via diagram code โ CSP + sanitization
- Recharts: data leakage โ validate data
๐ Conclusion
Embedding interactive content (YouTube, Mermaid, Recharts) in a Next.js blog without plugins offers many benefits:
โ Increased engagement (dwell time +52%, CTR +55%) โ Improved SEO (bounce rate -24%) โ Better reader experience (consistent styling, dark/light mode) โ Better performance (smaller bundle size without plugins)
By following this guide, you can: 1. Embed YouTube videos without plugins (iframe fallback) 2. Create Mermaid diagrams directly from code (diagrams as code) 3. Display interactive Recharts with dark/light mode styling 4. Implement editor windows for consistent styling
Next steps: - Implement on your blog and measure engagement metrics - Experiment with other diagram/chart types (Gantt, Pie, Scatter) - Share this article in developer communities for feedback
๐ References
- Recharts + Next.js 15 Tutorial (2026)
- Mermaid.js Tutorial (2026)
- YouTube Embed Best Practices (2024)
- Developer Engagement Data (2026)
- Next.js Documentation