# BlockInterface

> Defines a contract for renderable HTML elements that use separate opening and closing tags.

[API reference](/docs/api/index.md) › [HTML Contracts](/docs/extensions/html-contracts/reference/index.md) › [Element](/docs/extensions/html-contracts/reference/element/index.md) › BlockInterface

| interface | `UIAwesome\Html\Contracts\Element\BlockInterface` |
| --- | --- |
| Extends | [`UIAwesome\Html\Contracts\RenderableInterface`](/docs/extensions/html-contracts/reference/renderableinterface/index.md) |
| Source | [`src/Element/BlockInterface.php`](https://github.com/ui-awesome/html-contracts/blob/main/src/Element/BlockInterface.php#L19) |

Implemented by 1 type:

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

Defines a contract for renderable HTML elements that use separate opening and closing tags.

In this library, "Block" refers to elements rendered with [`begin()`](/docs/extensions/html-contracts/reference/element/blockinterface/index.md#method-begin) and [`end()`](/docs/extensions/html-contracts/reference/element/blockinterface/index.md#method-end) methods, not HTML's
standard block-level content categories.

See also: <https://developer.mozilla.org/en-US/docs/Glossary/Block-level_content>.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`begin()`](#method-begin) abstract | Starts begin/end rendering for this instance. | `BlockInterface` |
| [`end()`](#method-end) static abstract | Ends the most recent begin/end rendering block for the current class. | `BlockInterface` |
| <span id="method-render"></span>[`render()`](/docs/extensions/html-contracts/reference/renderableinterface/index.md#method-render) abstract | Renders the object as an HTML string. | [`UIAwesome\Html\Contracts\RenderableInterface`](/docs/extensions/html-contracts/reference/renderableinterface/index.md) |

## Method details

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

```php
abstract public function begin(): string
```

Starts begin/end rendering for this instance.

Returns the opening markup to the caller, who emits content between `begin()` and `end()`.
Whitespace around streamed content is implementation-specific.

**Returns**

`string`: Opening HTML markup for the element.

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

```php
abstract public static function end(): string
```

Ends the most recent begin/end rendering block for the current class.

**Returns**

`string`: Rendered HTML tag string.

**Throws**

- [`LogicException`](https://www.php.net/manual/en/class.logicexception.php): if no matching `begin()` call is found.
- [`RuntimeException`](https://www.php.net/manual/en/class.runtimeexception.php): if the tag class does not match the expected type.