---
title: "Toggle through heading levels with a button"
description: "Add a button that toggles through different heading levels in your Tiptap editor. More in the docs!"
---

> This page is for Tiptap 2.x. [See the latest version of this page.](https://tiptap.dev/docs/ui-components/components/heading-button.md)

# Toggle through heading levels with a button

Add a button that toggles through different heading levels in your Tiptap editor. More in the docs!

> **Upgrade to v3**
>
> To use UI components or templates you need to upgrade to Editor version 3.x. See the [upgrade
> guide](https://tiptap.dev/docs/resources/whats-new) for more details.

A button for toggling different heading levels.

> **Interactive demo:** [heading button](https://template.tiptap.dev/preview/tiptap-ui/heading-button)

## Install

You can add the component via Tiptap CLI (for Vite or Next.js)

```bash
npx @tiptap/cli add heading-button
```

### Manual Integration

For frameworks other than Vite or Next.js, add the component manually from the [open-source repository](https://github.com/ueberdosis/tiptap-ui-components/tree/main/apps/web/src/components/tiptap-ui/heading-button).

### Import styles

This component requires you to import our styles which were added to `styles/keyframe-animation.scss` and `styles/_variables.scss`.

## Usage

```tsx
import { HeadingButton } from '@/components/tiptap-ui/heading-button'
import { EditorContent, EditorContext, useEditor } from '@tiptap/react'
import { StarterKit } from '@tiptap/starter-kit'

import '@/components/tiptap-node/paragraph-node/paragraph-node.scss'

export default function MyEditor() {
  const editor = useEditor({
    immediatelyRender: false,
    extensions: [StarterKit],
    content: `
          <h1>Heading 1</h1>
          <h2>Heading 2</h2>
          <h3>Heading 3</h3>
          <h4>Heading 4</h4>
        `,
  })

  return (
    <EditorContext.Provider value={{ editor }}>
      <div className="tiptap-button-group" data-orientation="horizontal">
        <HeadingButton level={1}></HeadingButton>
        <HeadingButton level={2}></HeadingButton>
        <HeadingButton level={3}></HeadingButton>
        <HeadingButton level={4}></HeadingButton>
      </div>

      <EditorContent editor={editor} role="presentation" />
    </EditorContext.Provider>
  )
}
```

## Props

| Name                | Type                       | Default  | Description                                        |
| ------------------- | -------------------------- | -------- | -------------------------------------------------- |
| editor              | Editor \| null             | null     | The Tiptap editor instance                         |
| level               | 1 \| 2 \| 3 \| 4 \| 5 \| 6 | required | The heading level                                  |
| hideWhenUnavailable | boolean                    | false    | Whether the button should be hide if not available |
| text                | string                     | -        | Text to display alongside the icon                 |

## Requirements

Used reference components

- `use-tiptap-editor` (hook)
- `button` (primitive)
- `tiptap-utils` (lib)
- `heading-one-icon` (icon)
- `heading-two-icon` (icon)
- `heading-three-icon` (icon)
- `heading-four-icon` (icon)
- `heading-five-icon` (icon)
- `heading-six-icon` (icon)
