noora
Sign in

Button

Triggers an action, submits a form, or navigates to another location. A ghost button does the same for quiet utility controls.

Variants

Primary for the main action, secondary for supporting ones, destructive for actions that delete or revoke. Ghost buttons come in the same three, with no fill until hovered, for quiet utility controls, plus outline: secondary with a border.

<div>
  <.button label="Primary" variant="primary" />
  <.button label="Secondary" variant="secondary" />
  <.button label="Destructive" variant="destructive" />
</div>
<div>
  <.ghost_button label="Primary" variant="primary" />
  <.ghost_button label="Secondary" variant="secondary" />
  <.ghost_button label="Destructive" variant="destructive" />
  <.ghost_button label="Outline" variant="outline" />
</div>

Sizes

Large is the default. Use medium and small in dense layouts such as table rows and toolbars.

<.button label="Small" variant="secondary" size="small" />
<.button label="Medium" variant="secondary" size="medium" />
<.button label="Large" variant="secondary" size="large" />

All variants and sizes

Buttons and ghost buttons share their sizes, so they line up side by side.

<div :for={size <- ~w(small medium large)}>
  <.button
:for={variant <- ~w(primary secondary destructive)}
    label="Demo"
    variant={variant}
    size={size}
  />
  <.ghost_button
:for={variant <- ~w(primary secondary destructive outline)}
    label="Demo"
    variant={variant}
    size={size}
  />
</div>

Icons

An icon before or after the label reinforces direction or meaning.

<.button label="Back" variant="secondary">
  <:icon_left><.arrow_left /></:icon_left>
</.button>
<.button label="Continue" variant="secondary">
  <:icon_right><.arrow_right /></:icon_right>
</.button>
<.button label="Demo" variant="secondary">
  <:icon_left><.arrow_left /></:icon_left>
  <:icon_right><.arrow_right /></:icon_right>
</.button>
<.ghost_button label="Copy link" variant="secondary">
  <:icon_left><.copy /></:icon_left>
</.ghost_button>
<.ghost_button label="Share" variant="outline">
  <:icon_right><.external_link /></:icon_right>
</.ghost_button>

Icon only

Square buttons for compact controls whose icon is unambiguous, at every size. Always pass an aria-label that names the action and its target.

<.button
:for={size <- ~w(small medium large)}
  icon_only
  variant="secondary"
  size={size}
  aria-label="Next page"
>
  <.chevron_right />
</.button>
<.ghost_button
:for={size <- ~w(small medium large)}
  variant="secondary"
  size={size}
  aria-label="Copy command"
>
  <.copy />
</.ghost_button>

Disabled

Every variant looks the same when disabled.

<.button label="Primary" variant="primary" disabled />
<.button label="Secondary" variant="secondary" disabled />
<.button label="Destructive" variant="destructive" disabled />
<.ghost_button label="Ghost" variant="secondary" disabled />
<.ghost_button label="Outline" variant="outline" disabled />
<.ghost_button variant="secondary" aria-label="Copy command" disabled>
  <.copy />
</.ghost_button>

Loading

While an action runs, put a spinner where the icon goes and disable the button, so it can't be pressed twice.

<div>
  <.button :for={size <- ~w(small medium large)} label="Saving" size={size} disabled>
    <:icon_left><.spinner /></:icon_left>
  </.button>
</div>
<div>
  <.button label="Deploying" variant="secondary" disabled>
    <:icon_left><.spinner /></:icon_left>
  </.button>
  <.ghost_button label="Loading" variant="secondary" disabled>
    <:icon_left><.spinner /></:icon_left>
  </.ghost_button>
  <.ghost_button label="Syncing" variant="outline" disabled>
    <:icon_left><.spinner /></:icon_left>
  </.ghost_button>
  <.button icon_only variant="secondary" aria-label="Loading" disabled>
    <.spinner />
  </.button>
</div>

Guidelines

  • Use a button for actions that change something, such as saving, deploying, or deleting. Pass href , navigate , or patch when it changes the page instead; it renders a link that looks the same.
  • Use one primary button per surface, for the action people most likely want. Supporting actions use secondary .
  • Reserve destructive for actions that delete or revoke something, and confirm them in a modal when they can't be undone.
  • Use a ghost button for utility controls that should stay in the background, such as copying a command, closing a panel, or opening a menu.
  • Name the button after what happens: Create project, Invite member, Rotate token. Avoid bare verbs such as Submit or OK.
  • Disable a button only when the action is impossible right now, and explain why nearby or in a tooltip.
  • While an action runs, show a spinner in the icon slot and disable the button. Keep the label, or switch it to what's happening, such as Deploying.
  • Icon-only buttons need an aria-label that names the action and its target, such as Copy project URL. Don't add one to a button with a visible label; it replaces the label for screen readers.
  • A ghost button without label shows its inner block, usually one icon. With label , it shows the label with the icon_left and icon_right slots.

API reference

<.button>

Attribute Type Default Description
href
any
nil
Uses traditional browser navigation to the new location
icon_only
boolean
false
Uses the inner block as the entire button content. Provide an aria-label .
label
string
""
The text displayed in the button.
navigate
string
nil
Navigates to a LiveView
patch
string
nil
Patches the current LiveView
size
string
"large"
Controls the button dimensions and text size. "small""medium""large"
variant
string
"primary"
Controls the visual emphasis and semantic intent. "primary""secondary""destructive"

Also accepts global attributes, including phx-clickdisabledformtargetreltype.

Slot Description
:icon_left
Icon displayed on the left of an item
:icon_right
Icon displayed on the right of an item
inner_block
Inner block that renders HEEx content

<.ghost_button>

Attribute Type Default Description
href
any
nil
Uses traditional browser navigation to the new location
label
string
nil
The label of the button. When set, the inner block is replaced by the label and the icon slots.
navigate
string
nil
Navigates to a LiveView
patch
string
nil
Patches the current LiveView
size
string
"large"
Controls the button dimensions and text size. "small""medium""large"
variant
string
"primary"
Controls the visual emphasis and semantic intent. Outline is secondary with a border. "primary""secondary""destructive""outline"

Also accepts global attributes, including phx-clickdisabledtargetrel.

Slot Description
:icon_left
Icon displayed on the left of the label
:icon_right
Icon displayed on the right of the label
inner_block
Inner block that renders HEEx content when no label is set