Skip to content
PHP Ecosystem
Explore

Button

API reference › HTML › Form › Button

Renders the HTML <button> element.

Supports the experimental command and commandfor attributes. Availability and behavior may vary across browsers.

See also: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/button (BaseInline for the base implementation.).

PropertyTypeDescriptionDefined by
$attributes protectedmixed[]HTML attributes array used by the implementing class. Default: [].UIAwesome\Html\Mixin\HasAttributes
$content protectedstringContent string assigned to the element. Default: ''.UIAwesome\Html\Mixin\HasContent
$prefix protectedstringPrefix content string assigned to the element. Default: ''.UIAwesome\Html\Mixin\HasPrefixCollection
$prefixAttributes protectedarrayHTML attributes array for the prefix element. Default: [].UIAwesome\Html\Mixin\HasPrefixCollection
$prefixTag protectedfalse|UnitEnumTag name for the prefix element, or false to disable. Default: false.UIAwesome\Html\Mixin\HasPrefixCollection
$suffix protectedstringSuffix content string assigned to the element. Default: ''.UIAwesome\Html\Mixin\HasSuffixCollection
$suffixAttributes protectedarrayHTML attributes array for the suffix element. Default: [].UIAwesome\Html\Mixin\HasSuffixCollection
$suffixTag protectedfalse|UnitEnumTag name for the suffix element, or false to disable. Default: false.UIAwesome\Html\Mixin\HasSuffixCollection
$template protectedstringTemplate string used for constructing the HTML tag. Default: ''.UIAwesome\Html\Mixin\HasTemplate
MethodDescriptionDefined by
__construct() finalInitializes a new tag instance.UIAwesome\Html\Core\Base\BaseTag
__toString()Returns the rendered tag string.UIAwesome\Html\Core\Base\BaseTag
accesskey()Sets the accesskey attribute.UIAwesome\Html\Attribute\Global\HasAccesskey
addAriaAttribute()Sets an aria-* attribute.UIAwesome\Html\Attribute\Global\HasAria
addAttribute()Adds or updates a single HTML attribute for the element.UIAwesome\Html\Mixin\HasAttributes
addDataAttribute()Sets a data-* attribute.UIAwesome\Html\Attribute\Global\HasData
addEvent()Sets an on* event attribute.UIAwesome\Html\Attribute\Global\HasEvents
ariaAttributes()Sets multiple aria-* attributes.UIAwesome\Html\Attribute\Global\HasAria
attributes()Adds or updates multiple HTML attributes for the element.UIAwesome\Html\Mixin\HasAttributes
autofocus()Sets the autofocus attribute.UIAwesome\Html\Attribute\Global\CanBeAutofocus
class()Sets the class attribute.UIAwesome\Html\Attribute\Global\HasClass
clearContent()Clears encoded and raw content without changing other component state.UIAwesome\Html\Mixin\HasContent
command()Sets the command attribute.Button
commandfor()Sets the commandfor attribute.Button
config()Applies application-scoped config recipes to this tag.UIAwesome\Html\Core\Base\BaseTag
content()Appends encoded content.UIAwesome\Html\Mixin\HasContent
dataAttributes()Sets multiple data-* attributes.UIAwesome\Html\Attribute\Global\HasData
dir()Sets the dir attribute.UIAwesome\Html\Attribute\Global\HasDir
disabled()Sets the disabled attribute.UIAwesome\Html\Attribute\CanBeDisabled
events()Sets multiple on* event attributes.UIAwesome\Html\Attribute\Global\HasEvents
form()Sets the form attribute.Button
formaction()Sets the formaction attribute.Button
formenctype()Sets the formenctype attribute.Button
formmethod()Sets the formmethod attribute.Button
formnovalidate()Sets the formnovalidate attribute.Button
formtarget()Sets the formtarget attribute.Button
getAttribute()Returns the value of a single HTML attribute.UIAwesome\Html\Mixin\HasAttributes
getAttributes()Returns the array of HTML attributes for the element.UIAwesome\Html\Mixin\HasAttributes
getContent()Returns the content assigned to the element.UIAwesome\Html\Mixin\HasContent
getPrefix()Returns the prefix content string assigned to the element.UIAwesome\Html\Mixin\HasPrefixCollection
getPrefixAttribute()Returns the value of a single HTML attribute for the prefix element attributes.UIAwesome\Html\Mixin\HasPrefixCollection
getPrefixAttributes()Returns the array of HTML attributes for the prefix element.UIAwesome\Html\Mixin\HasPrefixCollection
getPrefixTag()Returns the tag name for the prefix element.UIAwesome\Html\Mixin\HasPrefixCollection
getSuffix()Returns the suffix content string assigned to the element.UIAwesome\Html\Mixin\HasSuffixCollection
getSuffixAttribute()Returns the value of a single HTML attribute for the suffix element attributes.UIAwesome\Html\Mixin\HasSuffixCollection
getSuffixAttributes()Returns the array of HTML attributes for the suffix element.UIAwesome\Html\Mixin\HasSuffixCollection
getSuffixTag()Returns the tag name for the suffix element.UIAwesome\Html\Mixin\HasSuffixCollection
getTemplate()Returns the template assigned to the element.UIAwesome\Html\Mixin\HasTemplate
hidden()Sets the hidden attribute.UIAwesome\Html\Attribute\Global\CanBeHidden
html()Appends trusted raw HTML content without encoding or sanitizing it.UIAwesome\Html\Mixin\HasContent
id()Sets the id attribute.UIAwesome\Html\Attribute\Global\HasId
lang()Sets the lang attribute.UIAwesome\Html\Attribute\Global\HasLang
name()Sets the name attribute.UIAwesome\Html\Attribute\HasName
popoverTarget()Sets the popovertarget attribute.Button
popoverTargetAction()Sets the popovertargetaction attribute.Button
prefix()Sets the prefix content string for the element.UIAwesome\Html\Mixin\HasPrefixCollection
prefixAttributes()Sets the HTML attributes for the prefix element.UIAwesome\Html\Mixin\HasPrefixCollection
prefixClass()Adds a CSS class to the prefix element attributes.UIAwesome\Html\Mixin\HasPrefixCollection
prefixRemoveAttribute()Removes a specific HTML attribute from the prefix element.UIAwesome\Html\Mixin\HasPrefixCollection
prefixSetAttribute()Sets a single HTML attribute for the prefix element.UIAwesome\Html\Mixin\HasPrefixCollection
prefixTag()Sets the tag name for the prefix element.UIAwesome\Html\Mixin\HasPrefixCollection
removeAriaAttribute()Removes an aria-* attribute.UIAwesome\Html\Attribute\Global\HasAria
removeAttribute()Removes a specific HTML attribute from the element.UIAwesome\Html\Mixin\HasAttributes
removeDataAttribute()Removes a data-* attribute.UIAwesome\Html\Attribute\Global\HasData
removeEvent()Removes an on* event attribute.UIAwesome\Html\Attribute\Global\HasEvents
render() finalRenders the tag with lifecycle hooks.UIAwesome\Html\Core\Base\BaseTag
replaceAttributes()Replaces all HTML attributes for the element.UIAwesome\Html\Mixin\HasAttributes
role()Sets the role attribute.UIAwesome\Html\Attribute\Global\HasRole
style()Sets the style attribute.UIAwesome\Html\Attribute\Global\HasStyle
suffix()Sets the suffix content string for the element.UIAwesome\Html\Mixin\HasSuffixCollection
suffixAttributes()Sets the HTML attributes for the suffix element.UIAwesome\Html\Mixin\HasSuffixCollection
suffixClass()Adds a CSS class to the suffix element attributes.UIAwesome\Html\Mixin\HasSuffixCollection
suffixRemoveAttribute()Removes a specific HTML attribute from the suffix element.UIAwesome\Html\Mixin\HasSuffixCollection
suffixSetAttribute()Sets a single HTML attribute for the suffix element.UIAwesome\Html\Mixin\HasSuffixCollection
suffixTag()Sets the tag type for the suffix element.UIAwesome\Html\Mixin\HasSuffixCollection
tabIndex()Sets the tabindex attribute.UIAwesome\Html\Attribute\Global\HasTabindex
tag() staticCreates and configures a new tag instance.UIAwesome\Html\Core\Base\BaseTag
template()Sets the template string for the element.UIAwesome\Html\Mixin\HasTemplate
title()Sets the title attribute.UIAwesome\Html\Attribute\Global\HasTitle
translate()Sets the translate attribute.UIAwesome\Html\Attribute\Global\HasTranslate
type()Sets the type attribute.Button
value()Sets the value attribute.UIAwesome\Html\Attribute\HasValue
afterRun() protectedPost-processes rendered output.UIAwesome\Html\Core\Event\HasAfterRun
beforeRun() protectedValidates state before rendering.UIAwesome\Html\Core\Event\HasBeforeRun
buildElement() protectedBuilds element output from content and template tokens.UIAwesome\Html\Core\Element\Concern\HasElementBuilder
getTag() protectedReturns the tag enumeration for the <button> element.Button
loadDefault() protectedReturns class-level default definitions.UIAwesome\Html\Core\Base\BaseTag
run() protectedRenders the <button> element with its content and attributes.Button
public function command(string|Stringable|UnitEnum|null $value): static

Sets the command attribute.

Parameters

ParameterTypeDescription
$valuestring|Stringable|UnitEnum|nullCommand value, or null to remove the attribute. Accepts predefined values (‘show-modal’, ‘close’, ‘request-close’, ‘show-popover’, ‘hide-popover’, ‘toggle-popover’) or any custom value prefixed with ’—’.

Returns

static: New instance with the updated command attribute. ButtonCommand for predefined enum values.

public function commandfor(string|Stringable|UnitEnum|null $value): static

Sets the commandfor attribute.

Parameters

ParameterTypeDescription
$valuestring|Stringable|UnitEnum|nullID of the element to control, or null to remove the attribute.

Returns

static: New instance with the updated commandfor attribute.

public function form(string|Stringable|UnitEnum|null $value): static

Sets the form attribute.

Parameters

ParameterTypeDescription
$valuestring|Stringable|UnitEnum|nullForm ID, or null to remove the attribute.

Returns

static: New instance with the updated form attribute.

public function formaction(string|Stringable|UnitEnum|null $value): static

Sets the formaction attribute.

Parameters

ParameterTypeDescription
$valuestring|Stringable|UnitEnum|nullURL for form submission, or null to remove the attribute.

Returns

static: New instance with the updated formaction attribute.

public function formenctype(string|Stringable|UnitEnum|null $value): static

Sets the formenctype attribute.

Parameters

ParameterTypeDescription
$valuestring|Stringable|UnitEnum|nullEncoding type for form submission, or null to remove the attribute.

Returns

static: New instance with the updated formenctype attribute.

public function formmethod(string|Stringable|UnitEnum|null $value): static

Sets the formmethod attribute.

Parameters

ParameterTypeDescription
$valuestring|Stringable|UnitEnum|nullHTTP method for form submission, or null to remove the attribute.

Returns

static: New instance with the updated formmethod attribute.

public function formnovalidate(bool|null $value): static

Sets the formnovalidate attribute.

Parameters

ParameterTypeDescription
$valuebool|nullWhether to bypass form validation, or null to remove the attribute.

Returns

static: New instance with the updated formnovalidate attribute.

public function formtarget(string|Stringable|UnitEnum|null $value): static

Sets the formtarget attribute.

Parameters

ParameterTypeDescription
$valuestring|Stringable|UnitEnum|nullBrowsing context for form submission response, or null to remove the attribute.

Returns

static: New instance with the updated formtarget attribute.

public function popoverTarget(string|Stringable|UnitEnum|null $value): static

Sets the popovertarget attribute.

Parameters

ParameterTypeDescription
$valuestring|Stringable|UnitEnum|nullPopover target ID, or null to remove the attribute.

Returns

static: New instance with the updated popovertarget attribute.

public function popoverTargetAction(string|Stringable|UnitEnum|null $value): static

Sets the popovertargetaction attribute.

Parameters

ParameterTypeDescription
$valuestring|Stringable|UnitEnum|nullPopover target action (‘hide’, ‘show’, ‘toggle’), or null to remove the attribute.

Returns

static: New instance with the updated popovertargetaction attribute.

Throws

public function type(string|UnitEnum|null $value): static

Sets the type attribute.

Parameters

ParameterTypeDescription
$valuestring|UnitEnum|nullButton type (‘button’, ‘reset’, ‘submit’), or null to remove the attribute.

Returns

static: New instance with the updated type attribute. ButtonType for predefined enum values.

Throws

protected function getTag(): UIAwesome\Html\Interop\Inline

Returns the tag enumeration for the <button> element.

Returns

Inline: Tag enumeration instance for <button>. Inline for valid inline-level tags.

protected function run(): string

Renders the <button> element with its content and attributes.

Returns

string: Rendered HTML for the <button> element.