Skip to main content
Components
Button Group
pnpm add @winkintel/bootstrap-svelte
GitHub

Button Group

Group a series of buttons together on a single line with the button group.


Experiment with the Button Group component by adjusting the props below:

Interactive Playground

Controls

3 buttons

Preview

Code

            
            <ButtonGroup>
  <Button colorVariant="primary">Button 1</Button>
  <Button colorVariant="primary">Button 2</Button>
  <Button colorVariant="primary">Button 3</Button>
</ButtonGroup>
        

Wrap a series of Button components with ButtonGroup component.

            
            <ButtonGroup>
    <Button colorVariant="primary">Left</Button>
    <Button colorVariant="primary">Middle</Button>
    <Button colorVariant="primary">Right</Button>
</ButtonGroup>
        

Mix and match button styles within a button group.

            
            <ButtonGroup>
    <Button colorVariant="danger">Left</Button>
    <Button colorVariant="secondary">Middle</Button>
    <Button colorVariant="success">Right</Button>
</ButtonGroup>
        

Use outlined styles for a different look.

            
            <ButtonGroup>
    <Button colorVariant="outline-primary">Left</Button>
    <Button colorVariant="outline-primary">Middle</Button>
    <Button colorVariant="outline-primary">Right</Button>
</ButtonGroup>
        

Use ButtonCheck to render Bootstrap toggle buttons powered by checkbox and radio inputs.

            
            <ButtonGroup ariaLabel="Toggle button group">
    <ButtonCheck colorVariant="outline-primary" id="toggle-check-1">Option 1</ButtonCheck>
    <ButtonCheck checked colorVariant="outline-primary" id="toggle-check-2">Option 2</ButtonCheck>
</ButtonGroup>

<ButtonGroup ariaLabel="Radio toggle button group">
    <ButtonCheck checked colorVariant="outline-secondary" id="toggle-radio-1" name="radio-toggles" type="radio">Active</ButtonCheck>
    <ButtonCheck colorVariant="outline-secondary" id="toggle-radio-2" name="radio-toggles" type="radio">Inactive</ButtonCheck>
</ButtonGroup>
        

Combine sets of button groups into button toolbars for more complex components.

            
            <ButtonToolbar ariaLabel="Toolbar with button groups">
    <ButtonGroup class="me-2">
        <Button colorVariant="primary">1</Button>
        <Button colorVariant="primary">2</Button>
        <Button colorVariant="primary">3</Button>
        <Button colorVariant="primary">4</Button>
    </ButtonGroup>
    <ButtonGroup class="me-2">
        <Button colorVariant="secondary">5</Button>
        <Button colorVariant="secondary">6</Button>
        <Button colorVariant="secondary">7</Button>
    </ButtonGroup>
    <ButtonGroup>
        <Button colorVariant="info">8</Button>
        <Button colorVariant="info">9</Button>
    </ButtonGroup>
</ButtonToolbar>
        

Instead of applying button sizing props to every button in a group, just set the size prop on the ButtonGroup.

            
            <ButtonGroup size="lg">
    <Button colorVariant="outline-primary">Left</Button>
    <Button colorVariant="outline-primary">Middle</Button>
    <Button colorVariant="outline-primary">Right</Button>
</ButtonGroup>

<ButtonGroup>
    <Button colorVariant="outline-primary">Left</Button>
    <Button colorVariant="outline-primary">Middle</Button>
    <Button colorVariant="outline-primary">Right</Button>
</ButtonGroup>

<ButtonGroup size="sm">
    <Button colorVariant="outline-primary">Left</Button>
    <Button colorVariant="outline-primary">Middle</Button>
    <Button colorVariant="outline-primary">Right</Button>
</ButtonGroup>
        

Place a ButtonGroup within another ButtonGroup when you want dropdown menus mixed with regular buttons.

            
            <ButtonGroup>
    <Button colorVariant="primary">1</Button>
    <Button colorVariant="primary">2</Button>
    <ButtonGroup>
        <Button colorVariant="primary" id="btnGroupDrop1" class="dropdown-toggle">Dropdown</Button>
        <!-- Dropdown menu would be implemented here -->
    </ButtonGroup>
</ButtonGroup>
        

Make a set of buttons appear vertically stacked rather than horizontally by adding the vertical prop.

            
            <ButtonGroup vertical>
    <Button colorVariant="primary">Button</Button>
    <Button colorVariant="primary">Button</Button>
    <Button colorVariant="primary">Button</Button>
    <Button colorVariant="primary">Button</Button>
</ButtonGroup>
        

ButtonGroup Props

NameTypeDefaultDescription
aria-labelstring'Button group [id]'ARIA label for the button group
classstringundefinedAdditional CSS classes to apply to the component.
elementRefHTMLElement | nullnullReference to the DOM element
idstringUnique identifier for the button. If not specified, it will be auto-generated.
isVerticalbooleanfalseMakes the button group stack vertically
sizestring-Sets the size for all buttons in the group. Values: 'sm', 'lg'

ButtonCheck Props

NameTypeDefaultDescription
autocompletestring'off'Autocomplete behavior for the underlying input.
checkedbooleanfalseBindable checked state for checkbox inputs.
classstringundefinedAdditional CSS classes applied to the input element.
colorVariantButtonColorVariantundefinedBootstrap button variant for the label (for example, primary or outline-primary).
elementRefHTMLInputElement | nullnullReference to the input element.
groupstring | unknown[]undefinedBindable group value for grouped radio or checkbox inputs.
idstring'btn-check-[id]'Input ID used by the label for attribute.
labelClassstringundefinedAdditional CSS classes applied to the label element.
labelElementRefHTMLLabelElement | nullnullReference to the label element.
type'checkbox' | 'radio''checkbox'Input type for the toggle button.

ButtonToolbar Props

NameTypeDefaultDescription
aria-labelstring'Button toolbar [id]'ARIA label for the button group
classstringundefinedAdditional CSS classes to apply to the component.
elementRefHTMLElement | nullnullReference to the DOM element
idstringUnique identifier for the button. If not specified, it will be auto-generated.

CSS Classes

The component applies Bootstrap's button group classes:

  • btn-group - Applied when isVertical prop is false
  • btn-group-vertical - Applied when isVertical prop is true
  • btn-group-lg - Applied when size="lg"
  • btn-group-sm - Applied when size="sm"
  • btn-check - Applied to the ButtonCheck input element.
  • btn - Applied to the ButtonCheck label element.
  • btn-[variant] - Applied to ButtonCheck labels when colorVariant is set.
  • btn-toolbar - Applied when using the ButtonToolbar component.