# BaseHtml

> Provides the base implementation for rendering HTML tags.

[API reference](/docs/api/index.md) › [HTML Core](/docs/extensions/html-core/reference/index.md) › [Base](/docs/extensions/html-core/reference/base/index.md) › BaseHtml

| abstract class | `UIAwesome\Html\Core\Base\BaseHtml` |
| --- | --- |
| Source | [`src/Base/BaseHtml.php`](https://github.com/ui-awesome/html-core/blob/main/src/Base/BaseHtml.php#L22) |

1 subclass:

- [`UIAwesome\Html\Core\Html`](/docs/extensions/html-core/reference/html/index.md)

Provides the base implementation for rendering HTML tags.

See also: <https://developer.mozilla.org/en-US/docs/Glossary/Block-level_content>, <https://developer.mozilla.org/en-US/docs/Glossary/Inline-level_content>, <https://developer.mozilla.org/en-US/docs/Glossary/Void_element>, <https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements#main_root>, <https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements#table_content>.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`begin()`](#method-begin) static | Returns the opening tag for a block element. | `BaseHtml` |
| [`element()`](#method-element) static | Returns a complete HTML element `string`. | `BaseHtml` |
| [`end()`](#method-end) static | Returns the closing tag for a block element. | `BaseHtml` |
| [`inline()`](#method-inline) static | Returns an inline HTML element `string`. | `BaseHtml` |
| [`void()`](#method-void) static | Returns a void HTML element `string`. | `BaseHtml` |

## Method details

### begin() <span id="method-begin"></span>

```php
public static function begin(BackedEnum $tag, array $attributes = []): string
```

Returns the opening tag for a block element.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tag` | [`BackedEnum`](https://www.php.net/manual/en/class.backedenum.php) | Tag enumeration instance. |
| `$attributes` | `array` | Associative array of HTML attributes. |

**Returns**

`string`: Rendered opening tag string with attributes. The `pre` and `textarea` opening tags do not add a newline. Callers must supply a protective LF before streamed content starting with LF or CR (including CRLF); the opening tag cannot inspect future content. [`Block`](https://github.com/ui-awesome/html-interop/blob/bbc56fa772c4b4772a6a83d4a3e602c5c27313c9/src/Block.php) for valid block-level tags. [`Lists`](https://github.com/ui-awesome/html-interop/blob/bbc56fa772c4b4772a6a83d4a3e602c5c27313c9/src/Lists.php) for valid list-level tags. [`Root`](https://github.com/ui-awesome/html-interop/blob/bbc56fa772c4b4772a6a83d4a3e602c5c27313c9/src/Root.php) for valid root-level tags. [`Table`](https://github.com/ui-awesome/html-interop/blob/bbc56fa772c4b4772a6a83d4a3e602c5c27313c9/src/Table.php) for valid table-level tags.

### element() <span id="method-element"></span>

```php
public static function element(BackedEnum $tag, string $content, array $attributes = [], bool $encode = false): string
```

Returns a complete HTML element `string`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tag` | [`BackedEnum`](https://www.php.net/manual/en/class.backedenum.php) | Tag enumeration instance. |
| `$content` | `string` | Content to be rendered inside the tag. |
| `$attributes` | `array` | Associative array of HTML attributes. |
| `$encode` | `bool` | Whether to encode the content for HTML output. |

**Returns**

`string`: Rendered HTML element string. The `pre` and `textarea` elements do not receive presentation newlines around nonempty content. A protective LF is added only when their content starts with LF or CR (including CRLF). HTML normalizes CR/CRLF to LF before ignoring the first newline; the supplied content bytes are not normalized here. [`Block`](https://github.com/ui-awesome/html-interop/blob/bbc56fa772c4b4772a6a83d4a3e602c5c27313c9/src/Block.php) for valid block-level tags. [`Inline`](https://github.com/ui-awesome/html-interop/blob/bbc56fa772c4b4772a6a83d4a3e602c5c27313c9/src/Inline.php) for valid inline-level tags. [`Lists`](https://github.com/ui-awesome/html-interop/blob/bbc56fa772c4b4772a6a83d4a3e602c5c27313c9/src/Lists.php) for valid list-level tags. [`Root`](https://github.com/ui-awesome/html-interop/blob/bbc56fa772c4b4772a6a83d4a3e602c5c27313c9/src/Root.php) for valid root-level tags. [`Table`](https://github.com/ui-awesome/html-interop/blob/bbc56fa772c4b4772a6a83d4a3e602c5c27313c9/src/Table.php) for valid table-level tags. For void tags, use [`Html::void()`](/docs/extensions/html-core/reference/base/basehtml/index.md#method-void).

### end() <span id="method-end"></span>

```php
public static function end(BackedEnum $tag): string
```

Returns the closing tag for a block element.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tag` | [`BackedEnum`](https://www.php.net/manual/en/class.backedenum.php) | Tag enumeration instance. |

**Returns**

`string`: Rendered closing tag string. No presentation newline is added before `pre` or `textarea` closing tags, so streamed content stays intact. [`Block`](https://github.com/ui-awesome/html-interop/blob/bbc56fa772c4b4772a6a83d4a3e602c5c27313c9/src/Block.php) for valid block-level tags. [`Lists`](https://github.com/ui-awesome/html-interop/blob/bbc56fa772c4b4772a6a83d4a3e602c5c27313c9/src/Lists.php) for valid list-level tags. [`Root`](https://github.com/ui-awesome/html-interop/blob/bbc56fa772c4b4772a6a83d4a3e602c5c27313c9/src/Root.php) for valid root-level tags. [`Table`](https://github.com/ui-awesome/html-interop/blob/bbc56fa772c4b4772a6a83d4a3e602c5c27313c9/src/Table.php) for valid table-level tags.

### inline() <span id="method-inline"></span>

```php
public static function inline(BackedEnum $tag, string $content, array $attributes = [], bool $encode = false): string
```

Returns an inline HTML element `string`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tag` | [`BackedEnum`](https://www.php.net/manual/en/class.backedenum.php) | Inline tag enumeration instance. |
| `$content` | `string` | Content to be rendered inside the tag. |
| `$attributes` | `array` | Associative array of HTML attributes. |
| `$encode` | `bool` | Whether to encode the content for HTML output. |

**Returns**

`string`: Rendered inline HTML element string. [`Inline`](https://github.com/ui-awesome/html-interop/blob/bbc56fa772c4b4772a6a83d4a3e602c5c27313c9/src/Inline.php) for valid inline-level tags.

### void() <span id="method-void"></span>

```php
public static function void(BackedEnum $tag, array $attributes = []): string
```

Returns a void HTML element `string`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tag` | [`BackedEnum`](https://www.php.net/manual/en/class.backedenum.php) | Void tag enumeration instance. |
| `$attributes` | `array` | Associative array of HTML attributes. |

**Returns**

`string`: Rendered void HTML element string. [`Voids`](https://github.com/ui-awesome/html-interop/blob/bbc56fa772c4b4772a6a83d4a3e602c5c27313c9/src/Voids.php) for valid void-level tags.