Excalidraw Diagrams
Complete guide to embedding interactive Excalidraw diagrams
Excalidraw Diagrams
Excalidraw diagrams allow you to embed interactive diagrams in your documentation. These diagrams support theme switching, fullscreen mode, and zoom controls.
Overview
Excalidraw is a virtual whiteboard for sketching hand-drawn like diagrams. You can create diagrams in Excalidraw and embed them in your documentation with full interactivity.
Features
- ✅ Theme Support: Automatically matches your website's theme (light/dark)
- ✅ Fullscreen Mode: Click the fullscreen button to view in fullscreen
- ✅ Zoom Controls: Zoom in, zoom out, and reset zoom
- ✅ Centered Display: Diagrams are automatically centered
- ✅ Responsive: Adapts to different screen sizes
- ✅ Clean UI: Default Excalidraw UI elements are hidden for a clean look
Step 1: Create Your Diagram
- Go to Excalidraw
- Create your diagram
- Click the menu (three dots) → Save to file
- Save as
.excalidrawfile (JSON format)
Step 2: Save the File
Save your .excalidraw file in the public/assets/docs/ directory:
Step 3: Embed in Your Content
Use the <ExcalidrawDiagram> component in your MDX:
Component Props
Required Props
src: Path to the.excalidrawfile (relative topublic/)- Example:
"/assets/docs/other/diagram.excalidraw"
- Example:
Optional Props
alt: Alt text for accessibility- Example:
"Architecture diagram showing system components"
- Example:
caption: Caption text displayed below the diagram- Example:
"Project Architecture Overview"
- Example:
initialZoom: Initial zoom level (default:1= 100%)0.5= 50% zoom (good for large diagrams)1= 100% zoom (default)2= 200% zoom (for detailed diagrams)
Examples
Basic Diagram
MDX Syntax:
Rendered Result:
Here's a visual representation of the project architecture:
Loading diagram...
Diagram with Caption
MDX Syntax:
Rendered Result:
Loading diagram...
Large Diagram with Custom Zoom
MDX Syntax:
Rendered Result:
Loading diagram...
Diagram with Alt Text
MDX Syntax:
Rendered Result:
Loading diagram...
Complete Example
Here's a complete example using Excalidraw diagrams:
File Organization
Organize your Excalidraw files logically:
Zoom Levels
Choose the appropriate initial zoom level:
initialZoom={0.5}: Good for large diagrams that need to fit on screeninitialZoom={1}: Default - shows diagram at 100%initialZoom={2}: Useful for detailed diagrams that need to be larger
Controls
The diagram includes a toolbar with:
- Zoom In (+): Increase zoom level
- Zoom Out (-): Decrease zoom level
- Reset Zoom: Return to initial zoom level
- Fullscreen: View diagram in fullscreen mode
Best Practices
- Use descriptive filenames:
project-architecture.excalidraw,data-flow.excalidraw - Add captions: Help readers understand what the diagram shows
- Choose appropriate zoom: Large diagrams benefit from
initialZoom={0.5} - Organize files: Keep diagrams in logical locations (by section or topic)
- Test both themes: Make sure diagrams look good in both light and dark modes
- Add alt text: Improve accessibility with descriptive alt text
Troubleshooting
Diagram Not Loading
- Verify the file path is correct (relative to
public/) - Check the file exists in the specified location
- Ensure the file is valid JSON
- Check browser console for errors
Diagram Not Centered
- The diagram should automatically center on load
- If not centered, check the diagram's element positions in Excalidraw
- Try adjusting the initial zoom level
Theme Not Matching
- The diagram theme automatically matches your website theme
- If it doesn't match, check that
next-themesis properly configured - The diagram uses the same theme as the rest of your site
Next Steps
- Tabbed Content - Learn about multi-tab sections
- Images & Videos - Learn about media components
- Code Blocks - Learn about syntax highlighting