Bootstrap 4 tutorial

Components (2): Buttons / Button group

Buttons

Examples

button.btn.btn-(primary|secondary|success|danger|warning|info|light|dark|link)

Various elements and attributes

Link
  • a.btn.btn-primary
    • Attribute href="#"
    • Attribute role="button"
    • Text Link
    • Jumps to the top on click
  • button.btn.btn-primary
    • Attribute type="submit"
    • Text Button
  • input.btn.btn-primary
    • Attribute type="button"
    • Attribute value="Input"
  • input.btn.btn-primary
    • Attribute type="submit"`
    • Attribute value="Submit"
  • input.btn.btn-primary
    • Attribute type="reset"`
    • Attribute value="Reset"

Outline buttons

button.btn.btn-outline-(primary|secondary|success|danger|warning|info|light|dark)

Sizes

(button|...).btn.btn-(lg|sm)

Large .btn-lg

Medium (default)

Small .btn-sm

Block level buttons

Add .btn-block

Active state

Setting .active displays buttons with always active (pressed) state.

Primary link Secondary link 

Disabled state

Example 1: Attribute disabled to button (disables both display and action)
Example 2: Class .disabled to button (can be still pressed)
Example 3: Class .disabled to a (disables both display and action)
Primary link Secondary link 

Button group

Basic example

Button toolbar

A button toolbar is used to gather button groups, input groups, form controls, etc.

Basic example of a button toolbar

Examples using input groups with alignment options

div.btn-toolbar

div.btn-toolbar.justify-content-between (⇒ Flex utilities )

Example using radios: (see Chexboxes and radios - Inline )

Radios are wrapped by div.form.form-inline and justified with .mx-auto

Sizing

Set .btn-group-(lg|sm)

div.btn-group.btn-group-lg

div.btn-group

div.btn-group.btn-group-sm

Using dropdowns (nesting)

Dropdowns can be used with nesting button groups.

Vertical variation

div.btn-group-vertical

Vertival example with dropdowns (see source for detail)