# utils/dom/createelement

module

<a id="type-definitions">

## Type Definitions

<a id="typedef-ChildrenElements">

### `ChildrenElements`

<a id="typedef-HTMLElementAttributes">

### `HTMLElementAttributes`

<a id="typedef-SVGElementAttributes">

### `SVGElementAttributes`

<a id="functions">

## Functions

<a id="function-createElement:SVG_ELEMENT">

### `createElement( doc, name, attributes, children? ) → SVGElementTagNameMap[ T ]`

Creates an SVG element with attributes and children elements.

```typescript
createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg' } ); // <mask>
createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg', id: 'foo' } ); // <mask id="foo">
createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg' }, 'foo' ); // <mask>foo</mask>
createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg' }, [ createElement(...) ] ); // <mask><...></mask>
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/dom/createelement.ts#L45)

#### Type parameters

* `T: extends keyof SVGElementTagNameMap`

#### Parameters

* `doc: Document`

  Document used to create the element.

* `name: T`

  Name of the SVG element.

* `attributes: SVGElementAttributes`

  Object where keys represent attribute keys and values represent attribute values.

* `children?: ChildrenElements`

  Child or any iterable of children. Strings will be automatically turned into Text nodes.

#### Returns

* `SVGElementTagNameMap[ T ]`

  SVG element.

<a id="function-createElement:HTML_ELEMENT">

### `createElement( doc, name, attributes?, children? ) → HTMLElementTagNameMap[ T ]`

Creates an HTML element with attributes and children elements.

```typescript
createElement( document, 'p' ); // <p>
createElement( document, 'p', { class: 'foo' } ); // <p class="foo">
createElement( document, 'p', null, 'foo' ); // <p>foo</p>
createElement( document, 'p', null, [ createElement(...) ] ); // <p><...></p>
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/dom/createelement.ts#L69)

#### Type parameters

* `T: extends keyof HTMLElementTagNameMap`

#### Parameters

* `doc: Document`

  Document used to create the element.

* `name: T`

  Name of the HTML element.

* `attributes?: HTMLElementAttributes`

  Object where keys represent attribute keys and values represent attribute values.

* `children?: ChildrenElements`

  Child or any iterable of children. Strings will be automatically turned into Text nodes.

#### Returns

* `HTMLElementTagNameMap[ T ]`

  HTML element.

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
