Skip to content

Code Editor

Pro

Lets people edit code in a page or a form, with syntax colors, line numbers, folding, find and replace, autocomplete, and marks on errors.

  • Base UI
  • React 19
  • Tailwind CSS 4

Added Nov 9, 2026 · Pro license

Playground

Loading the preview

Props

Needs your Pro API key in GELATIN_UI_PRO_TOKEN. Set it up

Pro itemAPI key required

Code Editor needs a Pro API key

Try the live preview for free. With Pro, the add command above puts the source in your project.

Files it adds
31
More Pro items, one API key
+327
Your coding agent runs it
1 cmd

$79$129once, for life

Already have Pro? Sign in to set up your API key.

Give the editor a language and a name for screen readers. The editor loads CodeMirror when it mounts.

config-editor.tsx

CodeEditor

<div>
PropTypeDefaultDescription
autoFocusbooleanfalseFocus the text box when the editor is ready.
palette"color""ink""theme"—
valuestring—The text (controlled).
defaultValuestring—The text at first (uncontrolled).
onValueChange—Runs on each edit by the user, with the whole text. Not on a value change.
languagestring—A language name or alias of #/lib/code-editor-languages-model (tsx, json, sh).
lineNumbersbooleantrueLine numbers in the gutter. Default true.
foldingbooleantrueFold blocks from the gutter, and Cmd/Ctrl+Alt+[ ]. Default true.
wrapboolean—Wrap long lines. Default: the Wrap toggle of the Code Block, else false (lines scroll).
readOnlybooleanfalseThe text can be read, selected, copied, and searched, not changed.
disabledbooleanfalseNot focusable and not editable; 50% opacity.
placeholderstring—The text of an empty editor.
tabSizenumber2Spaces per indent level, and the width of a tab. Default 2.
indentWithTabbooleantrueTab indents and Shift+Tab outdents. Default true. Escape, then Tab, leaves the editor (no keyboard trap, WCAG 2.1.2); the description of the text box says so, and the status row shows it.
autocompletebooleantrueThe completions of the language as you type, and on Ctrl+Space. Default true.
lintLintSource—A CodeMirror lint source: its problems show as wavy lines, gutter marks, and tooltips. Keep it stable (a module function or a memo): a new function restarts the linter.
extensionsreadonly Extension[]—More CodeMirror extensions, after the editor's own. Keep the array stable (a module constant or a memo): a new array reconfigures them.
namestring—The form field name: a hidden input carries the text.
formstring—The form of the hidden input, by id.
requiredbooleanfalse
invalidbooleanfalseThe text is wrong: the destructive border and ring, and aria-invalid.
labelsPartial<CodeEditorLabels>—The words of the editor (CodeEditorLabels in #/lib/code-editor-state). Keep a custom unfold function stable: a new one rebuilds the fold gutter.
childrenReactNode—Parts after the code, inside the frame: CodeEditorStatus.
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

CodeEditorStatus

<div>
PropTypeDefaultDescription
...props<div> attributes—Every other attribute goes to the <div>, with a ref.
  • Use it when people must edit code or config text in your app.
  • Use readOnly for a file that people can select, copy, and search but not change.
  • Give it a name to send the text with a form. A Field around it gives the label and the error.
  • Pass a CodeMirror lint source to show problems as wavy lines and gutter marks.
  • Put it in a CodeBlock to get the file header, the copy button, and the Wrap toggle.
  • To only show code with no edits, use a Code Block.
  • For a JSON value that people open and close by key, use a JSON Viewer.
  • For plain text with no code features, use a Textarea.
TaborShiftTabIndents or outdents the line. With indentWithTab={false}, Tab moves the focus.
Escapeorthen TabLeaves the editor.
⌘ForCtrlFOpens the find and replace bar.
EnterorShiftEnterIn the find field: goes to the next or the previous match.
EscapeIn the find bar: closes it and puts focus back in the code.
CtrlSpaceOpens the completions of the language.
⌘⌥[orCtrlAlt[Folds the block at the cursor. Use ] to unfold it.
⌘ZorCtrlZUndoes the last edit. Add Shift to redo.

The text box is the CodeMirror content: a textbox with aria-multiline, named by aria-label or aria-labelledby. invalid, required, and readOnly set the ARIA states.

Tab indents. Escape, then Tab, leaves the editor, so the keyboard is never trapped. The text box description says so.

The find bar fields have names, and Match case, Whole word, and Regexp are toggle buttons (aria-pressed).

If CodeMirror cannot load, a plain <textarea> with the same name and description takes its place.

Find bar
popup · 150ms · ease-panel (0.2, 0.4, 0.2, 1) · it scales from 96% and fades in

Built with

Installs with Code Editor

  1. AddedCode Editor, with Button, Code, Input Group, Kbd.
Open the release