---
title: "tinymce.html.Writer"
description: "This class is used to write HTML tags out it can be used with the Serializer."
canonical_url: "https://www.tiny.cloud/docs/tinymce/latest/apis/tinymce.html.writer/"
md_url: "https://www.tiny.cloud/docs/tinymce/6/apis/tinymce.html.writer/index.md"
version: "6"
last_updated: "2022-07-13T05:38:26Z"
tokens: 855
---
Important This page documents TinyMCE 6. For new projects, Tiny recommends using the latest, most up-to-date version. [See TinyMCE 8 documentation](../../../latest/apis/tinymce.html.writer/).
# tinymce.html.Writer

This class is used to write HTML tags out it can be used with the Serializer.

## Examples

```javascript
const writer = tinymce.html.Writer({ indent: true });
writer.start('node', { attr: 'value' });
writer.end('node');
console.log(writer.getContent());
```

## Summary

### Methods

| Name | Summary | Defined by |
| --- | --- | --- |
| [cdata()](#cdata) | Writes a cdata node, such as `<![CDATA[data]]>`. | `Writer` |
| [comment()](#comment) | Writes a comment node, such as `<!-- Comment -->`. | `Writer` |
| [doctype()](#doctype) | Writes a doctype node, such as `<!DOCTYPE data>`. | `Writer` |
| [end()](#end) | Writes an end element, such as `</p>`. | `Writer` |
| [getContent()](#getContent) | Returns the contents that was serialized. | `Writer` |
| [pi()](#pi) | Writes a processing instruction (PI) node, such as `<?xml attr="value" ?>`. | `Writer` |
| [reset()](#reset) | Resets the internal buffer. For example, if one wants to reuse the writer. | `Writer` |
| [start()](#start) | Writes a start element, such as `<p id="a">`. | `Writer` |
| [text()](#text) | Writes a text node. | `Writer` |

## Methods

### cdata()

```javascript
cdata(text: String)
```
Writes a cdata node, such as `<![CDATA[data]]>`.

#### Parameters

- `text (String)` - String to write out inside the cdata.

### comment()

```javascript
comment(text: String)
```
Writes a comment node, such as `<!-- Comment -->`.

#### Parameters

- `text (String)` - String to write out inside the comment.

### doctype()

```javascript
doctype(text: String)
```
Writes a doctype node, such as `<!DOCTYPE data>`.

#### Parameters

- `text (String)` - String to write out inside the doctype.

### end()

```javascript
end(name: String)
```
Writes an end element, such as `</p>`.

#### Parameters

- `name (String)` - Name of the element.

### getContent()

```javascript
getContent(): String
```
Returns the contents that was serialized.

#### Return value

- `String` - HTML contents that got written down.

### pi()

```javascript
pi(name: String, text: String)
```
Writes a processing instruction (PI) node, such as `<?xml attr="value" ?>`.

#### Parameters

- `name (String)` - Name of the pi.
- `text (String)` - String to write out inside the pi.

### reset()

```javascript
reset()
```
Resets the internal buffer. For example, if one wants to reuse the writer.

### start()

```javascript
start(name: String, attrs: Array, empty: Boolean)
```
Writes a start element, such as `<p id="a">`.

#### Parameters

- `name (String)` - Name of the element.
- `attrs (Array)` - Optional array of objects containing an attribute name and value, or undefined if the element has no attributes.
- `empty (Boolean)` - Optional empty state if the tag should serialize as a void element. For example: `<img />`

### text()

```javascript
text(text: String, raw: Boolean)
```
Writes a text node.

#### Parameters

- `text (String)` - String to write out.
- `raw (Boolean)` - Optional raw state. If true, the contents won’t get encoded.
