Logo

Button

Button is the primary interactive component for triggering actions like form submissions, navigation, opening modals, and API calls. It supports multiple visual styles and sizes to match different UI contexts and importance levels.
Key features:
  • Visual hierarchy: Choose from solid, outlined, or ghost variants to indicate importance
  • Theme colors: Use primary, secondary, or attention colors for different action types
  • Icon support: Add icons before or after text, or create icon-only buttons
  • Form integration: Automatically handles form submission when used in forms

Properties

autoFocus (default: false)

Indicates if the button should receive focus when the page loads.

contentPosition (default: "center")

This optional value determines how the label and icon (or nested children) should be placedinside the Button component.
Available values:
ValueDescription
centerPlace the content in the middle (default)
startJustify the content to the left (to the right if in right-to-left)
endJustify the content to the right (to the left if in right-to-left)
<App>
  <Button width="200px" icon="drive" label="Button" contentPosition="center" />
  <Button width="200px" icon="drive" label="Button" contentPosition="start" />
  <Button width="200px" icon="drive" label="Button" contentPosition="end" />
  <Button width="200px" contentPosition="end">
    This is a nested text
  </Button>
</App>
Example: content position
<App>
  <Button width="200px" icon="drive" label="Button" contentPosition="center" />
  <Button width="200px" icon="drive" label="Button" contentPosition="start" />
  <Button width="200px" icon="drive" label="Button" contentPosition="end" />
  <Button width="200px" contentPosition="end">
    This is a nested text
  </Button>
</App>

contextualLabel

This optional value is used to provide an accessible name for the Button in the context of its usage.

enabled (default: true)

The value of this property indicates whether the button accepts actions (true) or does not react to them (false).
<App>
  <HStack>
    <Button label="I am enabled (by default)" />
    <Button label="I am enabled explicitly" enabled="true" />
    <Button label="I am not enabled" enabled="false" />
  </HStack>
</App>
Example: enabled
<App>
  <HStack>
    <Button label="I am enabled (by default)" />
    <Button label="I am enabled explicitly" enabled="true" />
    <Button label="I am not enabled" enabled="false" />
  </HStack>
</App>

icon

This string value denotes an icon name. The framework will render an icon if XMLUI recognizes the icon by its name. If no label is specified and an icon is set, the Button displays only that icon.
<App>
  <HStack>
    <Button icon="drive" label="Let there be drive" />
    <Button icon="drive" />
  </HStack>
</App>
Example: icon
<App>
  <HStack>
    <Button icon="drive" label="Let there be drive" />
    <Button icon="drive" />
  </HStack>
</App>

iconPosition (default: "start")

This optional string determines the location of the icon in the Button.
Available values:
ValueDescription
startThe icon will appear at the start (left side when the left-to-right direction is set) (default)
endThe icon will appear at the end (right side when the left-to-right direction is set)
<App>
  <HStack>
    <Button icon="drive" label="Left" />
    <Button icon="drive" label="Right" iconPosition="right" />
  </HStack>
  <HStack>
    <Button icon="drive" label="Start" iconPosition="start" />
    <Button icon="drive" label="End" iconPosition="end" />
  </HStack>
  <HStack>
    <Button 
      icon="drive" 
      label="Start (right-to-left)" 
      iconPosition="start" 
      direction="rtl" />
    <Button 
      icon="drive" 
      label="End (right-to-left)" 
      iconPosition="end" 
      direction="rtl" />
  </HStack>
</App>
Example: icon position
<App>
  <HStack>
    <Button icon="drive" label="Left" />
    <Button icon="drive" label="Right" iconPosition="right" />
  </HStack>
  <HStack>
    <Button icon="drive" label="Start" iconPosition="start" />
    <Button icon="drive" label="End" iconPosition="end" />
  </HStack>
  <HStack>
    <Button 
      icon="drive" 
      label="Start (right-to-left)" 
      iconPosition="start" 
      direction="rtl" />
    <Button 
      icon="drive" 
      label="End (right-to-left)" 
      iconPosition="end" 
      direction="rtl" />
  </HStack>
</App>

label

This property is an optional string to set a label for the Button. If no label is specified and an icon is set, the Button will modify its styling to look like a small icon button. When the Button has nested children, it will display them and ignore the value of the label prop.
<App>
  <Button label="I am the button label" />
  <Button />
  <Button label="I am the button label">
    <Icon name="trash" />
    I am a text nested into Button
  </Button>
</App>
Example: label
<App>
  <Button label="I am the button label" />
  <Button />
  <Button label="I am the button label">
    <Icon name="trash" />
    I am a text nested into Button
  </Button>
</App>

orientation (default: "horizontal")

This property sets the main axis along which the nested components are rendered.
Available values:
ValueDescription
horizontalThe component will fill the available space horizontally (default)
verticalThe component will fill the available space vertically

size (default: "sm")

Sets the size of the button.
Available values:
ValueDescription
xsExtra small
smSmall (default)
mdMedium
lgLarge
<App>
  <HStack>
    <Button icon="drive" label="default" />
    <Button icon="drive" label="extra-small" size="xs" />
    <Button icon="drive" label="small" size="sm" />
    <Button icon="drive" label="medium" size="md" />
    <Button icon="drive" label="large" size="lg" />
  </HStack>
  <HStack>
    <Button label="default" />
    <Button label="extra-small" size="xs" />
    <Button label="small" size="sm" />
    <Button label="medium" size="md" />
    <Button label="large" size="lg" />
  </HStack>
</App>
Example: size
<App>
  <HStack>
    <Button icon="drive" label="default" />
    <Button icon="drive" label="extra-small" size="xs" />
    <Button icon="drive" label="small" size="sm" />
    <Button icon="drive" label="medium" size="md" />
    <Button icon="drive" label="large" size="lg" />
  </HStack>
  <HStack>
    <Button label="default" />
    <Button label="extra-small" size="xs" />
    <Button label="small" size="sm" />
    <Button label="medium" size="md" />
    <Button label="large" size="lg" />
  </HStack>
</App>

themeColor (default: "primary")

Sets the button color scheme defined in the application theme.
Available values:
ValueDescription
attentionAttention state theme color
primaryPrimary theme color (default)
secondarySecondary theme color
<App>
  <HStack>
    <Button label="Button" themeColor="primary" />
    <Button label="Button" themeColor="secondary" />
    <Button label="Button" themeColor="attention" />
  </HStack>
</App>  
Example: theme colors
<App>
  <HStack>
    <Button label="Button" themeColor="primary" />
    <Button label="Button" themeColor="secondary" />
    <Button label="Button" themeColor="attention" />
  </HStack>
</App>  

type (default: "button")

This optional string describes how the Button appears in an HTML context. You rarely need to set this property explicitly.
Available values:
ValueDescription
buttonRegular behavior that only executes logic if explicitly determined. (default)
submitThe button submits the form data to the server. This is the default for buttons in a Form or NativeForm component.
resetResets all the controls to their initial values. Using it is ill advised for UX reasons.

variant (default: "solid")

The button variant determines the level of emphasis the button should possess.
Available values:
ValueDescription
solidA button with a border and a filled background. (default)
outlinedThe button is displayed with a border and a transparent background.
ghostA button with no border and fill. Only the label is visible; the background is colored when hovered or clicked.
<App>
  <HStack>
    <Button label="default (solid)" />
    <Button label="solid" variant="solid" />
    <Button label="outlined" variant="outlined" />
    <Button label="ghost" variant="ghost" />
  </HStack>
</App>
Example: variant
<App>
  <HStack>
    <Button label="default (solid)" />
    <Button label="solid" variant="solid" />
    <Button label="outlined" variant="outlined" />
    <Button label="ghost" variant="ghost" />
  </HStack>
</App>

Events

click

This event is triggered when the Button is clicked.
<App>
  <Button label="Click me!" onClick="toast('Button clicked')" />
</App>
Example: click
<App>
  <Button label="Click me!" onClick="toast('Button clicked')" />
</App>

gotFocus

This event is triggered when the Button has received the focus.
<App var.text="No event" >
  <HStack verticalAlignment="center" >
    <Button label="First, click me!" 
      onGotFocus="text = 'Focus received'" 
      onLostFocus="text = 'Focus lost'" />
    <Text value="Then, me!"/>
  </HStack>
  <Text value="{text}" />
</App>
Example: gotFocus
<App var.text="No event" >
  <HStack verticalAlignment="center" >
    <Button label="First, click me!" 
      onGotFocus="text = 'Focus received'" 
      onLostFocus="text = 'Focus lost'" />
    <Text value="Then, me!"/>
  </HStack>
  <Text value="{text}" />
</App>

lostFocus

This event is triggered when the Button has lost the focus.
(See the example above)

Exposed Methods

This component does not expose any methods.

Styling

Fixed width and height

Using a set of buttons with a fixed width or height is often helpful. So Button supports these theme variables:
  • width-Button
  • height-Button
Avoid setting the width-Button and height-Button styles in the theme definition. Instead, wrap the affected button group into a Theme component as in the following example:
Example: Buttons with fixed width

Theme Variables

VariableDefault Value (Light)Default Value (Dark)
backgroundColor-Button--disabled$backgroundColor--disabled$backgroundColor--disabled
backgroundColor-Button-attention$backgroundColor-attention$backgroundColor-attention
backgroundColor-Button-attention--active$color-danger-500$color-danger-500
backgroundColor-Button-attention--hover$color-danger-400$color-danger-400
backgroundColor-Button-attention-ghost--active$color-danger-100$color-danger-100
backgroundColor-Button-attention-ghost--hover$color-danger-50$color-danger-50
backgroundColor-Button-attention-outlined--active$color-danger-100$color-danger-100
backgroundColor-Button-attention-outlined--hover$color-danger-50$color-danger-50
backgroundColor-Button-attention-solidnonenone
backgroundColor-Button-attention-solid--activenonenone
backgroundColor-Button-attention-solid--hovernonenone
backgroundColor-Button-primary$color-primary-500$color-primary-500
backgroundColor-Button-primary--active$color-primary-500$color-primary-500
backgroundColor-Button-primary--hover$color-primary-400$color-primary-400
backgroundColor-Button-primary-ghost--active$color-primary-100$color-primary-100
backgroundColor-Button-primary-ghost--hover$color-primary-50$color-primary-50
backgroundColor-Button-primary-outlined--active$color-primary-100$color-primary-100
backgroundColor-Button-primary-outlined--hover$color-primary-50$color-primary-50
backgroundColor-Button-primary-solidnonenone
backgroundColor-Button-primary-solid--activenonenone
backgroundColor-Button-primary-solid--hovernonenone
backgroundColor-Button-secondary$color-secondary-500$color-secondary-500
backgroundColor-Button-secondary--active$color-secondary-500$color-secondary-500
backgroundColor-Button-secondary--hover$color-secondary-400$color-secondary-400
backgroundColor-Button-secondary-ghost--active$color-secondary-100$color-secondary-100
backgroundColor-Button-secondary-ghost--hover$color-secondary-100$color-secondary-100
backgroundColor-Button-secondary-outlined--active$color-secondary-100$color-secondary-100
backgroundColor-Button-secondary-outlined--hover$color-secondary-50$color-secondary-50
backgroundColor-Button-secondary-solidnonenone
backgroundColor-Button-secondary-solid--activenonenone
backgroundColor-Button-secondary-solid--hovernonenone
borderColor-Button--disabled$borderColor--disabled$borderColor--disabled
borderColor-Button-attention$color-attention$color-attention
borderColor-Button-attention-outlinednonenone
borderColor-Button-attention-outlined--activenonenone
borderColor-Button-attention-outlined--hovernonenone
borderColor-Button-attention-solidnonenone
borderColor-Button-attention-solid--activenonenone
borderColor-Button-attention-solid--hovernonenone
borderColor-Button-primary$color-primary-500$color-primary-500
borderColor-Button-primary-outlined$color-primary-600$color-primary-600
borderColor-Button-primary-outlined--activenonenone
borderColor-Button-primary-outlined--hover$color-primary-500$color-primary-500
borderColor-Button-primary-solidnonenone
borderColor-Button-primary-solid--activenonenone
borderColor-Button-primary-solid--hovernonenone
borderColor-Button-secondary$color-secondary-100$color-secondary-100
borderColor-Button-secondary-outlinednonenone
borderColor-Button-secondary-outlined--activenonenone
borderColor-Button-secondary-outlined--hovernonenone
borderColor-Button-secondary-solidnonenone
borderColor-Button-secondary-solid--activenonenone
borderColor-Button-secondary-solid--hovernonenone
borderRadius-Button$borderRadius$borderRadius
borderRadius-Button-attention-ghostnonenone
borderRadius-Button-attention-outlinednonenone
borderRadius-Button-attention-solidnonenone
borderRadius-Button-primary-ghostnonenone
borderRadius-Button-primary-outlinednonenone
borderRadius-Button-primary-solidnonenone
borderRadius-Button-secondary-ghostnonenone
borderRadius-Button-secondary-outlinednonenone
borderRadius-Button-secondary-solidnonenone
borderStyle-Buttonsolidsolid
borderStyle-Button-attention-outlinednonenone
borderStyle-Button-attention-solidnonenone
borderStyle-Button-primary-outlinednonenone
borderStyle-Button-primary-solidnonenone
borderStyle-Button-secondary-outlinednonenone
borderStyle-Button-secondary-solidnonenone
borderWidth-Button1px1px
borderWidth-Button-attention-ghostnonenone
borderWidth-Button-attention-outlinednonenone
borderWidth-Button-attention-solidnonenone
borderWidth-Button-primary-ghostnonenone
borderWidth-Button-primary-outlinednonenone
borderWidth-Button-primary-solidnonenone
borderWidth-Button-secondary-ghostnonenone
borderWidth-Button-secondary-outlinednonenone
borderWidth-Button-secondary-solidnonenone
boxShadow-Button-attention-outlinednonenone
boxShadow-Button-attention-solidnonenone
boxShadow-Button-attention-solid--activenonenone
boxShadow-Button-primary-outlinednonenone
boxShadow-Button-primary-solidnonenone
boxShadow-Button-primary-solid--activenonenone
boxShadow-Button-secondary-outlinednonenone
boxShadow-Button-secondary-solidnonenone
boxShadow-Button-secondary-solid--activenonenone
fontFamily-Button-attention-ghostnonenone
fontFamily-Button-attention-outlinednonenone
fontFamily-Button-attention-solidnonenone
fontFamily-Button-primary-ghostnonenone
fontFamily-Button-primary-outlinednonenone
fontFamily-Button-primary-solidnonenone
fontFamily-Button-secondary-ghostnonenone
fontFamily-Button-secondary-outlinednonenone
fontFamily-Button-secondary-solidnonenone
fontSize-Button$fontSize-small$fontSize-small
fontSize-Button-attention-ghostnonenone
fontSize-Button-attention-outlinednonenone
fontSize-Button-attention-solidnonenone
fontSize-Button-primary-ghostnonenone
fontSize-Button-primary-outlinednonenone
fontSize-Button-primary-solidnonenone
fontSize-Button-secondary-ghostnonenone
fontSize-Button-secondary-outlinednonenone
fontSize-Button-secondary-solidnonenone
fontWeight-Button$fontWeight-medium$fontWeight-medium
fontWeight-Button-attention-ghostnonenone
fontWeight-Button-attention-outlinednonenone
fontWeight-Button-attention-solidnonenone
fontWeight-Button-primary-ghostnonenone
fontWeight-Button-primary-outlinednonenone
fontWeight-Button-primary-solidnonenone
fontWeight-Button-secondary-ghostnonenone
fontWeight-Button-secondary-outlinednonenone
fontWeight-Button-secondary-solidnonenone
height-Buttonfit-contentfit-content
outlineColor-Button--focus$outlineColor--focus$outlineColor--focus
outlineColor-Button-attention-ghost--focusnonenone
outlineColor-Button-attention-outlined--focusnonenone
outlineColor-Button-attention-solid--focusnonenone
outlineColor-Button-primary-ghost--focusnonenone
outlineColor-Button-primary-outlined--focusnonenone
outlineColor-Button-primary-solid--focusnonenone
outlineColor-Button-secondary-ghost--focusnonenone
outlineColor-Button-secondary-outlined--focusnonenone
outlineColor-Button-secondary-solid--focusnonenone
outlineOffset-Button--focus$outlineOffset--focus$outlineOffset--focus
outlineOffset-Button-attention-ghost--focusnonenone
outlineOffset-Button-attention-outlined--focusnonenone
outlineOffset-Button-attention-solid--focusnonenone
outlineOffset-Button-primary-ghost--focusnonenone
outlineOffset-Button-primary-outlined--focusnonenone
outlineOffset-Button-primary-solid--focusnonenone
outlineOffset-Button-secondary-ghost--focusnonenone
outlineOffset-Button-secondary-outlined--focusnonenone
outlineOffset-Button-secondary-solid--focusnonenone
outlineStyle-Button--focus$outlineStyle--focus$outlineStyle--focus
outlineStyle-Button-attention-ghost--focusnonenone
outlineStyle-Button-attention-outlined--focusnonenone
outlineStyle-Button-attention-solid--focusnonenone
outlineStyle-Button-primary-ghost--focusnonenone
outlineStyle-Button-primary-outlined--focusnonenone
outlineStyle-Button-primary-solid--focusnonenone
outlineStyle-Button-secondary-ghost--focusnonenone
outlineStyle-Button-secondary-outlined--focusnonenone
outlineStyle-Button-secondary-solid--focusnonenone
outlineWidth-Button--focus$outlineWidth--focus$outlineWidth--focus
outlineWidth-Button-attention-ghost--focusnonenone
outlineWidth-Button-attention-outlined--focusnonenone
outlineWidth-Button-attention-solid--focusnonenone
outlineWidth-Button-primary-ghost--focusnonenone
outlineWidth-Button-primary-outlined--focusnonenone
outlineWidth-Button-primary-solid--focusnonenone
outlineWidth-Button-secondary-ghost--focusnonenone
outlineWidth-Button-secondary-outlined--focusnonenone
outlineWidth-Button-secondary-solid--focusnonenone
padding-Buttonnonenone
padding-Button-lgnonenone
padding-Button-mdnonenone
padding-Button-smnonenone
padding-Button-xsnonenone
paddingBottom-Buttonnonenone
paddingBottom-Button-lgnonenone
paddingBottom-Button-mdnonenone
paddingBottom-Button-smnonenone
paddingBottom-Button-xsnonenone
paddingHorizontal-Buttonnonenone
paddingHorizontal-Button-lg$space-5$space-5
paddingHorizontal-Button-md$space-4$space-4
paddingHorizontal-Button-sm$space-4$space-4
paddingHorizontal-Button-xs$space-1$space-1
paddingLeft-Buttonnonenone
paddingLeft-Button-lgnonenone
paddingLeft-Button-mdnonenone
paddingLeft-Button-smnonenone
paddingLeft-Button-xsnonenone
paddingRight-Buttonnonenone
paddingRight-Button-lgnonenone
paddingRight-Button-mdnonenone
paddingRight-Button-smnonenone
paddingRight-Button-xsnonenone
paddingTop-Buttonnonenone
paddingTop-Button-lgnonenone
paddingTop-Button-mdnonenone
paddingTop-Button-smnonenone
paddingTop-Button-xsnonenone
paddingVertical-Buttonnonenone
paddingVertical-Button-lg$space-4$space-4
paddingVertical-Button-md$space-3$space-3
paddingVertical-Button-sm$space-2$space-2
paddingVertical-Button-xs$space-0_5$space-0_5
textColor-Button$color-surface-950$color-surface-950
textColor-Button--disabled$textColor--disabled$textColor--disabled
textColor-Button-attention-ghostnonenone
textColor-Button-attention-ghost--activenonenone
textColor-Button-attention-ghost--hovernonenone
textColor-Button-attention-outlinednonenone
textColor-Button-attention-outlined--activenonenone
textColor-Button-attention-outlined--hovernonenone
textColor-Button-attention-solidnonenone
textColor-Button-attention-solid--activenonenone
textColor-Button-attention-solid--hovernonenone
textColor-Button-primary-ghostnonenone
textColor-Button-primary-ghost--activenonenone
textColor-Button-primary-ghost--hovernonenone
textColor-Button-primary-outlined$color-primary-900$color-primary-900
textColor-Button-primary-outlined--active$color-primary-900$color-primary-900
textColor-Button-primary-outlined--hover$color-primary-950$color-primary-950
textColor-Button-primary-solidnonenone
textColor-Button-primary-solid--activenonenone
textColor-Button-primary-solid--hovernonenone
textColor-Button-secondary-ghostnonenone
textColor-Button-secondary-ghost--activenonenone
textColor-Button-secondary-ghost--hovernonenone
textColor-Button-secondary-outlinednonenone
textColor-Button-secondary-outlined--activenonenone
textColor-Button-secondary-outlined--hovernonenone
textColor-Button-secondary-solidnonenone
textColor-Button-secondary-solid--activenonenone
textColor-Button-secondary-solid--hovernonenone
textColor-Button-solid$const-color-surface-50$const-color-surface-50
width-Buttonfit-contentfit-content
This site is an XMLUI™ app.