Bootstrap 4 buttons are used to perform interactive actions such as form submit, reset, redirecting to other pages, etc.
Steps to create bootstrap 4 buttons :
.btn
to the <button>
element base class.
<button>
,use contextual class(.btn-*
) to the <button>
element base class to provide background color of the button.
btn-primary
, btn-secondary
, btn-success
, btn-danger
, btn-warning
, btn-info
, btn-light
, btn-dark
,btn-link
.
General Syntax
<a href="#" class="btn btn-*">Link Button</a>
<button type="button" class="btn btn-*">Button</button>
Source Code
<div class="container mt-4">
<h2>Bootstrap Button</h2>
<div class="row">
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-primary">
Primary Button
</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-danger">
Danger Button
</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-success">
Success Button
</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-secondary">
Secondary Button
</button>
</div>
</div>
<!--/row-->
<p class="text-justify">
Button classes can also be applied to hyperlink and form input.
</p>
<div class="row">
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<input type="submit" class="btn btn-info" value="Submit Button" />
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<input type="button" class="btn btn-success" value="Input Button" />
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-danger">Info Button</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<a href="#" class="btn btn-secondary" role="button">Link Button</a>
</div>
</div><!--/row-->
</div><!--/container-->
Source Code: Output
Note:
Here, .btn
and .btn-*
is applied to the <button>
, <a>
, <input>
element base class to create button.
Follow the following steps to create larger and smaller button.
.btn-lg
to the
<button>
, <a>
& <input>
element base class.
.btn-sm
to the
<button>
, <a>
& <input>
element base class.
General Syntax
<button type="button" class="btn btn-* btn-lg">Large Button</button>
<button type="button" class="btn btn-* btn-sm">Small Button</button>
Source Code
<div class="container mt-4">
<h2>Large Button</h2>
<div class="row">
<div class="col-6 col-sm-6 mt-4">
<button type="button" class="btn btn-secondary btn-lg">Large Secondary button</button>
</div>
<div class="col-6 col-sm-6 mb-4 mt-4">
<button type="button" class="btn btn-primary btn-lg">Large Primary button</button>
</div>
</div>
<h4>Smaller Button</h4>
<br />
<div class="row mt-4">
<div class="col-6 col-sm-6 mt-4">
<button type="button" class="btn btn-secondary btn-sm">Small Secondary button</button>
</div>
<div class="col-6 col-sm-6 mt-4">
<button type="button" class="btn btn-primary btn-sm">Small Primary button</button>
</div>
</div>
</div>
Source Code: Output
Note: In the above example you are observing that for large button .btn-lg
is used while for small button .btn-sm
is used.
To create active and disabled button ,follow the given below statement.
.active
to the <button>
, <a>
,<input>
base class.
.disabled
to the <button>
, <a>
,<input>
base class.
General Syntax
<button type="button" class="btn btn-* active">Active Button</button>
<button type="button" class="btn btn-* disabled">Disabled Button</button>
Source Code
<div class="container mt-4">
<div class="col-12 col-sm-6">
<h2>Active Button</h2>
<button type="button" class="btn btn-primary active">Active Primary</button><br />
</div>
<div class="col-12 col-sm-6">
<h2>Disabled Button</h2>
<button type="button" class="btn btn-primary" disabled>Disabled Primary</button>
<a href="#" class="btn btn-primary disabled">Disabled Link</a>
</div>
</div>
Source Code: Output
Note:In the above example,.active
& .disabled
is assigned to
<button>
,<a>
& <input>
element base class.
Follow the given below statement to create boostrap outline button.
.btn
to the <button>
,<input>
,<a>
element base class.
.btn-*
to the <button>
,<input>
,<a>
element base class.
btn-primary
, btn-secondary
,btn-success
, btn-danger
,btn-warning
, btn-info
,btn-dark
, btn-light
, btn-link
.
General Syntax
<button type="button" class="btn btn-outline-* ">Outline Button</button>
<a href="#" class="btn btn-outline-* ">Outline Button</a>
Source Code
<div class="container mt-4">
<h2>Bootstrap Outline Button</h2>
<div class="row">
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-outline-warning">Warning</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-outline-danger">Danger</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-outline-success">Success</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-outline-secondary">Secondary</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-outline-primary">Primary</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-outline-info">Info</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-outline-dark">Dark</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-outline-light">Light</button>
</div>
</div>
</div><!--/container-->
Source Code: Output
Creating bootstrap outline button is very easy.You have to add .btn
class followed by one of the contextual class to <a>
,<button>
or <input>
element base class.
To create block level button that spans the entire width of the parent container,use .btn-block class to the <button>
,<a>
, <input>
element base class.
General Syntax
<button type="button" class="btn btn-block">Block Level Button</button>
<a href="#" class="btn btn-block">Block Level Button</a>
Source Code
<div class="container mt-4">
<h2>Bootstrap Block Level Button</h2>
<div class="row">
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-danger">Danger</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-success">Success</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-secondary">Secondary</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-primary">Primary</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-warning">Warning</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-info">Info</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-dark">Dark</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn--light">Light</button>
</div>
</div>
<h2>Bootstrap Outline Block Level Button</h2>
<div class="row mt-4">
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-outline-primary">Primary</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-outline-danger">Danger</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-outline-success">Success</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-outline-secondary">Secondary</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-outline-warning">Warning</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-outline-info">Info</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-outline-dark">Dark</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button type="button" class="btn btn-block btn-outline-light">Light</button>
</div>
</div><!--/row-->
</div><!--/container-->
Source Code: Output
Bootstrap block level element can take full available width and it is created by assigning .btn-block
to
the <button>
,<a>
or <input>
element base class.
Bootstrap provides class that indicate the loading state inside the web page.
Process of creating bootstrap 4 spinner buttons.
.spinner-border
& .spinner-border-*
to the child element(<span>
) of button
.
.spinner-border-*
is used to control the size of spinner. To create smaller spinner use .spinner-border-sm
& for larger spinner size use .spinner-border-lg
.
General Syntax
<button class="btn btn-*">
<span class="spinner-border spinner-border-sm"></span>
</button>
Source Code
<div class="container mt-4">
<h2>Bootstrap Spinner Button</h2>
<div class="row">
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button class="btn btn-primary">
<span class="spinner-border spinner-border-sm"></span>
</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button class="btn btn-primary" disabled>
<span class="spinner-border spinner-border-sm"></span>
Loading..
</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button class="btn btn-primary">
<span class="spinner-border spinner-border-sm"></span>
Loading..
</button>
</div>
<div class="col-6 col-sm-6 col-md-4 col-lg-3 mb-4">
<button class="btn btn-primary" disabled>
<span class="spinner-grow spinner-grow-sm"></span>
Loading..
</button>
</div>
</div>
</div>
Source Code: Output
Note:In the above example,.spinner-border
& .spinner-border
is assigned to the <button>
child element base class to create a loading spinner inside the project.