Code Editor in React: CodeMirror 6 vs Monaco vs Shiki
CodeMirror 6, Monaco, and Shiki each solve a different problem. Here's how to pick the right one - and wire it into React without losing your mind.
Three Tools, Three Different Problems
People throw "code editor" around as if it's one thing. It's not. You might want a full IDE-grade editing experience where users write and run code. You might want a read-only syntax-highlighted block that makes your docs look slick. You might want something in between - a lightweight editor with basic autocomplete for a config panel or a playground. The tool that wins each of those scenarios is different.
CodeMirror 6 is a modular, mobile-friendly editor that gives you complete control over every feature you include. Monaco is the engine behind VS Code - it's enormous, capable, and opinionated. Shiki is not an editor at all; it's a static syntax highlighter that renders server-side HTML, zero client-side JS required. Mix them up and you'll be fighting your bundle for the rest of the sprint.
Honestly, the single biggest mistake I see is teams reaching for Monaco because it's the most recognisable name, then spending two weeks fighting its opinionated defaults, iframe quirks in some setups, and a production bundle that balloons past 2 MB just for the worker files. So before you npm install, actually nail down what you need.
This article gives you the real trade-offs. Size numbers, setup code, and the specific cases where each library earns its keep.
Monaco Editor: The VS Code Engine
Monaco is the real deal. You get IntelliSense, multi-cursor, find-and-replace, a full diff editor, and language services that can typecheck TypeScript right in the browser. If your users need an experience that feels like their editor at home, Monaco delivers that by default - because it literally is their editor.
The setup in React is more involved than people expect. Monaco was built for vanilla JS and the community wrapper @monaco-editor/react is the go-to, but you still have to manage the web worker loading or you'll see flashes of unstyled content and slow initial parse on large files. As of Monaco 0.47 (released late 2024), the worker setup changed slightly - watch for that if you're copying old StackOverflow answers.
import Editor from '@monaco-editor/react';
export function MonacoPlayground() {
return (
<Editor
height="400px"
defaultLanguage="typescript"
defaultValue={`// your code here\nconst greet = (name: string) => \`Hello, ${name}\`;`}
theme="vs-dark"
options={{
fontSize: 14,
minimap: { enabled: false },
scrollBeyondLastLine: false,
wordWrap: 'on',
}}
/>
);
}Worth noting: the production bundle is the real cost. Monaco's JS workers for TypeScript alone add ~1.8 MB gzipped to your initial chunk if you load them naively. You should configure webpack or Vite to split the workers out and load them from a CDN (vs/loader pattern), or use @monaco-editor/react's loader.config() to point at a CDN copy. Don't skip this step on anything users will hit on mobile.
Monaco is the right call for: online IDEs, code playgrounds where users actually execute code, admin panels where engineers write logic, and anywhere you want TypeScript intellisense in the browser. It's overkill for a docs site or a component library showcase - and you'll feel that overkill on every Lighthouse run.
CodeMirror 6: Modular and Actually Portable
CodeMirror 6 is a ground-up rewrite from 2020 that ships as a collection of @codemirror/* packages. You pull in exactly what you need - the base editor, a language pack, a theme, maybe a linter - and nothing else. The core with a single language and a basic theme runs around 80β120 KB gzipped. That's a different planet from Monaco.
The API is functional and composable via "extensions" - think of them as the React hooks equivalent for editor configuration. You stack extensions into an array and pass them to EditorState.create(). This means you can feature-flag expensive capabilities (autocompletion, linting) at runtime without touching editor setup. It also makes theming genuinely clean: themes are just extension objects, not CSS class hacks.
import { useEffect, useRef } from 'react';
import { EditorView, basicSetup } from 'codemirror';
import { javascript } from '@codemirror/lang-javascript';
import { oneDark } from '@codemirror/theme-one-dark';
export function CodeMirrorEditor({ initialDoc }: { initialDoc: string }) {
const containerRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!containerRef.current) return;
const view = new EditorView({
doc: initialDoc,
extensions: [basicSetup, javascript(), oneDark],
parent: containerRef.current,
});
return () => view.destroy();
}, []);
return <div ref={containerRef} className="rounded-lg overflow-hidden" />;
}In practice, CodeMirror 6 is what you want for 80% of use cases. It works great on mobile (touch events handled natively), it's accessibility-compliant out of the box, and the TypeScript types are solid. The main friction is that the extension-based API has a learning curve - the docs are thorough but dense. Budget an afternoon to really understand EditorState, EditorView, and StateField before you try to build something custom.
One more thing - the React ecosystem wrapper @uiw/react-codemirror wraps the imperative API into a nice <CodeMirror> component with hooks for onChange, onFocus, etc. It's maintained well and reduces the boilerplate. That said, if you need deep access to the view internals, knowing the raw API will save you eventually.
Shiki: When You Don't Need an Editor at All
Shiki is a syntax highlighter, not an editor. It takes a string of source code, runs it through a TextMate grammar (the same grammars VS Code uses), and spits out HTML with inline color spans. The result looks exactly like VS Code's output because it uses VS Code's themes directly. No client JS, no runtime parsing, just pre-rendered HTML.
Since React 18 and Next.js 13 made server components mainstream, Shiki has become the obvious choice for documentation sites and component showcases. Render on the server, send the HTML, done. Your code blocks load instantly, they're perfectly readable with JS disabled, and your bundle pays zero cost. As of Shiki 1.0 (released early 2024), the API is async-first and tree-shakeable by language - you only load the grammar for the languages you actually use.
// app/docs/CodeBlock.tsx - React Server Component
import { codeToHtml } from 'shiki';
interface CodeBlockProps {
code: string;
lang: string;
}
export async function CodeBlock({ code, lang }: CodeBlockProps) {
const html = await codeToHtml(code, {
lang,
theme: 'github-dark',
});
return (
<div
className="rounded-xl overflow-x-auto text-sm leading-6"
dangerouslySetInnerHTML={{ __html: html }}
/>
);
}Look, dangerouslySetInnerHTML looks scary here but it's fine - Shiki is generating the HTML, not user input. The output is sanitised by design. The pattern above renders syntax-highlighted code at build time or request time with zero client JavaScript. It's what this blog uses for most code examples.
Shiki's limitation is obvious: it's read-only. Users can't type in it. If you want a copy button you add it yourself as a normal React component layered over the block. If you need editing, you're back to CodeMirror or Monaco. Quick aside: if you're building a docs-heavy design system like Empire UI, Shiki + a minimal copy-button wrapper is almost always the right call for showcasing component code examples.
Comparing Bundle Sizes and Real Performance
Numbers matter. Here's a rough breakdown of what each option costs in production as of late 2025, measured gzipped:
Shiki (single language + theme) ~220 KB (server only β 0 KB client)
CodeMirror 6 (basic + JS lang) ~95 KB gzipped client JS
CodeMirror 6 (full + TS lang) ~180 KB gzipped client JS
Monaco (via CDN workers) ~500 KB initial + ~1.4 MB async workers
Monaco (bundled, no CDN) ~2.1 MB gzipped (don't do this)That Monaco "bundled" number is not a typo. I've seen it in real production apps. Teams add @monaco-editor/react, forget to configure the worker loading, and suddenly their Lighthouse score nosedives. The fix is always the same: point Monaco at a CDN for worker files and lazy-load the editor component behind a dynamic import.
For CodeMirror 6, the extension model really pays off here. A minimal editor for a JSON config field - @codemirror/lang-json plus basicSetup minus autocompletion - can come in under 70 KB. That's genuinely acceptable for an interactive widget. Compare that to pulling in Monaco for the same use case, which is like driving a semi truck to pick up one grocery bag.
Worth noting: Shiki is zero cost on the client when used in server components. That's not a minor point. For marketing sites, docs, and component libraries built on Next.js App Router, that difference is the whole ballgame. You get pixel-perfect VS Code-matching colors with literally no JavaScript shipped to the browser.
Which One to Pick - The Actual Decision Tree
Here's the framework I use when a project asks for a code editor feature. Start with the most restrictive question: does the user need to type? No? Use Shiki, full stop. Done. Ship it.
If they need to type, ask how much language intelligence they need. Does the user need TypeScript error checking, import autocomplete, hover docs? That's Monaco's territory. Any other editing requirement - JSON, CSS, JSX with basic highlighting, a SQL query input - CodeMirror 6 is lighter, faster to configure, and more portable.
User needs to READ code β Shiki (server component, zero client JS)
User needs to EDIT, no intellisense β CodeMirror 6
User needs to EDIT + TS intellisense / multi-file β Monaco
User needs inline config field (JSON/YAML) β CodeMirror 6 minimal setup
User on mobile β CodeMirror 6 (Monaco has rough touch behavior)You can also mix them. A documentation site might use Shiki for static code blocks on 95% of pages, then load a CodeMirror 6 editor only on the interactive playground page. That's not over-engineering - that's just choosing the right tool per context. Lazy load the playground with Next.js dynamic(() => import('./Playground'), { ssr: false }) and users on the docs pages never pay for the editor bundle.
If you're building UI components that include code display - think a design system like Empire UI with live preview panels, a settings page with code output, or even a templates builder - you'll likely end up using Shiki for the display layer and CodeMirror 6 for any editable slots. That combo is increasingly the industry standard in 2026 for exactly this reason.
Styling Your Editor to Match Your UI
All three tools need CSS work to feel at home in your app. Monaco applies its own opinionated font (Consolas β monospace fallback) at 14px by default and wants an explicit height container. Wrap it in a div with a defined height and overflow: hidden, otherwise it collapses to 0px in flex layouts - this trips up almost everyone the first time.
CodeMirror 6 is more cooperative. The .cm-editor root element respects normal flow, and you style it with regular CSS or Tailwind. Add rounded-xl overflow-hidden border border-white/10 and it slots right into a dark UI. You can build a custom theme with the @codemirror/view EditorView.theme() API and control background, text color, selection color, and gutter styles programmatically, without touching global CSS.
Shiki's output is just HTML spans with inline style color attributes derived from the theme JSON. Drop it in any container and it looks right immediately. If you want to override a token color, you target .shiki span[style] - clunky, but doable. Easier to just pick a theme that matches your UI. For a dark design system, github-dark, one-dark-pro, and tokyo-night all pair well with the kind of dark glassmorphism or cyberpunk aesthetic popular in 2026.
One more thing - if you're using CodeMirror 6 inside a component library and want the editor to adapt to a light/dark system theme, the @codemirror/theme-one-dark package only covers dark mode. You'll need to set up a conditional extension array: pass oneDark when colorScheme === 'dark' and a light theme otherwise. This is cleaner than trying to override CSS variables after the fact. You can see a pattern like this in action on Empire UI's glassmorphism generator - the code output panel swaps themes with the color mode toggle.
FAQ
Yes, and it's actually a great pattern. Use Shiki as a React Server Component for static code display and CodeMirror 6 for any interactive editing. They don't conflict - they don't even share a runtime.
Yes - Monaco Editor is MIT licensed and free for commercial use. The @monaco-editor/react wrapper is also MIT. Just make sure you configure worker loading correctly in production or your bundle will be massive.
Yes, that's basically its ideal environment. Call codeToHtml() in an async server component and render the result with dangerouslySetInnerHTML. Zero client JavaScript, perfectly rendered highlighting.
CodeMirror 6 - it has proper touch event handling built in. Monaco has known rough edges on touch screens, and Shiki is read-only so not applicable if users need to type.