---
title: "Word Count plugin"
description: "Show a word count in the TinyMCE status bar."
canonical_url: "https://www.tiny.cloud/docs/tinymce/latest/wordcount/"
md_url: "https://www.tiny.cloud/docs/tinymce/7/wordcount/index.md"
version: "7"
last_updated: "2023-08-07T07:58:56Z"
tokens: 1290
---
Important This page documents TinyMCE 7. For new projects, Tiny recommends using the latest, most up-to-date version. [See TinyMCE 8 documentation](../../latest/wordcount/).
# Word Count plugin

The Word Count plugin adds functionality for counting words to the TinyMCE editor.

When loaded, the Word Count plugin:

- places a word and character counter in the status bar.

  - By default the counter appears adjacent the **Powered by Tiny** [product attribution logo](../statusbar-configuration-options/#branding).
  - Clicking the counter in the status bar switches the display between word count and character count.
- adds a **Word count** command to the **Tools** menu.

  - choosing this command presents a **Word Count** dialog showing the word and character count for the current document. If there is a current selection, the word and character count for the selection is also shown.
  - if `wordcount` is also added to the toolbar configuration, a **Word Count** toolbar item presents that functions equivalently to the **Tools → Word count** menu command.

## Word count logic

The Word count plugin counts ‘words’ by delimiting strings at pre-defined word boundaries.

### Word boundary characers

#### Some characters treated as word boundaries

| Name | Example and notes |
| --- | --- |
| Space | This includes space character entities such as `&nbsp;` (the non-breaking space character entity) and `&thinsp;` (the thin space character entity). |
| Em-dashes | **—** |
| En-dashes | **–** |
| Question marks | **?** |
| Commas | **,** |
| Semi-colons | **;** |
| Exclamation marks | **!** |
| Solidus (aka forward slash) | **/** |
| NOTE: This feature is only available for TinyMCE 6.5 and later. | NOTE: This feature is only available for TinyMCE 6.5 and later. |
| Circumflex | **^** |
| Numero sign | **№** |
| Tilde | **~** |
| Plus sign | **+** |
| Vertical bar (aka pipe character) | **\|** |
| Dollar sign | **$** |
| Grave accent | **`** |

#### Some characters not treated as word boundaries

| Name | Example and notes |
| --- | --- |
| Hyphens | **-** |
| Fraction slash | **⁄** |
| Equals sign | **=** |
| Full-stops (aka periods) | **.** <br>Note that space characters are word boundaries. <br>Practically speaking, it is full-stops embedded between letters without a space either side that don’t function as word boundary characters. |
| Colons | **:** <br>Note that space characters are word boundaries. <br>Practically speaking, it is colons embedded between letters without a space either side that don’t function as word boundary characters. |
| Empty block elements | `<p></p>` <br>Also, space characters inside otherwise empty elements — for example `<p>&nbsp;</p>` — do not change either the word or character count. |

## Character count logic

The Word Count plugin counts glyphs.

The Word Count plugin does not count characters added for document management purposes.

Consider an end-user enters the following:

```text
1↵
↵
2↵
↵
```
That is, they enter a numeric one, followed by two hard returns, and then a numeric two, followed by a further two hard returns.

By default, TinyMCE stores this entered data as follows:

```html
<p>1</p>
<p>&nbsp;</p>
<p>2</p>
<p>&nbsp;</p>
```
The character count for this data is **2**.

The Word Count does not add either of the `&nbsp;` characters placed by TinyMCE to the document character count.

## Basic setup

```js
tinymce.init({
  selector: 'textarea',  // change this value according to your HTML
  plugins: 'wordcount',
  toolbar: 'wordcount'
});
```

## Toolbar buttons

The Word Count plugin provides the following toolbar buttons:

| Toolbar button identifier | Description |
| --- | --- |
| `wordcount` | Opens a word count dialog showing word and character counts. |

These toolbar buttons can be added to the editor using:

- The [`toolbar`](../toolbar-configuration-options/#toolbar) configuration option.
- The [`quickbars_insert_toolbar`](../quickbars/#quickbars_insert_toolbar) configuration option.
- [Custom Context toolbars](../contexttoolbar/).

## Menu items

The Word Count plugin provides the following menu items:

| Menu item identifier | [Default Menu Location](../menus-configuration-options/#example-the-tinymce-default-menu-items) | Description |
| --- | --- | --- |
| `wordcount` | Tools | Opens a word count dialog showing word and character counts. |

These menu items can be added to the editor using:

- The [`menu`](../menus-configuration-options/#menu) configuration option.
- The [`contextmenu`](../menus-configuration-options/#contextmenu) configuration option.
- [Custom Menu toolbar buttons](../custom-menu-toolbar-button/).

## Commands

The Word Count plugin provides the following TinyMCE command.

| Command | Description |
| --- | --- |
| mceWordCount | Opens the Word Count summary dialog. |

Example
```js
tinymce.activeEditor.execCommand('mceWordCount');
```

## API

The Word Count plugin exposes an API for retrieving the word and character count of either the whole document or the current editor selection. Following is an example of how to retrieve each property.

### Example: using the `wordcount` plugin APIs

```js
const wordcount = tinymce.activeEditor.plugins.wordcount;

console.log(wordcount.body.getWordCount());
console.log(wordcount.body.getCharacterCount());
console.log(wordcount.body.getCharacterCountWithoutSpaces());

console.log(wordcount.selection.getWordCount());
console.log(wordcount.selection.getCharacterCount());
console.log(wordcount.selection.getCharacterCountWithoutSpaces());
```
