# Heading {#heading}

Source: [Add H1–H6 headings to a React editor · Yurich](https://leeyujoo.com/yurich/features/heading/)

Package: [`yurich`](https://www.npmjs.com/package/yurich)

Package version: `0.1.2`

Turn paragraphs into headings from H1 to H6.

## Try it {#try-it}

Put the caret in “Bring your own toolbar” and click **Heading 2**. The first block becomes `<h2>Bring your own toolbar</h2>`. Click **Paragraph** to restore a paragraph.

## Add it to your editor {#setup}

Enable `Heading` and pass a number from 1 to 6 as the second argument of `setHeading`. The button calls `useIsActive(editor, 'setHeading', 2)` to check for the particular level.

```tsx
import { EditorContent, EditorProvider, Heading, useEditor, useIsActive } from 'yurich';

export function HeadingEditor() {
  const editor = useEditor({
    extensions: [Heading],
    initialValue: "<p>Bring your own toolbar</p>" + "<p>Add a Bold button first.</p>",
  });
  const isH2 = useIsActive(editor, 'setHeading', 2);

  return (
    <EditorProvider editor={editor}>
      <div role="group" aria-label="Headings">
        <button
          type="button"
          aria-pressed={isH2}
          onMouseDown={event => event.preventDefault()}
          onClick={() => editor.execute('setHeading', 2)}
        >
          Heading 2
        </button>
        <button
          type="button"
          onMouseDown={event => event.preventDefault()}
          onClick={() => editor.execute('removeHeading')}
        >
          Paragraph
        </button>
      </div>
      <EditorContent ariaLabel="Editor" />
    </EditorProvider>
  );
}
```

## Behavior to account for {#behavior}

A selection covering multiple blocks applies the heading to each of those blocks. `removeHeading` converts the selected blocks to paragraphs. A heading applied to a list item takes it out of the list.

[Features](https://leeyujoo.com/yurich/features/)
