English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Bootstrap Buttons

This chapter will explain how to use Bootstrap buttons through examples. Any element with the class .btn elements will inherit the default appearance of rounded grey buttons. However, Bootstrap provides some options to define button styles, as shown in the following table:

The following styles can be used on <a>, <button>, or <input> elements:

ClassDescriptionExample
.btnAdd basic styles to the buttonTry it
.btn-defaultDefault/Standard buttonTry it
.btn-primaryOriginal button style (not operated)Try it
.btn-successIndicates a successful actionTry it
.btn-infoThis style can be used for buttons that pop up informationTry it
.btn-warningIndicates a button that requires careful operationTry it
.btn-dangerIndicates a button operation for a dangerous actionTry it
.btn-linkMake the button look like a link (still retains button behavior)Try it
.btn-lgMake a large buttonTry it
.btn-smMake a small buttonTry it
.btn-xsMake an extra small buttonTry it
.btn-blockBlock-level button (stretches to the parent element10(0% width)Try it
.activeButton is clickedTry it
.disabledDisabled buttonTry it

The following example demonstrates all the button classes mentioned above:

Online Example

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap Example - Button options/title>
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">  
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<!-- Standard button -->
<button type="button" class="btn btn-<button class="default">Default button</button>/button>
<!-- Provides additional visual effects to identify the original action in a group of buttons -->
<button type="button" class="btn btn-<button class="primary">Original button</button>/button>
<!-- Indicates a successful or positive action -->
<button type="button" class="btn btn-<button class="success">Success button</button>/button>
<!-- Contextual button for information warning messages -->
<button type="button" class="btn btn-<button class="info">Info button</button>/button>
<!-- Indicates an action that should be taken with caution -->
<button type="button" class="btn btn-<button class="warning">Warning button</button>/button>
<!-- Indicates a dangerous or potentially negative action -->
<button type="button" class="btn btn-<button class="danger">Danger button</button>/button>
<!-- It does not emphasize that it is a button, looking like a link, but still maintains the button behavior -->
<button type="button" class="btn btn-<button class="link">Link button</button>/button>
</body>
</html>
Test It Out ‹/›

The result is as shown below:

Button size

The following table lists the classes for obtaining buttons of various sizes:

ClassDescription
.btn-lgThis will make the button look larger.
.btn-smThis will make the button look smaller.
.btn-xsThis will make the button look particularly small.
.btn-blockThis will create a block-level button that spans the full width of the parent element.

The following example demonstrates all the button classes mentioned above:

Online Example

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap Example - Button size/title>
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">  
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<p>
   <button type="button" class="btn btn-primary btn-lg">Large original button</button>/button>
   <button type="button" class="btn btn-default btn-lg">Large button</button>/button>
</p>
<p>
   <button type="button" class="btn btn-primary">Default size original button</button>/button>
   <button type="button" class="btn btn-default">Default size button</button>/button>
</p>
<p>
   <button type="button" class="btn btn-primary btn-sm">Small original button</button>/button>
   <button type="button" class="btn btn-default btn-sm">Small button</button>/button>
</p>
<p>
   <button type="button" class="btn btn-primary btn-xs">Extra small original button</button>/button>
   <button type="button" class="btn btn-default btn-xs">Extra small button</button>/button>
</p>
<p>
   <button type="button" class="btn btn-primary btn-lg btn-<button class="block">Block-level original button</button>/button>
   <button type="button" class="btn btn-default btn-lg btn-<button class="block">Block-level button</button>/button>
</p>
</body>
</html>
Test It Out ‹/›

The result is as shown below:

Button state

Bootstrap provides classes for button states such as active and disabled, which will be explained in detail below.

Active state

When active, the button will appear as pressed (dark background, dark border, shadow).

The following table lists the classes that make the button element and anchor element active:

ElementClass
Button elementAdd .active class to display the button as active.
anchor elementAdd .active The class is used to display the button as active by targeting the <a> button.

The following example demonstrates this:

Online Example

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap Example - Button active state/title>
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">  
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<p>
	<button type="button" class="btn btn-default btn-lg ">default button</button>
   	<button type="button" class="btn btn-default btn-lg active">active button</button>
</p>
<p>
   	<button type="button" class="btn btn-primary btn-lg ">original button</button>
   	<button type="button" class="btn btn-primary btn-lg active">original active button</button>
</p>
</body>
</html>
Test It Out ‹/›

The result is as shown below:

Disabled state

When you disable a button, its color will fade 50%, and lose the gradient.

The following table lists the classes that make the button element and anchor element disabled:

ElementClass
Button elementAdd disabled Attribute to <button> button.
anchor elementAdd disabled class to <a> button.

The following example demonstrates this:

Online Example

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap Example - Button disabled state/title>
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">  
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<p>
   <button type="button" class="btn btn-default btn-lg">default button</button>
   <button type="button" class="btn btn-default btn-lg" disabled="disabled">disabled button</button>
</p>
<p>
   <button type="button" class="btn btn-primary btn-lg ">original button</button>
   <button type="button" class="btn btn-primary btn-lg" disabled="disabled">disabled original button</button>
</p>
<p>
   <a href="#" class="btn btn-default btn-lg" role="button">link</a>
   <a href="#" class="btn btn-default btn-lg disabled" role="button">disabled link</a>
</p>
<p>
   <a href="#" class="btn btn-primary btn-lg" role="button">original link</a>
   <a href="#" class="btn btn-primary btn-lg disabled" role="button">disabled original link</a>
</p>
</body>
</html>
Test It Out ‹/›

The result is as shown below:

Button tag

You can use the button class on <a>, <button>, or <input> elements. However, it is recommended to use the button class on the <button> element to avoid cross-browser inconsistencies.

The following example demonstrates this:

Online Example

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap Example - Button tag/title>
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">  
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<a class="btn btn-default" href="#" role="button">link</a>
<button class="btn btn-default" type="submit">button</button>
<input class="btn btn-default" type="button" value="input">
<input class="btn btn-default" type="submit" value="submit">
</body>
</html>
Test It Out ‹/›

The result is as shown below:

Button group

Use .btn directly in the div-group can create a button group:

Online Example

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap Example - Button (Button) plugin radio button/title>
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <h2>Button group/h2>
  <p>.btn-group class to create a button group:</p>
  <div class="btn-group">
    <button type="button" class="btn btn-primary">Apple</button>
    <button type="button" class="btn btn-primary">Samsung</button>
    <button type="button" class="btn btn-primary">Sony</button>
  </div>
</div>
</body>
</html>
Test It Out ‹/›

Use .btn-group-lg|sm|xs to control the size of the button group:

Online Example

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap Example - Button group/title>
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <h2>Button group - Set button size/h2>
  <p>Using .btn-group-* Class to control the size of buttons in the button group./p>
  <h2>Large button:</h2>
  <div class="btn-group btn-group-lg">
    <button type="button" class="btn btn-primary">Apple</button>
    <button type="button" class="btn btn-primary">Samsung</button>
    <button type="button" class="btn btn-primary">Sony</button>
  </div>
  <h2>Default size button:</h2>
  <div class="btn-group">
    <button type="button" class="btn btn-primary">Apple</button>
    <button type="button" class="btn btn-primary">Samsung</button>
    <button type="button" class="btn btn-primary">Sony</button>
  </div>
  <h2>Small button:</h2>
  <div class="btn-group btn-group-sm">
    <button type="button" class="btn btn-primary">Apple</button>
    <button type="button" class="btn btn-primary">Samsung</button>
    <button type="button" class="btn btn-primary">Sony</button>
  </div>
  <h2sm">/h2>
  <div class="btn-group btn-group->Super Small Button:<
    <button type="button" class="btn btn-primary">Apple</button>
    <button type="button" class="btn btn-primary">Samsung</button>
    <button type="button" class="btn btn-primary">Sony</button>
  </div>
</div>
</body>
</html>
Test It Out ‹/›

xs">-group-If you want to set vertical buttons, you can use .btn

Online Example

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap Example - Button</title>
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <h2vertical class to set:/h2>
  >Vertical Button Group<-group-<p>If you want to set vertical buttons, you can use .btn/p>
  <div class="btn-group-vertical class to set:<
    <button type="button" class="btn btn-primary">Apple</button>
    <button type="button" class="btn btn-primary">Samsung</button>
    <button type="button" class="btn btn-primary">Sony</button>
  </div>
</div>
</body>
</html>
Test It Out ‹/›

Vertical

Responsive Button Group-group-justified class to set a responsive button group.

The following example uses the a tag to display:

Online Example

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap Example - Button</title>
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <h2>Responsive Button Group</h2>
  <p>can be set through .btn-group-justified class to set a responsive button group.</p>
  <div class="btn-group btn-group-justified">
    <a href="#" class="btn btn-primary">Apple</a>
    <a href="#" class="btn btn-primary">Samsung</a>
    <a href="#" class="btn btn-primary">Sony</a>
  </div>
</div>
</body>
</html>
Test It Out ‹/›

Note: If it is a <button> element, you need to use .btn-group class to wrap:

Online Example

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap Example - Button</title>
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <h2>Responsive Button Group</h2>
  <div class="btn-group btn-group-justified">
    <div class="btn-group">
      <button type="button" class="btn btn-primary">Apple</button>
    </div>
    <div class="btn-group">
      <button type="button" class="btn btn-primary">Samsung</button>
    </div>
    <div class="btn-group">
      <button type="button" class="btn btn-primary">Sony</button>
    </div>
  </div>
</div>
</body>
</html>
Test It Out ‹/›

Nested Dropdown Button Group

Button groups can be nested to create dropdown menus, as shown in the following example:

Online Example

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap Example - Button</title>
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <h2>Inline Button Group</h2>
  <p>Create a dropdown menu with an inline button group: </p>
  <div class="btn-group">
    <button type="button" class="btn btn-primary">Apple</button>
    <button type="button" class="btn btn-primary">Samsung</button>
    <div class="btn-group">
      <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
      Sony <span class="caret"></span></button>
      <ul class="dropdown-menu" role="menu">
        <li><a href="#">Tablet</a></li>
        <li><a href="#">Smartphone</a></li>
      </ul>
    </div>
  </div>
</div>
</body>
</html>
Test It Out ‹/›

Split Button

Online Example

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap Example - Button</title>
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <h2>Separator Button</h2>
  <div class="btn-group">
    <button type="button" class="btn btn-primary">Sony</button>
    <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
      <span class="caret"></span>
    </button>
    <ul class="dropdown-menu" role="menu">
      <li><a href="#">Tablet</a></li>
      <li><a href="#">Smartphone</a></li>
    </ul>
  </div>
</div>
</body>
</html>
Test It Out ‹/›