# BaseHtml

> BaseHtml provides concrete implementation for yii\helpers\Html.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [helpers](/docs/api/yii/helpers/index.md) › BaseHtml

| class | `yii\helpers\BaseHtml` |
| --- | --- |
| Since | 2.0 |
| Source | [`framework/helpers/BaseHtml.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/helpers/BaseHtml.php#L26) |

1 subclass:

- [`Html`](/docs/api/yii/helpers/html/index.md)

BaseHtml provides concrete implementation for [`Html`](/docs/api/yii/helpers/html/index.md).

Do not use BaseHtml. Use [`Html`](/docs/api/yii/helpers/html/index.md) instead.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| [`$attributeOrder`](#property-attributeOrder) static | `array` | The preferred order of attributes in a tag. Default: `['type', 'id', 'class', 'name', 'value', 'href', 'src', 'srcset', 'form', 'action', 'method', 'selected', 'checked', 'readonly', 'disabled', 'multiple', 'size', 'maxlength', 'width', 'height', 'rows', 'cols', 'alt', 'title', 'rel', 'media']`. | `BaseHtml` |
| <span id="property-attributeRegex"></span>`$attributeRegex` static | `string` | Regular expression used for attribute name validation. Default: `'/(^\|.*\])([\w\.\+]+)(\[.*\|$)/u'`. Available since 2.0.12. | `BaseHtml` |
| [`$dataAttributes`](#property-dataAttributes) static | `array` | List of tag attributes that should be specially handled when their values are of array type. Default: `['aria', 'data', 'data-ng', 'ng']`. Available since 2.0.3. | `BaseHtml` |
| <span id="property-normalizeClassAttribute"></span>`$normalizeClassAttribute` static | `bool` | Whether to removes duplicate class names in tag attribute `class` Default: `false`. Available since 2.0.44. | `BaseHtml` |
| <span id="property-voidElements"></span>`$voidElements` static | `array` | List of void elements (element name => 1) Default: `['area' => 1, 'base' => 1, 'br' => 1, 'col' => 1, 'command' => 1, 'embed' => 1, 'hr' => 1, 'img' => 1, 'input' => 1, 'keygen' => 1, 'link' => 1, 'meta' => 1, 'param' => 1, 'source' => 1, 'track' => 1, 'wbr' => 1]`. | `BaseHtml` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`a()`](#method-a) static | Generates a hyperlink tag. | `BaseHtml` |
| [`activeCheckbox()`](#method-activeCheckbox) static | Generates a checkbox tag together with a label for the given model attribute. | `BaseHtml` |
| [`activeCheckboxList()`](#method-activeCheckboxList) static | Generates a list of checkboxes. | `BaseHtml` |
| [`activeDropDownList()`](#method-activeDropDownList) static | Generates a drop-down list for the given model attribute. | `BaseHtml` |
| [`activeFileInput()`](#method-activeFileInput) static | Generates a file input tag for the given model attribute. | `BaseHtml` |
| [`activeHiddenInput()`](#method-activeHiddenInput) static | Generates a hidden input tag for the given model attribute. | `BaseHtml` |
| [`activeHint()`](#method-activeHint) static | Generates a hint tag for the given model attribute. | `BaseHtml` |
| [`activeInput()`](#method-activeInput) static | Generates an input tag for the given model attribute. | `BaseHtml` |
| [`activeLabel()`](#method-activeLabel) static | Generates a label tag for the given model attribute. | `BaseHtml` |
| [`activeListBox()`](#method-activeListBox) static | Generates a list box. | `BaseHtml` |
| [`activePasswordInput()`](#method-activePasswordInput) static | Generates a password input tag for the given model attribute. | `BaseHtml` |
| [`activeRadio()`](#method-activeRadio) static | Generates a radio button tag together with a label for the given model attribute. | `BaseHtml` |
| [`activeRadioList()`](#method-activeRadioList) static | Generates a list of radio buttons. | `BaseHtml` |
| [`activeTextarea()`](#method-activeTextarea) static | Generates a textarea tag for the given model attribute. | `BaseHtml` |
| [`activeTextInput()`](#method-activeTextInput) static | Generates a text input tag for the given model attribute. | `BaseHtml` |
| [`addCssClass()`](#method-addCssClass) static | Adds a CSS class (or several classes) to the specified options. | `BaseHtml` |
| [`addCssStyle()`](#method-addCssStyle) static | Adds the specified CSS style to the HTML options. | `BaseHtml` |
| [`beginForm()`](#method-beginForm) static | Generates a form start tag. | `BaseHtml` |
| [`beginTag()`](#method-beginTag) static | Generates a start tag. | `BaseHtml` |
| [`button()`](#method-button) static | Generates a button tag. | `BaseHtml` |
| [`buttonInput()`](#method-buttonInput) static | Generates an input button. | `BaseHtml` |
| [`checkbox()`](#method-checkbox) static | Generates a checkbox input. | `BaseHtml` |
| [`checkboxList()`](#method-checkboxList) static | Generates a list of checkboxes. | `BaseHtml` |
| [`csrfMetaTags()`](#method-csrfMetaTags) static | Generates the meta tags containing CSRF token information. | `BaseHtml` |
| [`cssFile()`](#method-cssFile) static | Generates a link tag that refers to an external CSS file. | `BaseHtml` |
| [`cssStyleFromArray()`](#method-cssStyleFromArray) static | Converts a CSS style array into a string representation. | `BaseHtml` |
| [`cssStyleToArray()`](#method-cssStyleToArray) static | Converts a CSS style string into an array representation. | `BaseHtml` |
| [`decode()`](#method-decode) static | Decodes special HTML entities back to the corresponding characters. | `BaseHtml` |
| [`dropDownList()`](#method-dropDownList) static | Generates a drop-down list. | `BaseHtml` |
| [`encode()`](#method-encode) static | Encodes special characters into HTML entities. | `BaseHtml` |
| [`endForm()`](#method-endForm) static | Generates a form end tag. | `BaseHtml` |
| [`endTag()`](#method-endTag) static | Generates an end tag. | `BaseHtml` |
| [`error()`](#method-error) static | Generates a tag that contains the first validation error of the specified model attribute. | `BaseHtml` |
| [`errorSummary()`](#method-errorSummary) static | Generates a summary of the validation errors. | `BaseHtml` |
| [`escapeJsRegularExpression()`](#method-escapeJsRegularExpression) static | Escapes regular expression to use in JavaScript. | `BaseHtml` |
| [`fileInput()`](#method-fileInput) static | Generates a file input field. | `BaseHtml` |
| [`getAttributeName()`](#method-getAttributeName) static | Returns the real attribute name from the given attribute expression. | `BaseHtml` |
| [`getAttributeValue()`](#method-getAttributeValue) static | Returns the value of the specified attribute name or expression. | `BaseHtml` |
| [`getInputId()`](#method-getInputId) static | Generates an appropriate input ID for the specified attribute name or expression. | `BaseHtml` |
| [`getInputIdByName()`](#method-getInputIdByName) static | Converts input name to ID. | `BaseHtml` |
| [`getInputName()`](#method-getInputName) static | Generates an appropriate input name for the specified attribute name or expression. | `BaseHtml` |
| [`hiddenInput()`](#method-hiddenInput) static | Generates a hidden input field. | `BaseHtml` |
| [`img()`](#method-img) static | Generates an image tag. | `BaseHtml` |
| [`input()`](#method-input) static | Generates an input type of the given type. | `BaseHtml` |
| [`jsFile()`](#method-jsFile) static | Generates a script tag that refers to an external JavaScript file. | `BaseHtml` |
| [`label()`](#method-label) static | Generates a label tag. | `BaseHtml` |
| [`listBox()`](#method-listBox) static | Generates a list box. | `BaseHtml` |
| [`mailto()`](#method-mailto) static | Generates a mailto hyperlink. | `BaseHtml` |
| [`ol()`](#method-ol) static | Generates an ordered list. | `BaseHtml` |
| [`passwordInput()`](#method-passwordInput) static | Generates a password input field. | `BaseHtml` |
| [`radio()`](#method-radio) static | Generates a radio button input. | `BaseHtml` |
| [`radioList()`](#method-radioList) static | Generates a list of radio buttons. | `BaseHtml` |
| [`removeCssClass()`](#method-removeCssClass) static | Removes a CSS class from the specified options. | `BaseHtml` |
| [`removeCssStyle()`](#method-removeCssStyle) static | Removes the specified CSS style from the HTML options. | `BaseHtml` |
| [`renderSelectOptions()`](#method-renderSelectOptions) static | Renders the option tags that can be used by [`dropDownList()`](/docs/api/yii/helpers/basehtml/index.md#method-dropDownList) and [`listBox()`](/docs/api/yii/helpers/basehtml/index.md#method-listBox). | `BaseHtml` |
| [`renderTagAttributes()`](#method-renderTagAttributes) static | Renders the HTML tag attributes. | `BaseHtml` |
| [`resetButton()`](#method-resetButton) static | Generates a reset button tag. | `BaseHtml` |
| [`resetInput()`](#method-resetInput) static | Generates a reset input button. | `BaseHtml` |
| [`script()`](#method-script) static | Generates a script tag. | `BaseHtml` |
| [`style()`](#method-style) static | Generates a style tag. | `BaseHtml` |
| [`submitButton()`](#method-submitButton) static | Generates a submit button tag. | `BaseHtml` |
| [`submitInput()`](#method-submitInput) static | Generates a submit input button. | `BaseHtml` |
| [`tag()`](#method-tag) static | Generates a complete HTML tag. | `BaseHtml` |
| [`textarea()`](#method-textarea) static | Generates a text area input. | `BaseHtml` |
| [`textInput()`](#method-textInput) static | Generates a text input field. | `BaseHtml` |
| [`ul()`](#method-ul) static | Generates an unordered list. | `BaseHtml` |
| [`activeBooleanInput()`](#method-activeBooleanInput) protected static | Generates a boolean input This method is mainly called by [`activeCheckbox()`](/docs/api/yii/helpers/basehtml/index.md#method-activeCheckbox) and [`activeRadio()`](/docs/api/yii/helpers/basehtml/index.md#method-activeRadio). | `BaseHtml` |
| [`activeListInput()`](#method-activeListInput) protected static | Generates a list of input fields. | `BaseHtml` |
| [`booleanInput()`](#method-booleanInput) protected static | Generates a boolean input. | `BaseHtml` |
| [`setActivePlaceholder()`](#method-setActivePlaceholder) protected static | Generate placeholder from model attribute label. | `BaseHtml` |

## Property details

### $attributeOrder <span id="property-attributeOrder"></span>

```php
public static array $attributeOrder = ['type', 'id', 'class', 'name', 'value', 'href', 'src', 'srcset', 'form', 'action', 'method', 'selected', 'checked', 'readonly', 'disabled', 'multiple', 'size', 'maxlength', 'width', 'height', 'rows', 'cols', 'alt', 'title', 'rel', 'media']
```

The preferred order of attributes in a tag.

This mainly affects the order of the attributes
that are rendered by [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes).

### $dataAttributes <span id="property-dataAttributes"></span>

```php
public static array $dataAttributes = ['aria', 'data', 'data-ng', 'ng']
```

List of tag attributes that should be specially handled when their values are of array type.

In particular, if the value of the `data` attribute is `['name' => 'xyz', 'age' => 13]`, two attributes
will be generated instead of one: `data-name="xyz" data-age="13"`.

**Since**

2.0.3

## Method details

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

```php
public static function a(string $text, array|string|null $url = null, array $options = []): string
```

Generates a hyperlink tag.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$text` | `string` | Link body. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is coming from end users, you should consider [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode) it to prevent XSS attacks. |
| `$url` | `array\|string\|null` | The URL for the hyperlink tag. This parameter will be processed by [`Url::to()`](/docs/api/yii/helpers/baseurl/index.md#method-to) and will be used for the "href" attribute of the tag. If this parameter is null, the "href" attribute will not be generated. If you want to use an absolute url you can call [`Url::to()`](/docs/api/yii/helpers/baseurl/index.md#method-to) yourself, before passing the URL to this method, like this: Html::a('link text', Url::to($url, true)) |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated hyperlink

**See also**

- [`Url::to()`](/docs/api/yii/helpers/baseurl/index.md#method-to)

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

```php
public static function activeCheckbox(yii\base\Model $model, string $attribute, array $options = []): string
```

Generates a checkbox tag together with a label for the given model attribute.

This method will generate the "checked" tag attribute according to the model attribute value.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression. See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$options` | `array` | The tag options in terms of name-value pairs. See [`booleanInput()`](/docs/api/yii/helpers/basehtml/index.md#method-booleanInput) for details about accepted attributes. |

**Returns**

`string`: The generated checkbox tag

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

```php
public static function activeCheckboxList(yii\base\Model $model, string $attribute, array $items, array $options = []): string
```

Generates a list of checkboxes.

A checkbox list allows multiple selection, like [`listBox()`](/docs/api/yii/helpers/basehtml/index.md#method-listBox).
As a result, the corresponding submitted value is an array.
The selection of the checkbox list is taken from the value of the model attribute.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression. See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$items` | `array` | The data item used to generate the checkboxes. The array keys are the checkbox values, and the array values are the corresponding labels. |
| `$options` | `array` | Options (name => config) for the checkbox list container tag. The following options are specially handled: - tag: string\|false, the tag name of the container element. False to render checkbox without container. See also [`tag()`](/docs/api/yii/helpers/basehtml/index.md#method-tag). - unselect: string, the value that should be submitted when none of the checkboxes is selected. You may set this option to be null to prevent default value submission. If this option is not set, an empty string will be submitted. - encode: boolean, whether to HTML-encode the checkbox labels. Defaults to true. This option is ignored if `item` option is set. - separator: string, the HTML code that separates items. - itemOptions: array, the options for generating the checkbox tag using [`checkbox()`](/docs/api/yii/helpers/basehtml/index.md#method-checkbox). - item: callable, a callback that can be used to customize the generation of the HTML code corresponding to a single item in $items. The signature of this callback must be: function ($index, $label, $name, $checked, $value) where $index is the zero-based index of the checkbox in the whole list; $label is the label for the checkbox; and $name, $value and $checked represent the name, value and the checked status of the checkbox input. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated checkbox list

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

```php
public static function activeDropDownList(yii\base\Model $model, string $attribute, array $items, array $options = []): string
```

Generates a drop-down list for the given model attribute.

The selection of the drop-down list is taken from the value of the model attribute.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression. See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$items` | `array` | The option data items. The array keys are option values, and the array values are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too). For each sub-array, an option group will be generated whose label is the key associated with the sub-array. If you have a list of data models, you may convert them into the format described above using [`ArrayHelper::map()`](/docs/api/yii/helpers/basearrayhelper/index.md#method-map). Note, the values and labels will be automatically HTML-encoded by this method, and the blank spaces in the labels will also be HTML-encoded. |
| `$options` | `array` | The tag options in terms of name-value pairs. The following options are specially handled: - prompt: string, a prompt text to be displayed as the first option. Since version 2.0.11 you can use an array to override the value and to set other tag attributes: ['text' => 'Please select', 'options' => ['value' => 'none', 'class' => 'prompt', 'label' => 'Select']], - options: array, the attributes for the select option tags. The array keys must be valid option values, and the array values are the extra attributes for the corresponding option tags. For example, [ 'value1' => ['disabled' => true], 'value2' => ['label' => 'value 2'], ]; - groups: array, the attributes for the optgroup tags. The structure of this is similar to that of 'options', except that the array keys represent the optgroup labels specified in $items. - encodeSpaces: bool, whether to encode spaces in option prompt and option value with `&nbsp;` character. Defaults to false. - encode: bool, whether to encode option prompt and option value characters. Defaults to `true`. This option is available since 2.0.3. The rest of the options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated drop-down list tag

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

```php
public static function activeFileInput(yii\base\Model $model, string $attribute, array $options = []): string
```

Generates a file input tag for the given model attribute.

This method will generate the "name" and "value" tag attributes automatically for the model attribute
unless they are explicitly specified in `$options`.
Additionally, if a separate set of HTML options array is defined inside `$options` with a key named `hiddenOptions`,
it will be passed to the `activeHiddenInput` field as its own `$options` parameter.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression. See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. If `hiddenOptions` parameter which is another set of HTML options array is defined, it will be extracted from `$options` to be used for the hidden input. |

**Returns**

`string`: The generated input tag

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

```php
public static function activeHiddenInput(yii\base\Model $model, string $attribute, array $options = []): string
```

Generates a hidden input tag for the given model attribute.

This method will generate the "name" and "value" tag attributes automatically for the model attribute
unless they are explicitly specified in `$options`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression. See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated input tag

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

```php
public static function activeHint(yii\base\Model $model, string $attribute, array $options = []): string
```

Generates a hint tag for the given model attribute.

The hint text is the hint associated with the attribute, obtained via [`Model::getAttributeHint()`](/docs/api/yii/base/model/index.md#method-getAttributeHint).
If no hint content can be obtained, method will return an empty string.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression. See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. The following options are specially handled: - hint: this specifies the hint to be displayed. Note that this will NOT be [encoded](/docs/api/yii/helpers/basehtml/index.md#method-encode). If this is not set, [`Model::getAttributeHint()`](/docs/api/yii/base/model/index.md#method-getAttributeHint) will be called to get the hint for display (without encoding). See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated hint tag

**Since**

2.0.4

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

```php
public static function activeInput(string $type, yii\base\Model $model, string $attribute, array $options = []): string
```

Generates an input tag for the given model attribute.

This method will generate the "name" and "value" tag attributes automatically for the model attribute
unless they are explicitly specified in `$options`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$type` | `string` | The input type (e.g. 'text', 'password') |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression. See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated input tag

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

```php
public static function activeLabel(yii\base\Model $model, string $attribute, array $options = []): string
```

Generates a label tag for the given model attribute.

The label text is the label associated with the attribute, obtained via [`Model::getAttributeLabel()`](/docs/api/yii/base/model/index.md#method-getAttributeLabel).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression. See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. The following options are specially handled: - label: this specifies the label to be displayed. Note that this will NOT be [encoded](/docs/api/yii/helpers/basehtml/index.md#method-encode). If this is not set, [`Model::getAttributeLabel()`](/docs/api/yii/base/model/index.md#method-getAttributeLabel) will be called to get the label for display (after encoding). See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated label tag

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

```php
public static function activeListBox(yii\base\Model $model, string $attribute, array $items, array $options = []): string
```

Generates a list box.

The selection of the list box is taken from the value of the model attribute.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression. See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$items` | `array` | The option data items. The array keys are option values, and the array values are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too). For each sub-array, an option group will be generated whose label is the key associated with the sub-array. If you have a list of data models, you may convert them into the format described above using [`ArrayHelper::map()`](/docs/api/yii/helpers/basearrayhelper/index.md#method-map). Note, the values and labels will be automatically HTML-encoded by this method, and the blank spaces in the labels will also be HTML-encoded. |
| `$options` | `array` | The tag options in terms of name-value pairs. The following options are specially handled: - prompt: string, a prompt text to be displayed as the first option. Since version 2.0.11 you can use an array to override the value and to set other tag attributes: ['text' => 'Please select', 'options' => ['value' => 'none', 'class' => 'prompt', 'label' => 'Select']], - options: array, the attributes for the select option tags. The array keys must be valid option values, and the array values are the extra attributes for the corresponding option tags. For example, [ 'value1' => ['disabled' => true], 'value2' => ['label' => 'value 2'], ]; - groups: array, the attributes for the optgroup tags. The structure of this is similar to that of 'options', except that the array keys represent the optgroup labels specified in $items. - unselect: string, the value that will be submitted when no option is selected. When this attribute is set, a hidden field will be generated so that if no option is selected in multiple mode, we can still obtain the posted unselect value. - encodeSpaces: bool, whether to encode spaces in option prompt and option value with `&nbsp;` character. Defaults to false. - encode: bool, whether to encode option prompt and option value characters. Defaults to `true`. This option is available since 2.0.3. The rest of the options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated list box tag

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

```php
public static function activePasswordInput(yii\base\Model $model, string $attribute, array $options = []): string
```

Generates a password input tag for the given model attribute.

This method will generate the "name" and "value" tag attributes automatically for the model attribute
unless they are explicitly specified in `$options`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression. See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. The following special options are recognized: - maxlength: integer\|boolean, when `maxlength` is set true and the model attribute is validated by a string validator, the `maxlength` option will take the max value of [`StringValidator::$max`](/docs/api/yii/validators/stringvalidator/index.md#property-max) and [[\yii\validators\StringValidator::length]. This is available since version 2.0.6 and improved taking `length` into account since version 2.0.42. - placeholder: string\|boolean, when `placeholder` equals `true`, the attribute label from the $model will be used as a placeholder (this behavior is available since version 2.0.14). |

**Returns**

`string`: The generated input tag

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

```php
public static function activeRadio(yii\base\Model $model, string $attribute, array $options = []): string
```

Generates a radio button tag together with a label for the given model attribute.

This method will generate the "checked" tag attribute according to the model attribute value.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression. See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$options` | `array` | The tag options in terms of name-value pairs. See [`booleanInput()`](/docs/api/yii/helpers/basehtml/index.md#method-booleanInput) for details about accepted attributes. |

**Returns**

`string`: The generated radio button tag

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

```php
public static function activeRadioList(yii\base\Model $model, string $attribute, array $items, array $options = []): string
```

Generates a list of radio buttons.

A radio button list is like a checkbox list, except that it only allows single selection.
The selection of the radio buttons is taken from the value of the model attribute.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression. See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$items` | `array` | The data item used to generate the radio buttons. The array keys are the radio values, and the array values are the corresponding labels. |
| `$options` | `array` | Options (name => config) for the radio button list container tag. The following options are specially handled: - tag: string\|false, the tag name of the container element. False to render radio button without container. See also [`tag()`](/docs/api/yii/helpers/basehtml/index.md#method-tag). - unselect: string, the value that should be submitted when none of the radio buttons is selected. You may set this option to be null to prevent default value submission. If this option is not set, an empty string will be submitted. - encode: boolean, whether to HTML-encode the checkbox labels. Defaults to true. This option is ignored if `item` option is set. - separator: string, the HTML code that separates items. - itemOptions: array, the options for generating the radio button tag using [`radio()`](/docs/api/yii/helpers/basehtml/index.md#method-radio). - item: callable, a callback that can be used to customize the generation of the HTML code corresponding to a single item in $items. The signature of this callback must be: function ($index, $label, $name, $checked, $value) where $index is the zero-based index of the radio button in the whole list; $label is the label for the radio button; and $name, $value and $checked represent the name, value and the checked status of the radio button input. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated radio button list

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

```php
public static function activeTextarea(yii\base\Model $model, string $attribute, array $options = []): string
```

Generates a textarea tag for the given model attribute.

The model attribute value will be used as the content in the textarea.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression. See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. The following special options are recognized: - maxlength: integer\|boolean, when `maxlength` is set true and the model attribute is validated by a string validator, the `maxlength` option will take the max value of [`StringValidator::$max`](/docs/api/yii/validators/stringvalidator/index.md#property-max) and [[\yii\validators\StringValidator::length]. This is available since version 2.0.6 and improved taking `length` into account since version 2.0.42. - placeholder: string\|boolean, when `placeholder` equals `true`, the attribute label from the $model will be used as a placeholder (this behavior is available since version 2.0.14). |

**Returns**

`string`: The generated textarea tag

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

```php
public static function activeTextInput(yii\base\Model $model, string $attribute, array $options = []): string
```

Generates a text input tag for the given model attribute.

This method will generate the "name" and "value" tag attributes automatically for the model attribute
unless they are explicitly specified in `$options`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression. See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. The following special options are recognized: - maxlength: integer\|boolean, when `maxlength` is set true and the model attribute is validated by a string validator, the `maxlength` option will take the max value of [`StringValidator::$max`](/docs/api/yii/validators/stringvalidator/index.md#property-max) and [[\yii\validators\StringValidator::length]. This is available since version 2.0.3 and improved taking `length` into account since version 2.0.42. - placeholder: string\|boolean, when `placeholder` equals `true`, the attribute label from the $model will be used as a placeholder (this behavior is available since version 2.0.14). |

**Returns**

`string`: The generated input tag

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

```php
public static function addCssClass(array &$options, string|array $class): mixed
```

Adds a CSS class (or several classes) to the specified options.

If the CSS class is already in the options, it will not be added again.
If class specification at given options is an array, and some class placed there with the named (string) key,
overriding of such key will have no effect. For example:

```
$options = ['class' => ['persistent' => 'initial']];
Html::addCssClass($options, ['persistent' => 'override']);
var_dump($options['class']); // outputs: array('persistent' => 'initial');
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$options` | `array` | The options to be modified. |
| `$class` | `string\|array` | The CSS class(es) to be added |

**Returns**

`mixed`

**See also**

- [`removeCssClass()`](/docs/api/yii/helpers/basehtml/index.md#method-removeCssClass)

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

```php
public static function addCssStyle(array &$options, string|array $style, bool $overwrite = true): mixed
```

Adds the specified CSS style to the HTML options.

If the options already contain a `style` element, the new style will be merged
with the existing one. If a CSS property exists in both the new and the old styles,
the old one may be overwritten if `$overwrite` is true.

For example,

```
Html::addCssStyle($options, 'width: 100px; height: 200px');
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$options` | `array` | The HTML options to be modified. |
| `$style` | `string\|array` | The new style string (e.g. `'width: 100px; height: 200px'`) or array (e.g. `['width' => '100px', 'height' => '200px']`). |
| `$overwrite` | `bool` | Whether to overwrite existing CSS properties if the new style contain them too. |

**Returns**

`mixed`

**See also**

- [`removeCssStyle()`](/docs/api/yii/helpers/basehtml/index.md#method-removeCssStyle)
- [`cssStyleFromArray()`](/docs/api/yii/helpers/basehtml/index.md#method-cssStyleFromArray)
- [`cssStyleToArray()`](/docs/api/yii/helpers/basehtml/index.md#method-cssStyleToArray)

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

```php
public static function beginForm(array|string $action = '', string $method = 'post', array $options = []): string
```

Generates a form start tag.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$action` | `array\|string` | The form action URL. This parameter will be processed by [`Url::to()`](/docs/api/yii/helpers/baseurl/index.md#method-to). |
| `$method` | `string` | The form submission method, such as "post", "get", "put", "delete" (case-insensitive). Since most browsers only support "post" and "get", if other methods are given, they will be simulated using "post", and a hidden input will be added which contains the actual method type. See [`Request::$methodParam`](/docs/api/yii/web/request/index.md#property-methodParam) for more details. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. Special options: - `csrf`: whether to generate the CSRF hidden input. Defaults to true. |

**Returns**

`string`: The generated form start tag.

**See also**

- [`endForm()`](/docs/api/yii/helpers/basehtml/index.md#method-endForm)

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

```php
public static function beginTag(string|bool|null $name, array $options = []): string
```

Generates a start tag.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string\|bool\|null` | The tag name. If $name is `null` or `false`, the corresponding content will be rendered without any tag. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated start tag

**See also**

- [`endTag()`](/docs/api/yii/helpers/basehtml/index.md#method-endTag)
- [`tag()`](/docs/api/yii/helpers/basehtml/index.md#method-tag)

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

```php
public static function button(string $content = 'Button', array $options = []): string
```

Generates a button tag.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$content` | `string` | The content enclosed within the button tag. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should consider [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode) it to prevent XSS attacks. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated button tag

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

```php
public static function buttonInput(string|null $label = 'Button', array $options = []): string
```

Generates an input button.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$label` | `string\|null` | The value attribute. If it is null, the value attribute will not be generated. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated button tag

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

```php
public static function checkbox(string $name, bool $checked = false, array $options = []): string
```

Generates a checkbox input.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The name attribute. |
| `$checked` | `bool` | Whether the checkbox should be checked. |
| `$options` | `array` | The tag options in terms of name-value pairs. See [`booleanInput()`](/docs/api/yii/helpers/basehtml/index.md#method-booleanInput) for details about accepted attributes. |

**Returns**

`string`: The generated checkbox tag

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

```php
public static function checkboxList(string $name, string|array|null $selection = null, array $items = [], array $options = []): string
```

Generates a list of checkboxes.

A checkbox list allows multiple selection, like [`listBox()`](/docs/api/yii/helpers/basehtml/index.md#method-listBox).
As a result, the corresponding submitted value is an array.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The name attribute of each checkbox. |
| `$selection` | `string\|array\|null` | The selected value(s). String for single or array for multiple selection(s). |
| `$items` | `array` | The data item used to generate the checkboxes. The array keys are the checkbox values, while the array values are the corresponding labels. |
| `$options` | `array` | Options (name => config) for the checkbox list container tag. The following options are specially handled: - tag: string\|false, the tag name of the container element. False to render checkbox without container. See also [`tag()`](/docs/api/yii/helpers/basehtml/index.md#method-tag). - unselect: string, the value that should be submitted when none of the checkboxes is selected. By setting this option, a hidden input will be generated. - disabled: boolean, whether the generated by unselect option hidden input should be disabled. Defaults to false. This option is available since version 2.0.16. - encode: boolean, whether to HTML-encode the checkbox labels. Defaults to true. This option is ignored if `item` option is set. - strict: boolean, if `$selection` is an array and this value is true a strict comparison will be performed on `$items` keys. Defaults to false. This option is available since 2.0.37. - separator: string, the HTML code that separates items. - itemOptions: array, the options for generating the checkbox tag using [`checkbox()`](/docs/api/yii/helpers/basehtml/index.md#method-checkbox). - item: callable, a callback that can be used to customize the generation of the HTML code corresponding to a single item in $items. The signature of this callback must be: function ($index, $label, $name, $checked, $value) where $index is the zero-based index of the checkbox in the whole list; $label is the label for the checkbox; and $name, $value and $checked represent the name, value and the checked status of the checkbox input, respectively. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated checkbox list

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

```php
public static function csrfMetaTags(): string
```

Generates the meta tags containing CSRF token information.

**Returns**

`string`: The generated meta tags

**See also**

- [`Request::$enableCsrfValidation`](/docs/api/yii/web/request/index.md#property-enableCsrfValidation)

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

```php
public static function cssFile(array|string $url, array $options = []): string
```

Generates a link tag that refers to an external CSS file.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$url` | `array\|string` | The URL of the external CSS file. This parameter will be processed by [`Url::to()`](/docs/api/yii/helpers/baseurl/index.md#method-to). |
| `$options` | `array` | The tag options in terms of name-value pairs. The following options are specially handled: - condition: specifies the conditional comments for IE, e.g., `lt IE 9`. When this is specified, the generated `link` tag will be enclosed within the conditional comments. This is mainly useful for supporting old versions of IE browsers. - noscript: if set to true, `link` tag will be wrapped into `<noscript>` tags. The rest of the options will be rendered as the attributes of the resulting link tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated link tag

**See also**

- [`Url::to()`](/docs/api/yii/helpers/baseurl/index.md#method-to)

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

```php
public static function cssStyleFromArray(array $style): string
```

Converts a CSS style array into a string representation.

For example,

```
print_r(Html::cssStyleFromArray(['width' => '100px', 'height' => '200px']));
// will display: 'width: 100px; height: 200px;'
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$style` | `array` | The CSS style array. The array keys are the CSS property names, and the array values are the corresponding CSS property values. |

**Returns**

`string`: The CSS style string. If the CSS style is empty, a null will be returned.

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

```php
public static function cssStyleToArray(string $style): array
```

Converts a CSS style string into an array representation.

The array keys are the CSS property names, and the array values
are the corresponding CSS property values.

For example,

```
print_r(Html::cssStyleToArray('width: 100px; height: 200px;'));
// will display: ['width' => '100px', 'height' => '200px']
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$style` | `string` | The CSS style string |

**Returns**

`array`: The array representation of the CSS style

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

```php
public static function decode(string $content): string
```

Decodes special HTML entities back to the corresponding characters.

This is the opposite of [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$content` | `string` | The content to be decoded |

**Returns**

`string`: The decoded content

**See also**

- [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode)
- <https://www.php.net/manual/en/function.htmlspecialchars-decode.php>

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

```php
public static function dropDownList(string $name, string|bool|array|null $selection = null, array $items = [], array $options = []): string
```

Generates a drop-down list.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The input name |
| `$selection` | `string\|bool\|array\|null` | The selected value(s). String/boolean for single or array for multiple selection(s). |
| `$items` | `array` | The option data items. The array keys are option values, and the array values are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too). For each sub-array, an option group will be generated whose label is the key associated with the sub-array. If you have a list of data models, you may convert them into the format described above using [`ArrayHelper::map()`](/docs/api/yii/helpers/basearrayhelper/index.md#method-map). Note, the values and labels will be automatically HTML-encoded by this method, and the blank spaces in the labels will also be HTML-encoded. |
| `$options` | `array` | The tag options in terms of name-value pairs. The following options are specially handled: - prompt: string, a prompt text to be displayed as the first option. Since version 2.0.11 you can use an array to override the value and to set other tag attributes: ['text' => 'Please select', 'options' => ['value' => 'none', 'class' => 'prompt', 'label' => 'Select']], - options: array, the attributes for the select option tags. The array keys must be valid option values, and the array values are the extra attributes for the corresponding option tags. For example, [ 'value1' => ['disabled' => true], 'value2' => ['label' => 'value 2'], ]; - groups: array, the attributes for the optgroup tags. The structure of this is similar to that of 'options', except that the array keys represent the optgroup labels specified in $items. - encodeSpaces: bool, whether to encode spaces in option prompt and option value with `&nbsp;` character. Defaults to false. - encode: bool, whether to encode option prompt and option value characters. Defaults to `true`. This option is available since 2.0.3. - strict: boolean, if `$selection` is an array and this value is true a strict comparison will be performed on `$items` keys. Defaults to false. This option is available since 2.0.37. The rest of the options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated drop-down list tag

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

```php
public static function encode(string $content, bool $doubleEncode = true): string
```

Encodes special characters into HTML entities.

The [application charset](/docs/api/yii/base/application/index.md#property-charset) will be used for encoding.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$content` | `string` | The content to be encoded |
| `$doubleEncode` | `bool` | Whether to encode HTML entities in `$content`. If false, HTML entities in `$content` will not be further encoded. |

**Returns**

`string`: The encoded content

**See also**

- [`decode()`](/docs/api/yii/helpers/basehtml/index.md#method-decode)
- <https://www.php.net/manual/en/function.htmlspecialchars.php>

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

```php
public static function endForm(): string
```

Generates a form end tag.

**Returns**

`string`: The generated tag

**See also**

- [`beginForm()`](/docs/api/yii/helpers/basehtml/index.md#method-beginForm)

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

```php
public static function endTag(string|bool|null $name): string
```

Generates an end tag.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string\|bool\|null` | The tag name. If $name is `null` or `false`, the corresponding content will be rendered without any tag. |

**Returns**

`string`: The generated end tag

**See also**

- [`beginTag()`](/docs/api/yii/helpers/basehtml/index.md#method-beginTag)
- [`tag()`](/docs/api/yii/helpers/basehtml/index.md#method-tag)

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

```php
public static function error(yii\base\Model $model, string $attribute, array $options = []): string
```

Generates a tag that contains the first validation error of the specified model attribute.

Note that even if there is no validation error, this method will still return an empty error tag.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression. See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$options` | `array` | The tag options in terms of name-value pairs. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. The following options are specially handled: - tag: this specifies the tag name. If not set, "div" will be used. See also [`tag()`](/docs/api/yii/helpers/basehtml/index.md#method-tag). - encode: boolean, if set to false then the error message won't be encoded. - errorSource (since 2.0.14): \Closure\|callable, callback that will be called to obtain an error message. The signature of the callback must be: `function ($model, $attribute)` and return a string. When not set, the `$model->getFirstError()` method will be called. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated label tag

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

```php
public static function errorSummary(yii\base\Model|yii\base\Model[] $models, array $options = []): string
```

Generates a summary of the validation errors.

If there is no validation error, an empty error summary markup will still be generated, but it will be hidden.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$models` | [`yii\base\Model`](/docs/api/yii/base/model/index.md)`\|`[`yii\base\Model`](/docs/api/yii/base/model/index.md)`[]` | The model(s) whose validation errors are to be displayed. |
| `$options` | `array` | The tag options in terms of name-value pairs. The following options are specially handled: - header: string, the header HTML for the error summary. If not set, a default prompt string will be used. - footer: string, the footer HTML for the error summary. Defaults to empty string. - encode: boolean, if set to false then the error messages won't be encoded. Defaults to `true`. - showAllErrors: boolean, if set to true every error message for each attribute will be shown otherwise only the first error message for each attribute will be shown. Defaults to `false`. Option is available since 2.0.10. - emptyClass: string, the class name that is added to an empty summary. The rest of the options will be rendered as the attributes of the container tag. |

**Returns**

`string`: The generated error summary

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

```php
public static function escapeJsRegularExpression(string $regexp): string
```

Escapes regular expression to use in JavaScript.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$regexp` | `string` | The regular expression to be escaped. |

**Returns**

`string`: The escaped result.

**Since**

2.0.6

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

```php
public static function fileInput(string $name, string|null $value = null, array $options = []): string
```

Generates a file input field.

To use a file input field, you should set the enclosing form's "enctype" attribute to
be "multipart/form-data". After the form is submitted, the uploaded file information
can be obtained via $_FILES[$name] (see PHP documentation).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The name attribute. |
| `$value` | `string\|null` | The value attribute. If it is null, the value attribute will not be generated. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated file input tag

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

```php
public static function getAttributeName(string $attribute): string
```

Returns the real attribute name from the given attribute expression.

An attribute expression is an attribute name prefixed and/or suffixed with array indexes.
It is mainly used in tabular data input and/or input of array type. Below are some examples:

- `[0]content` is used in tabular data input to represent the "content" attribute
  for the first model in tabular input;
- `dates[0]` represents the first array element of the "dates" attribute;
- `[0]dates[0]` represents the first array element of the "dates" attribute
  for the first model in tabular input.

If `$attribute` has neither prefix nor suffix, it will be returned back without change.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$attribute` | `string` | The attribute name or expression |

**Returns**

`string`: The attribute name without prefix and suffix.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the attribute name contains non-word characters.

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

```php
public static function getAttributeValue(yii\base\Model $model, string $attribute): string|array|null
```

Returns the value of the specified attribute name or expression.

For an attribute expression like `[0]dates[0]`, this method will return the value of `$model->dates[0]`.
See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for more details about attribute expression.

If an attribute value is an instance of [`ActiveRecordInterface`](/docs/api/yii/db/activerecordinterface/index.md) or an array of such instances,
the primary value(s) of the AR instance(s) will be returned instead.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression |

**Returns**

`string|array|null`: The corresponding attribute value

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the attribute name contains non-word characters.

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

```php
public static function getInputId(yii\base\Model $model, string $attribute): string
```

Generates an appropriate input ID for the specified attribute name or expression.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression. See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for explanation of attribute expression. |

**Returns**

`string`: The generated input ID.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the attribute name contains non-word characters.

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

```php
public static function getInputIdByName(string $name): string
```

Converts input name to ID.

For example, if `$name` is `Post[content]`, this method will return `post-content`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The input name |

**Returns**

`string`: The generated input ID

**Since**

2.0.43

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

```php
public static function getInputName(yii\base\Model $model, string $attribute): string
```

Generates an appropriate input name for the specified attribute name or expression.

This method generates a name that can be used as the input name to collect user input
for the specified attribute. The name is generated according to the [form name](/docs/api/yii/base/model/index.md#method-formName)
of the model and the given attribute name. For example, if the form name of the `Post` model
is `Post`, then the input name generated for the `content` attribute would be `Post[content]`.

See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for explanation of attribute expression.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression |

**Returns**

`string`: The generated input name

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the attribute name contains non-word characters.

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

```php
public static function hiddenInput(string $name, string|null $value = null, array $options = []): string
```

Generates a hidden input field.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The name attribute. |
| `$value` | `string\|null` | The value attribute. If it is null, the value attribute will not be generated. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated hidden input tag

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

```php
public static function img(array|string $src, array $options = []): string
```

Generates an image tag.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$src` | `array\|string` | The image URL. This parameter will be processed by [`Url::to()`](/docs/api/yii/helpers/baseurl/index.md#method-to). |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. Since version 2.0.12 It is possible to pass the `srcset` option as an array which keys are descriptors and values are URLs. All URLs will be processed by [`Url::to()`](/docs/api/yii/helpers/baseurl/index.md#method-to). |

**Returns**

`string`: The generated image tag.

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

```php
public static function input(string $type, string|null $name = null, string|null $value = null, array $options = []): string
```

Generates an input type of the given type.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$type` | `string` | The type attribute. |
| `$name` | `string\|null` | The name attribute. If it is null, the name attribute will not be generated. |
| `$value` | `string\|null` | The value attribute. If it is null, the value attribute will not be generated. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated input tag

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

```php
public static function jsFile(string $url, array $options = []): string
```

Generates a script tag that refers to an external JavaScript file.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$url` | `string` | The URL of the external JavaScript file. This parameter will be processed by [`Url::to()`](/docs/api/yii/helpers/baseurl/index.md#method-to). |
| `$options` | `array` | The tag options in terms of name-value pairs. The following option is specially handled: - condition: specifies the conditional comments for IE, e.g., `lt IE 9`. When this is specified, the generated `script` tag will be enclosed within the conditional comments. This is mainly useful for supporting old versions of IE browsers. The rest of the options will be rendered as the attributes of the resulting script tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated script tag

**See also**

- [`Url::to()`](/docs/api/yii/helpers/baseurl/index.md#method-to)

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

```php
public static function label(string $content, string|null $for = null, array $options = []): string
```

Generates a label tag.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$content` | `string` | Label text. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode) it to prevent XSS attacks. |
| `$for` | `string\|null` | The ID of the HTML element that this label is associated with. If this is null, the "for" attribute will not be generated. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated label tag

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

```php
public static function listBox(string $name, string|bool|array|null $selection = null, array $items = [], array $options = []): string
```

Generates a list box.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The input name |
| `$selection` | `string\|bool\|array\|null` | The selected value(s). String for single or array for multiple selection(s). |
| `$items` | `array` | The option data items. The array keys are option values, and the array values are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too). For each sub-array, an option group will be generated whose label is the key associated with the sub-array. If you have a list of data models, you may convert them into the format described above using [`ArrayHelper::map()`](/docs/api/yii/helpers/basearrayhelper/index.md#method-map). Note, the values and labels will be automatically HTML-encoded by this method, and the blank spaces in the labels will also be HTML-encoded. |
| `$options` | `array` | The tag options in terms of name-value pairs. The following options are specially handled: - prompt: string, a prompt text to be displayed as the first option. Since version 2.0.11 you can use an array to override the value and to set other tag attributes: ['text' => 'Please select', 'options' => ['value' => 'none', 'class' => 'prompt', 'label' => 'Select']], - options: array, the attributes for the select option tags. The array keys must be valid option values, and the array values are the extra attributes for the corresponding option tags. For example, [ 'value1' => ['disabled' => true], 'value2' => ['label' => 'value 2'], ]; - groups: array, the attributes for the optgroup tags. The structure of this is similar to that of 'options', except that the array keys represent the optgroup labels specified in $items. - unselect: string, the value that will be submitted when no option is selected. When this attribute is set, a hidden field will be generated so that if no option is selected in multiple mode, we can still obtain the posted unselect value. - encodeSpaces: bool, whether to encode spaces in option prompt and option value with `&nbsp;` character. Defaults to false. - encode: bool, whether to encode option prompt and option value characters. Defaults to `true`. This option is available since 2.0.3. - strict: boolean, if `$selection` is an array and this value is true a strict comparison will be performed on `$items` keys. Defaults to false. This option is available since 2.0.37. The rest of the options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated list box tag

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

```php
public static function mailto(string $text, string|null $email = null, array $options = []): string
```

Generates a mailto hyperlink.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$text` | `string` | Link body. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is coming from end users, you should consider [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode) it to prevent XSS attacks. |
| `$email` | `string\|null` | Email address. If this is null, the first parameter (link body) will be treated as the email address and used. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated mailto link

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

```php
public static function ol(array|Traversable $items, array $options = []): string
```

Generates an ordered list.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$items` | `array\|`[`Traversable`](https://www.php.net/manual/en/class.traversable.php) | The items for generating the list. Each item generates a single list item. Note that items will be automatically HTML encoded if `$options['encode']` is not set or true. |
| `$options` | `array` | Options (name => config) for the radio button list. The following options are supported: - encode: boolean, whether to HTML-encode the items. Defaults to true. This option is ignored if the `item` option is specified. - itemOptions: array, the HTML attributes for the `li` tags. This option is ignored if the `item` option is specified. - item: callable, a callback that is used to generate each individual list item. The signature of this callback must be: function ($item, $index) where $index is the array key corresponding to `$item` in `$items`. The callback should return the whole list item tag. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated ordered list. An empty string is returned if `$items` is empty.

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

```php
public static function passwordInput(string $name, string|null $value = null, array $options = []): string
```

Generates a password input field.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The name attribute. |
| `$value` | `string\|null` | The value attribute. If it is null, the value attribute will not be generated. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated password input tag

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

```php
public static function radio(string $name, bool $checked = false, array $options = []): string
```

Generates a radio button input.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The name attribute. |
| `$checked` | `bool` | Whether the radio button should be checked. |
| `$options` | `array` | The tag options in terms of name-value pairs. See [`booleanInput()`](/docs/api/yii/helpers/basehtml/index.md#method-booleanInput) for details about accepted attributes. |

**Returns**

`string`: The generated radio button tag

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

```php
public static function radioList(string $name, string|array|null $selection = null, array $items = [], array $options = []): string
```

Generates a list of radio buttons.

A radio button list is like a checkbox list, except that it only allows single selection.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The name attribute of each radio button. |
| `$selection` | `string\|array\|null` | The selected value(s). String for single or array for multiple selection(s). |
| `$items` | `array` | The data item used to generate the radio buttons. The array keys are the radio button values, while the array values are the corresponding labels. |
| `$options` | `array` | Options (name => config) for the radio button list container tag. The following options are specially handled: - tag: string\|false, the tag name of the container element. False to render radio buttons without container. See also [`tag()`](/docs/api/yii/helpers/basehtml/index.md#method-tag). - unselect: string, the value that should be submitted when none of the radio buttons is selected. By setting this option, a hidden input will be generated. - disabled: boolean, whether the generated by unselect option hidden input should be disabled. Defaults to false. This option is available since version 2.0.16. - encode: boolean, whether to HTML-encode the checkbox labels. Defaults to true. This option is ignored if `item` option is set. - strict: boolean, if `$selection` is an array and this value is true a strict comparison will be performed on `$items` keys. Defaults to false. This option is available since 2.0.37. - separator: string, the HTML code that separates items. - itemOptions: array, the options for generating the radio button tag using [`radio()`](/docs/api/yii/helpers/basehtml/index.md#method-radio). - item: callable, a callback that can be used to customize the generation of the HTML code corresponding to a single item in $items. The signature of this callback must be: function ($index, $label, $name, $checked, $value) where $index is the zero-based index of the radio button in the whole list; $label is the label for the radio button; and $name, $value and $checked represent the name, value and the checked status of the radio button input, respectively. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated radio button list

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

```php
public static function removeCssClass(array &$options, string|array $class): mixed
```

Removes a CSS class from the specified options.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$options` | `array` | The options to be modified. |
| `$class` | `string\|array` | The CSS class(es) to be removed |

**Returns**

`mixed`

**See also**

- [`addCssClass()`](/docs/api/yii/helpers/basehtml/index.md#method-addCssClass)

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

```php
public static function removeCssStyle(array &$options, string|array $properties): mixed
```

Removes the specified CSS style from the HTML options.

For example,

```
Html::removeCssStyle($options, ['width', 'height']);
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$options` | `array` | The HTML options to be modified. |
| `$properties` | `string\|array` | The CSS properties to be removed. You may use a string if you are removing a single property. |

**Returns**

`mixed`

**See also**

- [`addCssStyle()`](/docs/api/yii/helpers/basehtml/index.md#method-addCssStyle)

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

```php
public static function renderSelectOptions(string|array|bool|null $selection, array $items, array &$tagOptions = []): string
```

Renders the option tags that can be used by [`dropDownList()`](/docs/api/yii/helpers/basehtml/index.md#method-dropDownList) and [`listBox()`](/docs/api/yii/helpers/basehtml/index.md#method-listBox).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$selection` | `string\|array\|bool\|null` | The selected value(s). String/boolean for single or array for multiple selection(s). |
| `$items` | `array` | The option data items. The array keys are option values, and the array values are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too). For each sub-array, an option group will be generated whose label is the key associated with the sub-array. If you have a list of data models, you may convert them into the format described above using [`ArrayHelper::map()`](/docs/api/yii/helpers/basearrayhelper/index.md#method-map). Note, the values and labels will be automatically HTML-encoded by this method, and the blank spaces in the labels will also be HTML-encoded. |
| `$tagOptions` | `array` | The $options parameter that is passed to the [`dropDownList()`](/docs/api/yii/helpers/basehtml/index.md#method-dropDownList) or [`listBox()`](/docs/api/yii/helpers/basehtml/index.md#method-listBox) call. This method will take out these elements, if any: "prompt", "options" and "groups". See more details in [`dropDownList()`](/docs/api/yii/helpers/basehtml/index.md#method-dropDownList) for the explanation of these elements. |

**Returns**

`string`: The generated list options

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

```php
public static function renderTagAttributes(array $attributes): string
```

Renders the HTML tag attributes.

Attributes whose values are of boolean type will be treated as
[boolean attributes](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes).

Attributes whose values are null will not be rendered.

The values of attributes will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode).

`aria` and `data` attributes get special handling when they are set to an array value. In these cases,
the array will be "expanded" and a list of ARIA/data attributes will be rendered. For example,
`'aria' => ['role' => 'checkbox', 'value' => 'true']` would be rendered as
`aria-role="checkbox" aria-value="true"`.

If a nested `data` value is set to an array, it will be JSON-encoded. For example,
`'data' => ['params' => ['id' => 1, 'name' => 'yii']]` would be rendered as
`data-params='{"id":1,"name":"yii"}'`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$attributes` | `array` | Attributes to be rendered. The attribute values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). |

**Returns**

`string`: The rendering result. If the attributes are not empty, they will be rendered into a string with a leading white space (so that it can be directly appended to the tag name in a tag). If there is no attribute, an empty string will be returned.

**See also**

- [`addCssClass()`](/docs/api/yii/helpers/basehtml/index.md#method-addCssClass)

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

```php
public static function resetButton(string $content = 'Reset', array $options = []): string
```

Generates a reset button tag.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$content` | `string` | The content enclosed within the button tag. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should consider [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode) it to prevent XSS attacks. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated reset button tag

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

```php
public static function resetInput(string|null $label = 'Reset', array $options = []): string
```

Generates a reset input button.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$label` | `string\|null` | The value attribute. If it is null, the value attribute will not be generated. |
| `$options` | `array` | The attributes of the button tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). Attributes whose value is null will be ignored and not put in the tag returned. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated button tag

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

```php
public static function script(string $content, array $options = []): string
```

Generates a script tag.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$content` | `string` | The script content |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated script tag

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

```php
public static function style(string $content, array $options = []): string
```

Generates a style tag.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$content` | `string` | The style content |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated style tag

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

```php
public static function submitButton(string $content = 'Submit', array $options = []): string
```

Generates a submit button tag.

Be careful when naming form elements such as submit buttons. According to the [jQuery documentation](https://api.jquery.com/submit/) there
are some reserved names that can cause conflicts, e.g. `submit`, `length`, or `method`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$content` | `string` | The content enclosed within the button tag. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should consider [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode) it to prevent XSS attacks. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated submit button tag

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

```php
public static function submitInput(string|null $label = 'Submit', array $options = []): string
```

Generates a submit input button.

Be careful when naming form elements such as submit buttons. According to the [jQuery documentation](https://api.jquery.com/submit/) there
are some reserved names that can cause conflicts, e.g. `submit`, `length`, or `method`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$label` | `string\|null` | The value attribute. If it is null, the value attribute will not be generated. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated button tag

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

```php
public static function tag(string|bool|null $name, string $content = '', array $options = []): string
```

Generates a complete HTML tag.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string\|bool\|null` | The tag name. If $name is `null` or `false`, the corresponding content will be rendered without any tag. |
| `$content` | `string` | The content to be enclosed between the start and end tags. It will not be HTML-encoded. If this is coming from end users, you should consider [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode) it to prevent XSS attacks. |
| `$options` | `array` | The HTML tag attributes (HTML options) in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. For example when using `['class' => 'my-class', 'target' => '_blank', 'value' => null]` it will result in the html attributes rendered like this: `class="my-class" target="_blank"`. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated HTML tag

**See also**

- [`beginTag()`](/docs/api/yii/helpers/basehtml/index.md#method-beginTag)
- [`endTag()`](/docs/api/yii/helpers/basehtml/index.md#method-endTag)

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

```php
public static function textarea(string $name, string $value = '', array $options = []): string
```

Generates a text area input.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The input name |
| `$value` | `string` | The input value. Note that it will be encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. The following special options are recognized: - `doubleEncode`: whether to double encode HTML entities in `$value`. If `false`, HTML entities in `$value` will not be further encoded. This option is available since version 2.0.11. |

**Returns**

`string`: The generated text area tag

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

```php
public static function textInput(string $name, string|null $value = null, array $options = []): string
```

Generates a text input field.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The name attribute. |
| `$value` | `string\|null` | The value attribute. If it is null, the value attribute will not be generated. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated text input tag

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

```php
public static function ul(array|Traversable $items, array $options = []): string
```

Generates an unordered list.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$items` | `array\|`[`Traversable`](https://www.php.net/manual/en/class.traversable.php) | The items for generating the list. Each item generates a single list item. Note that items will be automatically HTML encoded if `$options['encode']` is not set or true. |
| `$options` | `array` | Options (name => config) for the radio button list. The following options are supported: - encode: boolean, whether to HTML-encode the items. Defaults to true. This option is ignored if the `item` option is specified. - separator: string, the HTML code that separates items. Defaults to a simple newline (`"\n"`). This option is available since version 2.0.7. - itemOptions: array, the HTML attributes for the `li` tags. This option is ignored if the `item` option is specified. - item: callable, a callback that is used to generate each individual list item. The signature of this callback must be: function ($item, $index) where $index is the array key corresponding to `$item` in `$items`. The callback should return the whole list item tag. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated unordered list. An empty list tag will be returned if `$items` is empty.

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

```php
protected static function activeBooleanInput(string $type, yii\base\Model $model, string $attribute, array $options = []): string
```

Generates a boolean input
This method is mainly called by [`activeCheckbox()`](/docs/api/yii/helpers/basehtml/index.md#method-activeCheckbox) and [`activeRadio()`](/docs/api/yii/helpers/basehtml/index.md#method-activeRadio).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$type` | `string` | The input type. This can be either `radio` or `checkbox`. |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression. See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$options` | `array` | The tag options in terms of name-value pairs. See [`booleanInput()`](/docs/api/yii/helpers/basehtml/index.md#method-booleanInput) for details about accepted attributes. |

**Returns**

`string`: The generated input element

**Since**

2.0.9

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

```php
protected static function activeListInput(string $type, yii\base\Model $model, string $attribute, array $items, array $options = []): string
```

Generates a list of input fields.

This method is mainly called by [`activeListBox()`](/docs/api/yii/helpers/basehtml/index.md#method-activeListBox), [`activeRadioList()`](/docs/api/yii/helpers/basehtml/index.md#method-activeRadioList) and [`activeCheckboxList()`](/docs/api/yii/helpers/basehtml/index.md#method-activeCheckboxList).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$type` | `string` | The input type. This can be 'listBox', 'radioList', or 'checkBoxList'. |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression. See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$items` | `array` | The data item used to generate the input fields. The array keys are the input values, and the array values are the corresponding labels. |
| `$options` | `array` | Options (name => config) for the input list. The supported special options depend on the input type specified by `$type`. |

**Returns**

`string`: The generated input list

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

```php
protected static function booleanInput(string $type, string $name, bool $checked = false, array $options = []): string
```

Generates a boolean input.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$type` | `string` | The input type. This can be either `radio` or `checkbox`. |
| `$name` | `string` | The name attribute. |
| `$checked` | `bool` | Whether the checkbox should be checked. |
| `$options` | `array` | The tag options in terms of name-value pairs. The following options are specially handled: - uncheck: string, the value associated with the uncheck state of the checkbox. When this attribute is present, a hidden input will be generated so that if the checkbox is not checked and is submitted, the value of this attribute will still be submitted to the server via the hidden input. - label: string, a label displayed next to the checkbox.  It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode) it to prevent XSS attacks. When this option is specified, the checkbox will be enclosed by a label tag. - labelOptions: array, the HTML attributes for the label tag. Do not set this option unless you set the "label" option. The rest of the options will be rendered as the attributes of the resulting checkbox tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is null, the corresponding attribute will not be rendered. See [`renderTagAttributes()`](/docs/api/yii/helpers/basehtml/index.md#method-renderTagAttributes) for details on how attributes are being rendered. |

**Returns**

`string`: The generated checkbox tag

**Since**

2.0.9

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

```php
protected static function setActivePlaceholder(yii\base\Model $model, string $attribute, array &$options = []): mixed
```

Generate placeholder from model attribute label.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model object |
| `$attribute` | `string` | The attribute name or expression. See [`getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$options` | `array` | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [`encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). |

**Returns**

`mixed`

**Since**

2.0.14