# Bold {#bold}

Source: [Add a bold button to a React editor · Yurich](https://leeyujoo.com/yurich/features/bold/)

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

Package version: `0.1.2`

Emphasize selected text with bold.

## Try it {#try-it}

Select “Yurich” in the example and click **Bold**. `getHTML()` returns `<p><strong>Yurich</strong> deserves a little emphasis.</p>`. Click again with the same selection to remove bold.

## Add it to your editor {#setup}

Import `Bold` from `yurich` and add it to the editor’s `extensions` array. The toolbar calls `toggleBold` and reads the active state through `useIsActive`.

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

export function BoldEditor() {
  const editor = useEditor({
    extensions: [Bold],
    initialValue: "<p>Yurich deserves a little emphasis.</p>",
  });
  const active = useIsActive(editor, 'toggleBold');

  return (
    <EditorProvider editor={editor}>
      <button
        type="button"
        aria-pressed={active}
        onMouseDown={event => event.preventDefault()}
        onClick={() => editor.execute('toggleBold')}
      >
        Bold
      </button>
      <EditorContent ariaLabel="Editor" />
    </EditorProvider>
  );
}
```

## Behavior to account for {#behavior}

`Mod+B` also runs the command. With only a caret, the command leaves the document as it is. When only part of the selection is bold, toggling applies bold to the entire selection.

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