Italic
The Italic mark applies italic formatting to text. It renders as <em> and parses <em>, <i>, and CSS font-style: italic. Included in StarterKit by default.
When to use
Section titled “When to use”Use Italic when you need:
- A standard
<em>mark with Cmd+I,*single asterisks*, or_underscores_ - Pasted content from any source to land correctly (parses both
<em>and<i>tags plus inlinefont-style: italic) - Programmatic control via
setItalic,unsetItalic, andtoggleItaliccommands
Notes:
- Italic renders
<em>(semantic emphasis), not<i>(presentational), to match accessibility best practices - Both
*and_markdown rules fire; choose either or both depending on your project style
Live Playground
Section titled “Live Playground”Select text and apply italic with buttons, keyboard shortcut (Cmd+I / Ctrl+I), or type *text* to trigger the input rule.
With the default theme enabled. Click the I toolbar button or use Cmd+I / Ctrl+I.
Plain editor without the theme. The buttons above call toggleItalic(), setItalic(), and unsetItalic() directly.
Italic is included in StarterKit, so it works out of the box. To use it standalone:
import { Document, Paragraph, Text, Italic } from '@domternal/core';import { DomternalEditor, DomternalToolbar } from '@domternal/vanilla';import '@domternal/theme';
const editorEl = document.getElementById('editor')!;const toolbarEl = document.createElement('div');editorEl.before(toolbarEl);
const dm = new DomternalEditor(editorEl, { extensions: [Document, Paragraph, Text, Italic], content: '<p>This is <em>italic</em> text.</p>',});
new DomternalToolbar(toolbarEl, { editor: dm.editor });import { Component, signal } from '@angular/core';import { DomternalEditorComponent, DomternalToolbarComponent } from '@domternal/angular';import { Editor, Document, Paragraph, Text, Italic } from '@domternal/core';
@Component({ selector: 'app-editor', imports: [DomternalEditorComponent, DomternalToolbarComponent], templateUrl: './editor.html',})export class EditorComponent { editor = signal<Editor | null>(null); extensions = [Document, Paragraph, Text, Italic]; content = '<p>This is <em>italic</em> text.</p>';}@if (editor(); as ed) { <domternal-toolbar [editor]="ed" />}<domternal-editor [extensions]="extensions" [content]="content" (editorCreated)="editor.set($event)"/>import { Domternal } from '@domternal/react';import { Document, Paragraph, Text, Italic } from '@domternal/core';
export default function Editor() { return ( <Domternal extensions={[Document, Paragraph, Text, Italic]} content="<p>This is <em>italic</em> text.</p>" > <Domternal.Toolbar /> <Domternal.Content /> </Domternal> );}<script setup lang="ts">import { Domternal } from '@domternal/vue';import { Document, Paragraph, Text, Italic } from '@domternal/core';
const extensions = [Document, Paragraph, Text, Italic];</script>
<template> <Domternal :extensions="extensions" content="<p>This is <em>italic</em> text.</p>"> <Domternal.Toolbar /> <Domternal.Content /> </Domternal></template>import { Editor, Document, Paragraph, Text, Italic } from '@domternal/core';
const editor = new Editor({ element: document.getElementById('editor')!, extensions: [Document, Paragraph, Text, Italic], content: '<p>This is <em>italic</em> text.</p>',});
// Toggle italic programmaticallyeditor.chain().focus().toggleItalic().run();To disable Italic in StarterKit:
StarterKit.configure({ italic: false })Schema
Section titled “Schema”| Property | Value |
|---|---|
| ProseMirror name | italic |
| Type | Mark |
| HTML tag | <em> |
Parsing rules
Section titled “Parsing rules”Italic parses from multiple HTML sources for maximum compatibility:
| Source | Condition |
|---|---|
<em> | Always |
<i> | Unless font-style: normal (Google Docs compatibility) |
CSS font-style | Value is italic (case-insensitive) |
Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
HTMLAttributes | Record<string, unknown> | {} | Custom HTML attributes added to the rendered <em> element |
import { Italic } from '@domternal/core';
const CustomItalic = Italic.configure({ HTMLAttributes: { class: 'my-italic' },});Commands
Section titled “Commands”setItalic
Section titled “setItalic”Applies italic formatting to the current selection.
editor.commands.setItalic();unsetItalic
Section titled “unsetItalic”Removes italic formatting from the current selection.
editor.commands.unsetItalic();toggleItalic
Section titled “toggleItalic”Toggles italic formatting on the current selection. Applies italic if not active, removes it if active.
editor.commands.toggleItalic();
// With chainingeditor.chain().focus().toggleItalic().run();Keyboard shortcuts
Section titled “Keyboard shortcuts”| Key | Action |
|---|---|
Mod-I | Toggle italic (toggleItalic) |
Mod is Cmd on macOS and Ctrl on Windows/Linux.
Input rules
Section titled “Input rules”| Input | Result |
|---|---|
*text* | Wraps text in italic |
_text_ | Wraps text in italic |
Type the closing * or _ to trigger the conversion. The markers are removed and the text between them becomes italic.
Toolbar items
Section titled “Toolbar items”Italic registers a button in the toolbar with the name italic in group format at priority 190.
| Item | Type | Command | Icon | Shortcut | Active when |
|---|---|---|---|---|---|
| Italic | button | toggleItalic | textItalic | Mod-I | Italic mark is active on selection |
Exports
Section titled “Exports”import { Italic } from '@domternal/core';import type { ItalicOptions } from '@domternal/core';| Export | Type | Description |
|---|---|---|
Italic | Mark extension | The italic mark extension |
ItalicOptions | TypeScript type | Options for Italic.configure() |
Source
Section titled “Source”@domternal/core - Italic.ts
See also
Section titled “See also”- Bold - strong emphasis with
Cmd+Band**markdown** - Underline - underline mark with
Cmd+Ushortcut - Strike - strikethrough with
Cmd+Shift+Sand~~markdown~~ - Clear Formatting - removes all inline marks from selection