Forms

Rich text editor

Headings, lists, quotes, code and links, with a toolbar above and a small menu over whatever you select. Markdown shortcuts work as you type: ## for a heading, - for a list, > for a quote.

Installation

npx sinaui add rich-text-editor

Examples

A catalog note

Select some words to format them from the menu that appears over them.

Catalog note
<script lang="ts">
	import RichTextEditor from '#lib/ui/RichTextEditor.svelte';

	let html = $state(
		'<h2>Kitab al-Manazir</h2><p>Ibn al-Haytham, <strong>Cairo</strong>, c. 1027. Seven books on <em>how we see</em>.</p><ul><li>Book I: the theory of vision</li><li>Books IV–VI: reflection and mirrors</li></ul><blockquote><p>Light travels in straight lines.</p></blockquote>'
	);
</script>

<div class="demo">
	<RichTextEditor label="Catalog note" bind:html />
</div>

<style>
	.demo {
		inline-size: min(40rem, 100%);
	}
</style>

With a length limit

The count turns amber near the limit and red past it. The HTML is what you'd save.

Note for the copyists

0 / 280

HTML it sends
(empty)
<script lang="ts">
	import RichTextEditor from '#lib/ui/RichTextEditor.svelte';

	let html = $state('');
</script>

<div class="demo">
	<RichTextEditor
		label="Note for the copyists"
		placeholder="What should they know before they start?"
		maxLength={280}
		bind:html
	/>
	<details>
		<summary>HTML it sends</summary>
		<pre><code>{html || '(empty)'}</code></pre>
	</details>
</div>

<style>
	.demo {
		display: grid;
		gap: 0.75rem;
		inline-size: min(40rem, 100%);
	}
	summary {
		color: var(--ui-muted);
		font-size: 0.875rem;
		cursor: pointer;
	}
	pre {
		margin: 0.5rem 0 0;
		padding: 0.75rem;
		border-radius: var(--ui-radius-control);
		background: var(--ui-subtle);
		font-size: 0.8125rem;
		white-space: pre-wrap;
		overflow-wrap: anywhere;
	}
</style>

Props

PropTypeDefault
labelstring (required)
hideLabelbooleanfalse
htmlstring (bindable)''
placeholderstring'Write something…'
maxLengthnumber: shows a character count

Keyboard

On Windows and Linux, use Ctrl for ⌘ and Alt for ⌥.

KeyDoes
⌘ B / I / EBold, italic, code
⌘ ⇧ SStrikethrough
⌘ ⌥ 2 / 3Heading, subheading
⌘ ⇧ 8 / 7Bulleted, numbered list
⌘ ⇧ BQuote
⌘ KAdd or edit a link
⌘ Z / ⌘ ⇧ ZUndo, redo
← →Move along the toolbar
EscapeClose the link field

Accessibility

  • The writing area is a multi-line text box named by the label.
  • The toolbar is one Tab stop; arrow keys move between its buttons, and each says whether its style is on.
  • Every button's shortcut is in its tooltip, shown on hover and keyboard focus.
  • With a limit, the count is read with the text box.
  • With reduced motion, the menu over a selection fades in without moving.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Menubar
Navigation menu
Pagination
Sidebar layout
Stepper
Tabs
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
File explorer
Messaging
Notifications
Settings
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme