0 follower

Final Class Yiisoft\Html\Html

InheritanceYiisoft\Html\Html

Html provides a set of static methods for generating commonly used HTML tags.

Nearly all the methods in this class allow setting additional HTML attributes for the HTML tags they generate. You can specify, for example, class, style or id for an HTML element using the $options parameter. See the documentation of the tag() method for more details.

Public Methods

Hide inherited methods

Method Description Defined By
a() Generates a hyperlink tag. Yiisoft\Html\Html
addCssClass() Adds a CSS class (or several classes) to the specified options. Yiisoft\Html\Html
addCssStyle() Adds the specified CSS styles to the HTML options. Yiisoft\Html\Html
address() Generates a Yiisoft\Html\Tag\Address tag. Yiisoft\Html\Html
article() Generates a Yiisoft\Html\Tag\Article tag. Yiisoft\Html\Html
aside() Generates a Yiisoft\Html\Tag\Aside tag. Yiisoft\Html\Html
audio() Generates a Yiisoft\Html\Tag\Audio tag. Yiisoft\Html\Html
b() Generates a Yiisoft\Html\Tag\B tag. Yiisoft\Html\Html
body() Generates a Yiisoft\Html\Tag\Body tag. Yiisoft\Html\Html
br() Generates a Yiisoft\Html\Tag\Br tag. Yiisoft\Html\Html
button() Generates a button tag. Yiisoft\Html\Html
buttonInput() Generates an Yiisoft\Html\Tag\Input button. Yiisoft\Html\Html
caption() Generates a Yiisoft\Html\Tag\Caption tag. Yiisoft\Html\Html
checkbox() Generates a checkbox Yiisoft\Html\Tag\Input. Yiisoft\Html\Html
checkboxList() Generates a list of checkboxes. Yiisoft\Html\Html
closeTag() Generates an end tag. Yiisoft\Html\Html
code() Generates a Yiisoft\Html\Tag\Code tag. Yiisoft\Html\Html
col() Generates a Yiisoft\Html\Tag\Col tag. Yiisoft\Html\Html
colgroup() Generates a Yiisoft\Html\Tag\Colgroup tag. Yiisoft\Html\Html
color() Generates a color Yiisoft\Html\Tag\Input field. Yiisoft\Html\Html
cssFile() Generates a Yiisoft\Html\Tag\Link tag that refers to an CSS file. Yiisoft\Html\Html
cssStyleFromArray() Converts a CSS style array into a string representation. Yiisoft\Html\Html
cssStyleToArray() Converts a CSS style string into an array representation. Yiisoft\Html\Html
datalist() Generates a Yiisoft\Html\Tag\Datalist tag. Yiisoft\Html\Html
div() Generates a Yiisoft\Html\Tag\Div tag. Yiisoft\Html\Html
em() Generates a Yiisoft\Html\Tag\Em tag. Yiisoft\Html\Html
encode() Encodes special characters into HTML entities for use as a tag content i.e. <div>tag content</div>. Yiisoft\Html\Html
encodeAttribute() Encodes special characters into HTML entities for use as HTML tag quoted attribute value i.e. <input value="my-value">. Yiisoft\Html\Html
encodeUnquotedAttribute() Encodes special characters into HTML entities for use as HTML tag unquoted attribute value i.e. <input value=my-value>. Yiisoft\Html\Html
escapeJavaScriptStringValue() Escape special characters for use as JavaScript string value in a <script> tag: Yiisoft\Html\Html
fieldset() Generates a Yiisoft\Html\Tag\Fieldset tag. Yiisoft\Html\Html
file() Generates a file input field. Yiisoft\Html\Html
footer() Generates a Yiisoft\Html\Tag\Footer tag. Yiisoft\Html\Html
form() Generates a Yiisoft\Html\Tag\Form tag. Yiisoft\Html\Html
generateId() Returns an autogenerated sequential ID. Yiisoft\Html\Html
getArrayableName() Yiisoft\Html\Html
getNonArrayableName() Yiisoft\Html\Html
h1() Generates a Yiisoft\Html\Tag\H1 tag. Yiisoft\Html\Html
h2() Generates a Yiisoft\Html\Tag\H2 tag. Yiisoft\Html\Html
h3() Generates a Yiisoft\Html\Tag\H3 tag. Yiisoft\Html\Html
h4() Generates a Yiisoft\Html\Tag\H4 tag. Yiisoft\Html\Html
h5() Generates a Yiisoft\Html\Tag\H5 tag. Yiisoft\Html\Html
h6() Generates a Yiisoft\Html\Tag\H6 tag. Yiisoft\Html\Html
header() Generates a Yiisoft\Html\Tag\Header tag. Yiisoft\Html\Html
hgroup() Generates a Yiisoft\Html\Tag\Hgroup tag. Yiisoft\Html\Html
hiddenInput() Generates a hidden input field. Yiisoft\Html\Html
hr() Generates a Yiisoft\Html\Tag\Hr tag. Yiisoft\Html\Html
html() Generates a Yiisoft\Html\Html tag. Yiisoft\Html\Html
i() Generates a Yiisoft\Html\Tag\I tag. Yiisoft\Html\Html
img() Generates an Yiisoft\Html\Tag\Img tag. Yiisoft\Html\Html
input() Generates an Yiisoft\Html\Tag\Input type of the given type. Yiisoft\Html\Html
javaScriptFile() Generates a Yiisoft\Html\Tag\Script tag that refers to a JavaScript file. Yiisoft\Html\Html
label() Generates a Yiisoft\Html\Tag\Label tag. Yiisoft\Html\Html
legend() Generates a Yiisoft\Html\Tag\Legend tag. Yiisoft\Html\Html
li() Generates a Yiisoft\Html\Tag\Li tag. Yiisoft\Html\Html
link() Generates a Yiisoft\Html\Tag\Link tag. Yiisoft\Html\Html
mailto() Generates a mailto hyperlink tag. Yiisoft\Html\Html
meta() Generates a Yiisoft\Html\Tag\Meta tag. Yiisoft\Html\Html
normalTag() Generates a normal HTML tag. Yiisoft\Html\Html
normalizeRegexpPattern() Normalize PCRE regular expression to use in the "pattern" HTML attribute: - convert \x{FFFF} to \uFFFF; - remove flags and delimiters. Yiisoft\Html\Html
noscript() Generates a Yiisoft\Html\Tag\Noscript tag. Yiisoft\Html\Html
ol() Generates a Yiisoft\Html\Tag\Ol tag. Yiisoft\Html\Html
openTag() Generates a start tag. Yiisoft\Html\Html
optgroup() Generates a Yiisoft\Html\Tag\Optgroup tag. Yiisoft\Html\Html
option() Generates a Yiisoft\Html\Tag\Option tag. Yiisoft\Html\Html
p() Generates a Yiisoft\Html\Tag\P tag. Yiisoft\Html\Html
passwordInput() Generates a password input field. Yiisoft\Html\Html
picture() Generates a Yiisoft\Html\Tag\Picture tag. Yiisoft\Html\Html
pre() Generates a Yiisoft\Html\Tag\Pre tag. Yiisoft\Html\Html
radio() Generates a radio button Yiisoft\Html\Tag\Input. Yiisoft\Html\Html
radioList() Generates a list of radio buttons. Yiisoft\Html\Html
range() Generates a range Yiisoft\Html\Tag\Input\Range. Yiisoft\Html\Html
removeCssClass() Removes a CSS class from the specified options. Yiisoft\Html\Html
removeCssStyle() Removes the specified CSS styles from the HTML options. Yiisoft\Html\Html
renderTagAttributes() Renders the HTML tag attributes. Yiisoft\Html\Html
resetButton() Generates a reset button tag. Yiisoft\Html\Html
resetInput() Generates a reset Yiisoft\Html\Tag\Input button. Yiisoft\Html\Html
script() Generates a Yiisoft\Html\Tag\Script tag. Yiisoft\Html\Html
section() Generates a Yiisoft\Html\Tag\Section tag. Yiisoft\Html\Html
select() Generates a Yiisoft\Html\Tag\Select tag. Yiisoft\Html\Html
small() Generates a Yiisoft\Html\Tag\Small tag. Yiisoft\Html\Html
source() Generates a Yiisoft\Html\Tag\Source tag. Yiisoft\Html\Html
span() Generates a Yiisoft\Html\Tag\Span tag. Yiisoft\Html\Html
strong() Generates a Yiisoft\Html\Tag\Strong tag. Yiisoft\Html\Html
style() Generates a Yiisoft\Html\Tag\Style tag. Yiisoft\Html\Html
submitButton() Generates a submit button tag. Yiisoft\Html\Html
submitInput() Generates submit Yiisoft\Html\Tag\Input button. Yiisoft\Html\Html
table() Generates a Yiisoft\Html\Tag\Table tag. Yiisoft\Html\Html
tag() Generates a complete HTML tag. Yiisoft\Html\Html
tbody() Generates a Yiisoft\Html\Tag\Tbody tag. Yiisoft\Html\Html
td() Generates a Yiisoft\Html\Tag\Td tag. Yiisoft\Html\Html
textInput() Generates a text Yiisoft\Html\Tag\Input field. Yiisoft\Html\Html
textarea() Generates a Yiisoft\Html\Tag\Textarea input. Yiisoft\Html\Html
tfoot() Generates a Yiisoft\Html\Tag\Tfoot tag. Yiisoft\Html\Html
th() Generates a Yiisoft\Html\Tag\Th tag. Yiisoft\Html\Html
thead() Generates a Yiisoft\Html\Tag\Thead tag. Yiisoft\Html\Html
title() Generates a Yiisoft\Html\Tag\Title tag. Yiisoft\Html\Html
tr() Generates a Yiisoft\Html\Tag\Tr tag. Yiisoft\Html\Html
track() Generates a Yiisoft\Html\Tag\Track tag. Yiisoft\Html\Html
ul() Generates a Yiisoft\Html\Tag\Ul tag. Yiisoft\Html\Html
video() Generates a Yiisoft\Html\Tag\Video tag. Yiisoft\Html\Html
voidTag() Generates a void HTML tag. Yiisoft\Html\Html

Constants

Hide inherited constants

Constant Value Description Defined By
ATTRIBUTES_WITH_CONCATENATED_VALUES [ 'class', 'aria-describedby', ] List of tag attributes which values should be concatenated with space. In particular, if the value of the attribute with the name attribute is ['value1', 'value2'], the result will be attribute="value1 value2". Yiisoft\Html\Html
ATTRIBUTE_ORDER [ 'type', 'id', 'class', 'name', 'value', 'href', 'loading', 'src', 'srcset', 'form', 'action', 'method', 'selected', 'checked', 'readonly', 'disabled', 'multiple', 'size', 'maxlength', 'minlength', '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(). Yiisoft\Html\Html
DATA_ATTRIBUTES [ 'data', 'data-ng', 'ng', 'aria', ] 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". Yiisoft\Html\Html

Method Details

Hide inherited methods

a() public static method

Generates a hyperlink tag.

See also Yiisoft\Html\Tag\A.

public static a( string|\Stringable $content '', string|null $url null, array $attributes = [] ): Yiisoft\Html\Tag\A
$content string|\Stringable

The tag content.

$url string|null
$attributes array

The tag attributes in terms of name-value pairs.

                public static function a(string|Stringable $content = '', ?string $url = null, array $attributes = []): A
{
    $tag = A::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    if ($content !== '') {
        $tag = $tag->content($content);
    }
    if ($url !== null) {
        $tag = $tag->url($url);
    }
    return $tag;
}

            
addCssClass() public static method

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']];

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

See also removeCssClass().

public static addCssClass( array &$options, \BackedEnum|\BackedEnum[]|null[]|string|string[]|null $class ): void
$options array

The options to be modified. All string values in the array must be valid UTF-8 strings.

$class \BackedEnum|\BackedEnum[]|null[]|string|string[]|null

The CSS class(es) to be added. Null values will be ignored.

                public static function addCssClass(array &$options, BackedEnum|array|string|null $class): void
{
    if ($class === null) {
        return;
    }
    if ($class instanceof BackedEnum) {
        if (is_int($class->value)) {
            return;
        }
        $class = $class->value;
    }
    if (is_array($class)) {
        $filteredClass = [];
        foreach ($class as $key => $value) {
            if ($value instanceof BackedEnum) {
                $value = is_string($value->value) ? $value->value : null;
            }
            if ($value !== null) {
                $filteredClass[$key] = $value;
            }
        }
        if (empty($filteredClass)) {
            return;
        }
        $class = $filteredClass;
    }
    if (isset($options['class'])) {
        if (is_array($options['class'])) {
            /** @psalm-var string[] $options['class'] */
            $options['class'] = self::mergeCssClasses($options['class'], (array) $class);
        } else {
            /**
             * @psalm-var string $options['class']
             * @var string[] $classes We assume that `$options['class']` is valid UTF-8 string, so `preg_split()`
             * never returns `false`.
             */
            $classes = preg_split('/\s+/', $options['class'], -1, PREG_SPLIT_NO_EMPTY);
            $classes = self::mergeCssClasses($classes, (array) $class);
            $options['class'] = is_array($class) ? $classes : implode(' ', $classes);
        }
    } else {
        $options['class'] = $class;
    }
}

            
addCssStyle() public static method

Adds the specified CSS styles 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');

See also removeCssStyle().

public static addCssStyle( array &$options, string|string[] $style, boolean $overwrite true ): void
$options array

The HTML options to be modified.

$style string|string[]

The new style string (e.g. 'width: 100px; height: 200px') or array (e.g. ['width' => '100px', 'height' => '200px']).

$overwrite boolean

Whether to overwrite existing CSS properties if the new style contain them too.

                public static function addCssStyle(array &$options, array|string $style, bool $overwrite = true): void
{
    if (!empty($options['style'])) {
        /** @psalm-var array<string,string>|string $options['style'] */
        $oldStyle = is_array($options['style']) ? $options['style'] : self::cssStyleToArray($options['style']);
        $newStyle = is_array($style) ? $style : self::cssStyleToArray($style);
        if (!$overwrite) {
            foreach ($newStyle as $property => $_value) {
                if (isset($oldStyle[$property])) {
                    unset($newStyle[$property]);
                }
            }
        }
        $style = array_merge($oldStyle, $newStyle);
    }
    $options['style'] = is_array($style) ? self::cssStyleFromArray($style) : $style;
}

            
address() public static method

Generates a Yiisoft\Html\Tag\Address tag.

public static address( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Address
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function address(string|Stringable $content = '', array $attributes = []): Address
{
    $tag = Address::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
article() public static method

Generates a Yiisoft\Html\Tag\Article tag.

public static article( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Article
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function article(string|Stringable $content = '', array $attributes = []): Article
{
    $tag = Article::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
aside() public static method

Generates a Yiisoft\Html\Tag\Aside tag.

public static aside( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Aside
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function aside(string|Stringable $content = '', array $attributes = []): Aside
{
    $tag = Aside::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
audio() public static method

Generates a Yiisoft\Html\Tag\Audio tag.

public static audio( ): Yiisoft\Html\Tag\Audio

                public static function audio(): Audio
{
    return Audio::tag();
}

            
b() public static method

Generates a Yiisoft\Html\Tag\B tag.

public static b( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\B
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function b(string|Stringable $content = '', array $attributes = []): B
{
    $tag = B::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
body() public static method

Generates a Yiisoft\Html\Tag\Body tag.

public static body( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Body
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function body(string|Stringable $content = '', array $attributes = []): Body
{
    $tag = Body::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
br() public static method

Generates a Yiisoft\Html\Tag\Br tag.

public static br( ): Yiisoft\Html\Tag\Br

                public static function br(): Br
{
    return Br::tag();
}

            
button() public static method

Generates a button tag.

See also Yiisoft\Html\Tag\Button::button().

public static button( string $content 'Button', array $attributes = [] ): Yiisoft\Html\Tag\Button
$content string

The content enclosed within the button tag.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function button(string $content = 'Button', array $attributes = []): Button
{
    $tag = Button::button($content);
    if (!empty($attributes)) {
        $tag = $tag->addAttributes($attributes);
    }
    return $tag;
}

            
buttonInput() public static method
public static buttonInput( string|null $label 'Button', array $attributes = [] ): Yiisoft\Html\Tag\Input
$label string|null

The value attribute.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function buttonInput(?string $label = 'Button', array $attributes = []): Input
{
    $tag = Input::button($label);
    if (!empty($attributes)) {
        $tag = $tag->addAttributes($attributes);
    }
    return $tag;
}

            
caption() public static method

Generates a Yiisoft\Html\Tag\Caption tag.

public static caption( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Caption
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function caption(string|Stringable $content = '', array $attributes = []): Caption
{
    $tag = Caption::tag();
    if ($content !== '') {
        $tag = $tag->content($content);
    }
    if ($attributes !== []) {
        $tag = $tag->attributes($attributes);
    }
    return $tag;
}

            
checkbox() public static method
public static checkbox( string|null $name null, boolean|float|integer|string|\Stringable|null $value null, array $attributes = [] ): Yiisoft\Html\Tag\Input\Checkbox
$name string|null

The name attribute.

$value boolean|float|integer|string|\Stringable|null

The value attribute.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function checkbox(
    ?string $name = null,
    bool|float|int|string|Stringable|null $value = null,
    array $attributes = [],
): Checkbox {
    $tag = Input::checkbox($name, $value);
    return $attributes === [] ? $tag : $tag->addAttributes($attributes);
}

            
checkboxList() public static method

Generates a list of checkboxes.

See also Yiisoft\Html\Widget\CheckboxList\CheckboxList.

public static checkboxList( string $name ): Yiisoft\Html\Widget\CheckboxList\CheckboxList
$name string

                public static function checkboxList(string $name): CheckboxList
{
    return CheckboxList::create($name);
}

            
closeTag() public static method

Generates an end tag.

See also \Yiisoft\Html\self::openTag().

public static closeTag( string $name ): string
$name string

The tag name.

                public static function closeTag(string $name): string
{
    return "</$name>";
}

            
code() public static method

Generates a Yiisoft\Html\Tag\Code tag.

public static code( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Code
$content string|\Stringable

Tag content. If content includes HTML tags or special characters like <, >, or &, and you want them to be displayed as plain text, you need to enable encoding by calling ->encode(true). This ensures they are not interpreted as actual HTML.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function code(string|Stringable $content = '', array $attributes = []): Code
{
    $tag = Code::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
col() public static method

Generates a Yiisoft\Html\Tag\Col tag.

public static col( array $attributes = [] ): Yiisoft\Html\Tag\Col
$attributes array

The tag attributes in terms of name-value pairs.

                public static function col(array $attributes = []): Col
{
    $tag = Col::tag();
    return $attributes === [] ? $tag : $tag->attributes($attributes);
}

            
colgroup() public static method

Generates a Yiisoft\Html\Tag\Colgroup tag.

public static colgroup( array $attributes = [] ): Yiisoft\Html\Tag\Colgroup
$attributes array

The tag attributes in terms of name-value pairs.

                public static function colgroup(array $attributes = []): Colgroup
{
    $tag = Colgroup::tag();
    return $attributes === [] ? $tag : $tag->attributes($attributes);
}

            
color() public static method

Generates a color Yiisoft\Html\Tag\Input field.

See also Yiisoft\Html\Tag\Input::color().

public static color( string|null $name null, string|\Stringable|null $value null, array $attributes = [] ): Yiisoft\Html\Tag\Input\Color
$name string|null

The name attribute.

$value string|\Stringable|null

The value attribute.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function color(
    ?string $name = null,
    string|Stringable|null $value = null,
    array $attributes = [],
): Color {
    $tag = Input::color($name, $value);
    return $attributes === [] ? $tag : $tag->addAttributes($attributes);
}

            
cssFile() public static method

Generates a Yiisoft\Html\Tag\Link tag that refers to an CSS file.

public static cssFile( string $url, array $attributes = [] ): Yiisoft\Html\Tag\Link
$url string

The URL of the CSS file.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function cssFile(string $url, array $attributes = []): Link
{
    $tag = Link::toCssFile($url);
    if (!empty($attributes)) {
        $tag = $tag->addAttributes($attributes);
    }
    return $tag;
}

            
cssStyleFromArray() public static method

Converts a CSS style array into a string representation.

For example,

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

See also cssStyleToArray().

public static cssStyleFromArray( array<string, string> $style ): string|null
$style array<string, string>

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

return string|null

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

                public static function cssStyleFromArray(array $style): ?string
{
    $result = '';
    foreach ($style as $name => $value) {
        $result .= "$name: $value; ";
    }
    // Return null if empty to avoid rendering the "style" attribute.
    return $result === '' ? null : rtrim($result);
}

            
cssStyleToArray() public static method

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,

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

See also cssStyleFromArray().

public static cssStyleToArray( string|\Stringable $style ): array
$style string|\Stringable

The CSS style string.

return array

The array representation of the CSS style.

                public static function cssStyleToArray(string|Stringable $style): array
{
    $result = [];
    foreach (explode(';', (string) $style) as $property) {
        $property = explode(':', $property);
        if (count($property) > 1) {
            $result[trim($property[0])] = trim($property[1]);
        }
    }
    return $result;
}

            
datalist() public static method

Generates a Yiisoft\Html\Tag\Datalist tag.

public static datalist( array $attributes = [] ): Yiisoft\Html\Tag\Datalist
$attributes array

The tag attributes in terms of name-value pairs.

                public static function datalist(array $attributes = []): Datalist
{
    $tag = Datalist::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $tag;
}

            
div() public static method

Generates a Yiisoft\Html\Tag\Div tag.

public static div( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Div
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function div(string|Stringable $content = '', array $attributes = []): Div
{
    $tag = Div::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
em() public static method

Generates a Yiisoft\Html\Tag\Em tag.

public static em( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Em
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function em(string|Stringable $content = '', array $attributes = []): Em
{
    $tag = Em::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
encode() public static method

Encodes special characters into HTML entities for use as a tag content i.e. <div>tag content</div>.

Characters encoded are: &, <, >.

public static encode( mixed $content, boolean $doubleEncode true, string $encoding 'UTF-8' ): string
$content mixed

The content to be encoded.

$doubleEncode boolean

If already encoded entities should be encoded.

$encoding string

The encoding to use, defaults to "UTF-8".

return string

Encoded content.

                public static function encode(mixed $content, bool $doubleEncode = true, string $encoding = 'UTF-8'): string
{
    return htmlspecialchars(
        (string) $content,
        ENT_NOQUOTES | ENT_SUBSTITUTE | ENT_HTML5,
        $encoding,
        $doubleEncode,
    );
}

            
encodeAttribute() public static method

Encodes special characters into HTML entities for use as HTML tag quoted attribute value i.e. <input value="my-value">.

Characters encoded are: &, <, >, ", ', U+0000 (null).

public static encodeAttribute( mixed $value, boolean $doubleEncode true, string $encoding 'UTF-8' ): string
$value mixed

The attribute value to be encoded.

$doubleEncode boolean

If already encoded entities should be encoded.

$encoding string

The encoding to use, defaults to "UTF-8".

return string

Encoded attribute value.

                public static function encodeAttribute(mixed $value, bool $doubleEncode = true, string $encoding = 'UTF-8'): string
{
    $value = htmlspecialchars(
        (string) $value,
        ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5,
        $encoding,
        $doubleEncode,
    );
    return strtr($value, [
        "\u{0000}" => '&#0;', // U+0000 NULL
    ]);
}

            
encodeUnquotedAttribute() public static method

Encodes special characters into HTML entities for use as HTML tag unquoted attribute value i.e. <input value=my-value>.

Characters encoded are: &, <, >, ", ', `, =, tab, space, U+000A (form feed), U+0000 (null).

public static encodeUnquotedAttribute( mixed $value, boolean $doubleEncode true, string $encoding 'UTF-8' ): string
$value mixed

The attribute value to be encoded.

$doubleEncode boolean

If already encoded entities should be encoded.

$encoding string

The encoding to use, defaults to "UTF-8".

return string

Encoded attribute value.

                public static function encodeUnquotedAttribute(
    mixed $value,
    bool $doubleEncode = true,
    string $encoding = 'UTF-8',
): string {
    $value = htmlspecialchars(
        (string) $value,
        ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5,
        $encoding,
        $doubleEncode,
    );
    return strtr($value, [
        "\t" => '&Tab;', // U+0009 CHARACTER TABULATION (tab)
        "\n" => '&NewLine;', // U+000A LINE FEED (LF)
        "\u{000c}" => '&#12;', // U+000C FORM FEED (FF)
        "\u{0000}" => '&#0;', // U+0000 NULL
        ' ' => '&#32;', // U+0020 SPACE
        '=' => '&equals;', // U+003D EQUALS SIGN (=)
        '`' => '&grave;', // U+0060 GRAVE ACCENT (`)
    ]);
}

            
escapeJavaScriptStringValue() public static method

Escape special characters for use as JavaScript string value in a <script> tag:

<script>
    window.myVar = "<?= Html::escapeJavaScriptStringValue($myVar) ?>";
</script>
public static escapeJavaScriptStringValue( mixed $value ): string
$value mixed

JavaScript string.

return string

Escaped JavaScript string.

                public static function escapeJavaScriptStringValue(mixed $value): string
{
    return strtr((string) $value, [
        '/' => '\/',
        '"' => '\"',
        "'" => "\'",
        '\\' => '\\\\',
    ]);
}

            
fieldset() public static method

Generates a Yiisoft\Html\Tag\Fieldset tag.

public static fieldset( array $attributes = [] ): Yiisoft\Html\Tag\Fieldset
$attributes array

The tag attributes in terms of name-value pairs.

                public static function fieldset(array $attributes = []): Fieldset
{
    $tag = Fieldset::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $tag;
}

            
file() public static method

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).

See also Yiisoft\Html\Tag\Input::file().

public static file( string|null $name null, boolean|float|integer|string|\Stringable|null $value null, array $attributes = [] ): Yiisoft\Html\Tag\Input\File
$name string|null

The name attribute.

$value boolean|float|integer|string|\Stringable|null

The value attribute.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function file(
    ?string $name = null,
    bool|float|int|string|Stringable|null $value = null,
    array $attributes = [],
): File {
    $tag = Input::file($name, $value);
    return $attributes === [] ? $tag : $tag->addAttributes($attributes);
}

            
footer() public static method

Generates a Yiisoft\Html\Tag\Footer tag.

public static footer( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Footer
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function footer(string|Stringable $content = '', array $attributes = []): Footer
{
    $tag = Footer::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
form() public static method

Generates a Yiisoft\Html\Tag\Form tag.

public static form( string|null $action null, string|null $method null, array $attributes = [] ): Yiisoft\Html\Tag\Form
$action string|null

The URL to use for form submission.

$method string|null

The method attribute value.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function form(?string $action = null, ?string $method = null, array $attributes = []): Form
{
    $tag = Form::tag();
    if ($action !== null) {
        $attributes['action'] = $action;
    }
    if ($method !== null) {
        $attributes['method'] = $method;
    }
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $tag;
}

            
generateId() public static method

Returns an autogenerated sequential ID.

public static generateId( string $prefix 'i' ): string
$prefix string
return string

Autogenerated ID.

                public static function generateId(string $prefix = 'i'): string
{
    $prefix .= hrtime(true);
    if (isset(self::$generateIdCounter[$prefix])) {
        $counter = ++self::$generateIdCounter[$prefix];
    } else {
        $counter = 1;
        self::$generateIdCounter = [$prefix => $counter];
    }
    return $prefix . $counter;
}

            
getArrayableName() public static method

public static getArrayableName( string $name ): string
$name string

                public static function getArrayableName(string $name): string
{
    return !str_ends_with($name, '[]') ? $name . '[]' : $name;
}

            
getNonArrayableName() public static method

public static getNonArrayableName( string $name ): string
$name string

                public static function getNonArrayableName(string $name): string
{
    return str_ends_with($name, '[]') ? substr($name, 0, -2) : $name;
}

            
h1() public static method

Generates a Yiisoft\Html\Tag\H1 tag.

public static h1( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\H1
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function h1(string|Stringable $content = '', array $attributes = []): H1
{
    $tag = H1::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
h2() public static method

Generates a Yiisoft\Html\Tag\H2 tag.

public static h2( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\H2
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function h2(string|Stringable $content = '', array $attributes = []): H2
{
    $tag = H2::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
h3() public static method

Generates a Yiisoft\Html\Tag\H3 tag.

public static h3( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\H3
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function h3(string|Stringable $content = '', array $attributes = []): H3
{
    $tag = H3::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
h4() public static method

Generates a Yiisoft\Html\Tag\H4 tag.

public static h4( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\H4
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function h4(string|Stringable $content = '', array $attributes = []): H4
{
    $tag = H4::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
h5() public static method

Generates a Yiisoft\Html\Tag\H5 tag.

public static h5( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\H5
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function h5(string|Stringable $content = '', array $attributes = []): H5
{
    $tag = H5::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
h6() public static method

Generates a Yiisoft\Html\Tag\H6 tag.

public static h6( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\H6
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function h6(string|Stringable $content = '', array $attributes = []): H6
{
    $tag = H6::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
header() public static method

Generates a Yiisoft\Html\Tag\Header tag.

public static header( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Header
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function header(string|Stringable $content = '', array $attributes = []): Header
{
    $tag = Header::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
hgroup() public static method

Generates a Yiisoft\Html\Tag\Hgroup tag.

public static hgroup( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Hgroup
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function hgroup(string|Stringable $content = '', array $attributes = []): Hgroup
{
    $tag = Hgroup::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
hiddenInput() public static method

Generates a hidden input field.

See also Yiisoft\Html\Tag\Input::hidden().

public static hiddenInput( string|null $name null, boolean|float|integer|string|\Stringable|null $value null, array $attributes = [] ): Yiisoft\Html\Tag\Input
$name string|null

The name attribute.

$value boolean|float|integer|string|\Stringable|null

The value attribute.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function hiddenInput(
    ?string $name = null,
    bool|float|int|string|Stringable|null $value = null,
    array $attributes = [],
): Input {
    $tag = Input::hidden($name, $value);
    return $attributes === [] ? $tag : $tag->addAttributes($attributes);
}

            
hr() public static method

Generates a Yiisoft\Html\Tag\Hr tag.

public static hr( array $attributes = [] ): Yiisoft\Html\Tag\Hr
$attributes array

                public static function hr(array $attributes = []): Hr
{
    $tag = Hr::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $tag;
}

            
html() public static method

Generates a Yiisoft\Html\Html tag.

public static html( string|\Stringable $content '', string|null $lang null, array $attributes = [] ): Yiisoft\Html\Tag\Html
$content string|\Stringable

Tag content.

$lang string|null

The document language.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function html(string|Stringable $content = '', ?string $lang = null, array $attributes = []): Tag\Html
{
    $tag = Tag\Html::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    if ($content !== '') {
        $tag = $tag->content($content);
    }
    if ($lang !== null) {
        $tag = $tag->lang($lang);
    }
    return $tag;
}

            
i() public static method

Generates a Yiisoft\Html\Tag\I tag.

public static i( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\I
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function i(string|Stringable $content = '', array $attributes = []): I
{
    $tag = I::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
img() public static method

Generates an Yiisoft\Html\Tag\Img tag.

public static img( string|null $url null, string|null $alt '', array $attributes = [] ): Yiisoft\Html\Tag\Img
$url string|null

The image URL.

$alt string|null

Alt text.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function img(?string $url = null, ?string $alt = '', array $attributes = []): Img
{
    $tag = Img::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    if ($url !== null) {
        $tag = $tag->src($url);
    }
    if ($alt !== null) {
        $tag = $tag->alt($alt);
    }
    return $tag;
}

            
input() public static method

Generates an Yiisoft\Html\Tag\Input type of the given type.

public static input( string $type, string|null $name null, boolean|float|integer|string|\Stringable|null $value null, array $attributes = [] ): Yiisoft\Html\Tag\Input
$type string

The type attribute.

$name string|null

The name attribute. If it is null, the name attribute will not be generated.

$value boolean|float|integer|string|\Stringable|null

The value attribute. If it is null, the value attribute will not be generated.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function input(
    string $type,
    ?string $name = null,
    bool|float|int|string|Stringable|null $value = null,
    array $attributes = [],
): Input {
    $tag = Input::tag()->type($type);
    if ($name !== null) {
        $tag = $tag->name($name);
    }
    if ($value !== null) {
        $tag = $tag->value($value);
    }
    if (!empty($attributes)) {
        $tag = $tag->addAttributes($attributes);
    }
    return $tag;
}

            
javaScriptFile() public static method

Generates a Yiisoft\Html\Tag\Script tag that refers to a JavaScript file.

public static javaScriptFile( string $url, array $attributes = [] ): Yiisoft\Html\Tag\Script
$url string

The URL of the JavaScript file.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function javaScriptFile(string $url, array $attributes = []): Script
{
    $tag = Script::tag()->url($url);
    if (!empty($attributes)) {
        $tag = $tag->addAttributes($attributes);
    }
    return $tag;
}

            
label() public static method

Generates a Yiisoft\Html\Tag\Label tag.

public static label( string|\Stringable $content '', string|null $for null ): Yiisoft\Html\Tag\Label
$content string|\Stringable

Label text.

$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.

                public static function label(string|Stringable $content = '', ?string $for = null): Label
{
    $tag = Label::tag();
    if ($for !== null) {
        $tag = $tag->forId($for);
    }
    if ($content !== '') {
        $tag = $tag->content($content);
    }
    return $tag;
}

            
legend() public static method

Generates a Yiisoft\Html\Tag\Legend tag.

public static legend( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Legend
$content string|\Stringable

The tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function legend(string|Stringable $content = '', array $attributes = []): Legend
{
    $tag = Legend::tag();
    if ($content !== '') {
        $tag = $tag->content($content);
    }
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $tag;
}

            
li() public static method

Generates a Yiisoft\Html\Tag\Li tag.

public static li( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Li
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function li(string|Stringable $content = '', array $attributes = []): Li
{
    $tag = Li::tag();
    if ($attributes !== []) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
link() public static method

Generates a Yiisoft\Html\Tag\Link tag.

public static link( string|null $url null, array $attributes = [] ): Yiisoft\Html\Tag\Link
$url string|null

The destination of the link.

$attributes array

The tag attributes in terms of name-value pairs.

mailto() public static method

Generates a mailto hyperlink tag.

See also Yiisoft\Html\Tag\A.

public static mailto( string $content, string|null $mail null, array $attributes = [] ): Yiisoft\Html\Tag\A
$content string
$mail string|null
$attributes array

The tag attributes in terms of name-value pairs.

                public static function mailto(string $content, ?string $mail = null, array $attributes = []): A
{
    $tag = A::tag()
        ->content($content)
        ->mailto($mail ?? $content);
    if (!empty($attributes)) {
        $tag = $tag->addAttributes($attributes);
    }
    return $tag;
}

            
meta() public static method

Generates a Yiisoft\Html\Tag\Meta tag.

public static meta( array $attributes = [] ): Yiisoft\Html\Tag\Meta
$attributes array

The tag attributes in terms of name-value pairs.

                public static function meta(array $attributes = []): Meta
{
    $tag = Meta::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $tag;
}

            
normalTag() public static method

Generates a normal HTML tag.

See also Yiisoft\Html\Tag\CustomTag.

public static normalTag( string $name, string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\CustomTag
$name string

The tag name.

$content string|\Stringable

The tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function normalTag(string $name, string|Stringable $content = '', array $attributes = []): CustomTag
{
    $tag = CustomTag::name($name)->normal();
    if ($content !== '') {
        $tag = $tag->content($content);
    }
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $tag;
}

            
normalizeRegexpPattern() public static method

Normalize PCRE regular expression to use in the "pattern" HTML attribute: - convert \x{FFFF} to \uFFFF; - remove flags and delimiters.

For example:

Html::normalizeRegexpPattern('/([a-z0-9-]+)/im'); // will return: ([a-z0-9-]+)
public static normalizeRegexpPattern( string $regexp, string|null $delimiter null ): string
$regexp string

PCRE regular expression. It must be valid UTF-8 string.

$delimiter string|null

Regular expression delimiter.

return string

Value for use in the "pattern" HTML attribute

throws InvalidArgumentException

if incorrect regular expression or delimiter

                public static function normalizeRegexpPattern(string $regexp, ?string $delimiter = null): string
{
    if (strlen($regexp) < 2) {
        throw new InvalidArgumentException('Incorrect regular expression.');
    }
    /**
     * @var string $pattern We assume that `$regexp` is valid UTF-8 string, so `preg_replace()` never returns
     * `null`.
     */
    $pattern = preg_replace('/\\\\x{?([0-9a-fA-F]+)}?/', '\u$1', $regexp);
    if ($delimiter === null) {
        $delimiter = substr($pattern, 0, 1);
    } elseif (strlen($delimiter) !== 1) {
        throw new InvalidArgumentException('Incorrect delimiter.');
    }
    $endPosition = strrpos($pattern, $delimiter, 1);
    if ($endPosition === false) {
        throw new InvalidArgumentException('Incorrect regular expression.');
    }
    return substr($pattern, 1, $endPosition - 1);
}

            
noscript() public static method

Generates a Yiisoft\Html\Tag\Noscript tag.

public static noscript( string|\Stringable $content '' ): Yiisoft\Html\Tag\Noscript
$content string|\Stringable

Tag content.

                public static function noscript(string|Stringable $content = ''): Noscript
{
    $tag = Noscript::tag();
    return $content === '' ? $tag : $tag->content($content);
}

            
ol() public static method

Generates a Yiisoft\Html\Tag\Ol tag.

public static ol( array $attributes = [] ): Yiisoft\Html\Tag\Ol
$attributes array

The tag attributes in terms of name-value pairs.

                public static function ol(array $attributes = []): Ol
{
    $tag = Ol::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $tag;
}

            
openTag() public static method

Generates a start tag.

See also \Yiisoft\Html\self::closeTag().

public static openTag( string $name, array $attributes = [] ): string
$name string

The tag name.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function openTag(string $name, array $attributes = []): string
{
    return '<' . $name . self::renderTagAttributes($attributes) . '>';
}

            
optgroup() public static method

Generates a Yiisoft\Html\Tag\Optgroup tag.

public static optgroup( ): Yiisoft\Html\Tag\Optgroup

                public static function optgroup(): Optgroup
{
    return Optgroup::tag();
}

            
option() public static method

Generates a Yiisoft\Html\Tag\Option tag.

public static option( string|\Stringable $content '', boolean|float|integer|string|\Stringable|null $value null ): Yiisoft\Html\Tag\Option
$content string|\Stringable

Tag content.

$value boolean|float|integer|string|\Stringable|null

The value attribute.

                public static function option(
    string|Stringable $content = '',
    bool|float|int|string|Stringable|null $value = null,
): Option {
    $tag = Option::tag();
    if ($content !== '') {
        $tag = $tag->content($content);
    }
    if ($value !== null) {
        $tag = $tag->value($value);
    }
    return $tag;
}

            
p() public static method

Generates a Yiisoft\Html\Tag\P tag.

public static p( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\P
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function p(string|Stringable $content = '', array $attributes = []): P
{
    $tag = P::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
passwordInput() public static method

Generates a password input field.

See also Yiisoft\Html\Tag\Input::password().

public static passwordInput( string|null $name null, boolean|float|integer|string|\Stringable|null $value null, array $attributes = [] ): Yiisoft\Html\Tag\Input
$name string|null

The name attribute.

$value boolean|float|integer|string|\Stringable|null

The value attribute.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function passwordInput(
    ?string $name = null,
    bool|float|int|string|Stringable|null $value = null,
    array $attributes = [],
): Input {
    $tag = Input::password($name, $value);
    return $attributes === [] ? $tag : $tag->addAttributes($attributes);
}

            
picture() public static method

Generates a Yiisoft\Html\Tag\Picture tag.

public static picture( ): Yiisoft\Html\Tag\Picture

                public static function picture(): Picture
{
    return Picture::tag();
}

            
pre() public static method

Generates a Yiisoft\Html\Tag\Pre tag.

public static pre( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Pre
$content string|\Stringable

Tag content. If content includes HTML tags or special characters like <, >, or &, and you want them to be displayed as plain text, you need to enable encoding by calling ->encode(true). This ensures they are not interpreted as actual HTML.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function pre(string|Stringable $content = '', array $attributes = []): Pre
{
    $tag = Pre::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
radio() public static method

Generates a radio button Yiisoft\Html\Tag\Input.

See also Yiisoft\Html\Tag\Input::radio().

public static radio( string|null $name null, boolean|float|integer|string|\Stringable|null $value null, array $attributes = [] ): Yiisoft\Html\Tag\Input\Radio
$name string|null

The name attribute.

$value boolean|float|integer|string|\Stringable|null

The value attribute.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function radio(
    ?string $name = null,
    bool|float|int|string|Stringable|null $value = null,
    array $attributes = [],
): Radio {
    $tag = Input::radio($name, $value);
    return $attributes === [] ? $tag : $tag->addAttributes($attributes);
}

            
radioList() public static method

Generates a list of radio buttons.

See also Yiisoft\Html\Widget\RadioList\RadioList.

public static radioList( string $name ): Yiisoft\Html\Widget\RadioList\RadioList
$name string

                public static function radioList(string $name): RadioList
{
    return RadioList::create($name);
}

            
range() public static method
public static range( string|null $name null, float|integer|string|\Stringable|null $value null, array $attributes = [] ): Yiisoft\Html\Tag\Input\Range
$name string|null

The name attribute.

$value float|integer|string|\Stringable|null

The value attribute.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function range(
    ?string $name = null,
    float|int|string|Stringable|null $value = null,
    array $attributes = [],
): Range {
    $tag = Input::range($name, $value);
    return $attributes === [] ? $tag : $tag->addAttributes($attributes);
}

            
removeCssClass() public static method

Removes a CSS class from the specified options.

See also addCssClass().

public static removeCssClass( array &$options, string|string[] $class ): void
$options array

The options to be modified.

$class string|string[]

The CSS class(es) to be removed.

                public static function removeCssClass(array &$options, string|array $class): void
{
    if (isset($options['class'])) {
        if (is_array($options['class'])) {
            $classes = array_diff($options['class'], (array) $class);
            if (empty($classes)) {
                unset($options['class']);
            } else {
                $options['class'] = $classes;
            }
        } else {
            /** @var string[] */
            $classes = preg_split('/\s+/', (string) $options['class'], -1, PREG_SPLIT_NO_EMPTY);
            $classes = array_diff($classes, (array) $class);
            if (empty($classes)) {
                unset($options['class']);
            } else {
                $options['class'] = implode(' ', $classes);
            }
        }
    }
}

            
removeCssStyle() public static method

Removes the specified CSS styles from the HTML options.

For example,

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

See also addCssStyle().

public static removeCssStyle( array &$options, string|string[] $properties ): void
$options array

The HTML options to be modified.

$properties string|string[]

The CSS properties to be removed. You may use a string if you are removing a single property.

                public static function removeCssStyle(array &$options, string|array $properties): void
{
    if (!empty($options['style'])) {
        /** @psalm-var array<string,string>|string $options['style'] */
        $style = is_array($options['style']) ? $options['style'] : self::cssStyleToArray($options['style']);
        foreach ((array) $properties as $property) {
            unset($style[$property]);
        }
        $options['style'] = self::cssStyleFromArray($style);
    }
}

            
renderTagAttributes() public static method

Renders the HTML tag attributes.

Attributes whose values are of boolean type will be treated as boolean attributes.

Attributes whose values are null will not be rendered. The values of attributes will be HTML-encoded using encodeAttribute().

The "data" attribute is specially handled when it is receiving an array value. In this case, the array will be "expanded" and a list data attributes will be rendered. For example, if 'data' => ['id' => 1, 'name' => 'yii'] then this will be rendered data-id="1" data-name="yii".

Additionally, 'data' => ['params' => ['id' => 1, 'name' => 'yii'], 'status' => 'ok'] will be rendered as: data-params='{"id":1,"name":"yii"}' data-status="ok".

public static renderTagAttributes( array $attributes ): string
$attributes array

Attributes to be rendered. The attribute values will be HTML-encoded using encodeAttribute().

return 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.

throws JsonException

                public static function renderTagAttributes(array $attributes): string
{
    if (count($attributes) > 1) {
        $sorted = [];
        foreach (self::ATTRIBUTE_ORDER as $name) {
            if (isset($attributes[$name])) {
                $sorted[$name] = $attributes[$name];
            }
        }
        $attributes = array_merge($sorted, $attributes);
    }
    $html = '';
    /**
     * @var string $name
     */
    foreach ($attributes as $name => $value) {
        if (is_bool($value)) {
            if ($value) {
                $html .= self::renderAttribute($name);
            }
        } elseif (is_array($value)) {
            if (in_array($name, self::DATA_ATTRIBUTES, true)) {
                /** @psalm-var array<array-key, scalar[]|string|Stringable|null> $value */
                foreach ($value as $n => $v) {
                    if (!isset($v)) {
                        continue;
                    }
                    $fullName = "$name-$n";
                    if (in_array($fullName, self::ATTRIBUTES_WITH_CONCATENATED_VALUES, true)) {
                        $html .= self::renderAttribute(
                            $fullName,
                            self::encodeAttribute(
                                is_array($v) ? implode(' ', $v) : $v,
                            ),
                        );
                    } else {
                        $html .= is_array($v)
                            ? self::renderAttribute($fullName, Json::htmlEncode($v), '\'')
                            : self::renderAttribute($fullName, self::encodeAttribute($v));
                    }
                }
            } elseif (in_array($name, self::ATTRIBUTES_WITH_CONCATENATED_VALUES, true)) {
                /** @var string[] $value */
                if (empty($value)) {
                    continue;
                }
                $html .= self::renderAttribute($name, self::encodeAttribute(implode(' ', $value)));
            } elseif ($name === 'style') {
                /** @psalm-var array<string,string> $value */
                if (empty($value)) {
                    continue;
                }
                $html .= self::renderAttribute($name, self::encodeAttribute(self::cssStyleFromArray($value)));
            } else {
                $html .= self::renderAttribute($name, Json::htmlEncode($value), '\'');
            }
        } elseif ($value !== null) {
            $html .= self::renderAttribute($name, self::encodeAttribute($value));
        }
    }
    return $html;
}

            
resetButton() public static method

Generates a reset button tag.

See also Yiisoft\Html\Tag\Button::reset().

public static resetButton( string $content 'Reset', array $attributes = [] ): Yiisoft\Html\Tag\Button
$content string

The content enclosed within the button tag.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function resetButton(string $content = 'Reset', array $attributes = []): Button
{
    $tag = Button::reset($content);
    if (!empty($attributes)) {
        $tag = $tag->addAttributes($attributes);
    }
    return $tag;
}

            
resetInput() public static method
public static resetInput( string|null $label 'Reset', array $attributes = [] ): Yiisoft\Html\Tag\Input
$label string|null

The value attribute.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function resetInput(?string $label = 'Reset', array $attributes = []): Input
{
    $tag = Input::resetButton($label);
    if (!empty($attributes)) {
        $tag = $tag->addAttributes($attributes);
    }
    return $tag;
}

            
script() public static method

Generates a Yiisoft\Html\Tag\Script tag.

public static script( string $content '', array $attributes = [] ): Yiisoft\Html\Tag\Script
$content string

The script content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function script(string $content = '', array $attributes = []): Script
{
    $tag = Script::tag();
    if ($content !== '') {
        $tag = $tag->content($content);
    }
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $tag;
}

            
section() public static method

Generates a Yiisoft\Html\Tag\Section tag.

public static section( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Section
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function section(string|Stringable $content = '', array $attributes = []): Section
{
    $tag = Section::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
select() public static method

Generates a Yiisoft\Html\Tag\Select tag.

public static select( string|null $name null ): Yiisoft\Html\Tag\Select
$name string|null

The name attribute

                public static function select(?string $name = null): Select
{
    $tag = Select::tag();
    if ($name !== null) {
        $tag = $tag->name($name);
    }
    return $tag;
}

            
small() public static method

Generates a Yiisoft\Html\Tag\Small tag.

public static small( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Small
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function small(string|Stringable $content = '', array $attributes = []): Small
{
    $tag = Small::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
source() public static method

Generates a Yiisoft\Html\Tag\Source tag.

public static source( ): Yiisoft\Html\Tag\Source

                public static function source(): Source
{
    return Source::tag();
}

            
span() public static method

Generates a Yiisoft\Html\Tag\Span tag.

public static span( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Span
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function span(string|Stringable $content = '', array $attributes = []): Span
{
    $tag = Span::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
strong() public static method

Generates a Yiisoft\Html\Tag\Strong tag.

public static strong( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Strong
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function strong(string|Stringable $content = '', array $attributes = []): Strong
{
    $tag = Strong::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
style() public static method

Generates a Yiisoft\Html\Tag\Style tag.

public static style( string $content '', array $attributes = [] ): Yiisoft\Html\Tag\Style
$content string

The style content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function style(string $content = '', array $attributes = []): Style
{
    $tag = Style::tag();
    if ($content !== '') {
        $tag = $tag->content($content);
    }
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $tag;
}

            
submitButton() public static method

Generates a submit button tag.

See also Yiisoft\Html\Tag\Button::submit().

public static submitButton( string $content 'Submit', array $attributes = [] ): Yiisoft\Html\Tag\Button
$content string

The content enclosed within the button tag.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function submitButton(string $content = 'Submit', array $attributes = []): Button
{
    $tag = Button::submit($content);
    if (!empty($attributes)) {
        $tag = $tag->addAttributes($attributes);
    }
    return $tag;
}

            
submitInput() public static method
public static submitInput( string|null $label 'Submit', array $attributes = [] ): Yiisoft\Html\Tag\Input
$label string|null

The value attribute.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function submitInput(?string $label = 'Submit', array $attributes = []): Input
{
    $tag = Input::submitButton($label);
    if (!empty($attributes)) {
        $tag = $tag->addAttributes($attributes);
    }
    return $tag;
}

            
table() public static method

Generates a Yiisoft\Html\Tag\Table tag.

public static table( array $attributes = [] ): Yiisoft\Html\Tag\Table
$attributes array

The tag attributes in terms of name-value pairs.

                public static function table(array $attributes = []): Table
{
    $tag = Table::tag();
    return $attributes === [] ? $tag : $tag->attributes($attributes);
}

            
tag() public static method

Generates a complete HTML tag.

See also Yiisoft\Html\Tag\CustomTag.

public static tag( string $name, string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\CustomTag
$name string

The tag name.

$content string|\Stringable

The tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function tag(string $name, string|Stringable $content = '', array $attributes = []): CustomTag
{
    $tag = CustomTag::name($name);
    if ($content !== '') {
        $tag = $tag->content($content);
    }
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $tag;
}

            
tbody() public static method

Generates a Yiisoft\Html\Tag\Tbody tag.

public static tbody( array $attributes = [] ): Yiisoft\Html\Tag\Tbody
$attributes array

The tag attributes in terms of name-value pairs.

                public static function tbody(array $attributes = []): Tbody
{
    $tag = Tbody::tag();
    return $attributes === [] ? $tag : $tag->attributes($attributes);
}

            
td() public static method

Generates a Yiisoft\Html\Tag\Td tag.

public static td( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Td
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function td(string|Stringable $content = '', array $attributes = []): Td
{
    $tag = Td::tag();
    if ($content !== '') {
        $tag = $tag->content($content);
    }
    if ($attributes !== []) {
        $tag = $tag->attributes($attributes);
    }
    return $tag;
}

            
textInput() public static method

Generates a text Yiisoft\Html\Tag\Input field.

public static textInput( string|null $name null, boolean|float|integer|string|\Stringable|null $value null, array $attributes = [] ): Yiisoft\Html\Tag\Input
$name string|null

The name attribute.

$value boolean|float|integer|string|\Stringable|null

The value attribute.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function textInput(
    ?string $name = null,
    bool|float|int|string|Stringable|null $value = null,
    array $attributes = [],
): Input {
    $tag = Input::text($name, $value);
    return $attributes === [] ? $tag : $tag->addAttributes($attributes);
}

            
textarea() public static method

Generates a Yiisoft\Html\Tag\Textarea input.

public static textarea( string|null $name null, string|string[]|\Stringable|null $value null, array $attributes = [] ): Yiisoft\Html\Tag\Textarea
$name string|null

The input name.

$value string|string[]|\Stringable|null

The input value.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function textarea(?string $name = null, string|Stringable|array|null $value = null, array $attributes = []): Textarea
{
    $tag = Textarea::tag();
    if ($name !== null) {
        $tag = $tag->name($name);
    }
    if (!empty($value)) {
        $tag = $tag->value($value);
    }
    return $attributes === [] ? $tag : $tag->addAttributes($attributes);
}

            
tfoot() public static method

Generates a Yiisoft\Html\Tag\Tfoot tag.

public static tfoot( array $attributes = [] ): Yiisoft\Html\Tag\Tfoot
$attributes array

The tag attributes in terms of name-value pairs.

                public static function tfoot(array $attributes = []): Tfoot
{
    $tag = Tfoot::tag();
    return $attributes === [] ? $tag : $tag->attributes($attributes);
}

            
th() public static method

Generates a Yiisoft\Html\Tag\Th tag.

public static th( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Th
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function th(string|Stringable $content = '', array $attributes = []): Th
{
    $tag = Th::tag();
    if ($content !== '') {
        $tag = $tag->content($content);
    }
    if ($attributes !== []) {
        $tag = $tag->attributes($attributes);
    }
    return $tag;
}

            
thead() public static method

Generates a Yiisoft\Html\Tag\Thead tag.

public static thead( array $attributes = [] ): Yiisoft\Html\Tag\Thead
$attributes array

The tag attributes in terms of name-value pairs.

                public static function thead(array $attributes = []): Thead
{
    $tag = Thead::tag();
    return $attributes === [] ? $tag : $tag->attributes($attributes);
}

            
title() public static method

Generates a Yiisoft\Html\Tag\Title tag.

public static title( string|\Stringable $content '', array $attributes = [] ): Yiisoft\Html\Tag\Title
$content string|\Stringable

Tag content.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function title(string|Stringable $content = '', array $attributes = []): Title
{
    $tag = Title::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $content === '' ? $tag : $tag->content($content);
}

            
tr() public static method

Generates a Yiisoft\Html\Tag\Tr tag.

public static tr( array $attributes = [] ): Yiisoft\Html\Tag\Tr
$attributes array

The tag attributes in terms of name-value pairs.

                public static function tr(array $attributes = []): Tr
{
    $tag = Tr::tag();
    return $attributes === [] ? $tag : $tag->attributes($attributes);
}

            
track() public static method

Generates a Yiisoft\Html\Tag\Track tag.

public static track( string|null $src null ): Yiisoft\Html\Tag\Track
$src string|null

                public static function track(?string $src = null): Track
{
    $tag = Track::tag();
    return $src === null ? $tag : $tag->src($src);
}

            
ul() public static method

Generates a Yiisoft\Html\Tag\Ul tag.

public static ul( array $attributes = [] ): Yiisoft\Html\Tag\Ul
$attributes array

The tag attributes in terms of name-value pairs.

                public static function ul(array $attributes = []): Ul
{
    $tag = Ul::tag();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $tag;
}

            
video() public static method

Generates a Yiisoft\Html\Tag\Video tag.

public static video( ): Yiisoft\Html\Tag\Video

                public static function video(): Video
{
    return Video::tag();
}

            
voidTag() public static method

Generates a void HTML tag.

See also Yiisoft\Html\Tag\CustomTag.

public static voidTag( string $name, array $attributes = [] ): Yiisoft\Html\Tag\CustomTag
$name string

The tag name.

$attributes array

The tag attributes in terms of name-value pairs.

                public static function voidTag(string $name, array $attributes = []): CustomTag
{
    $tag = CustomTag::name($name)->void();
    if (!empty($attributes)) {
        $tag = $tag->attributes($attributes);
    }
    return $tag;
}