Signup/Sign In

How to make smaller buttons using Bootstrap 5?

Bootstrap 5 offers several predefined classes for creating buttons. The buttons are used to perform any task on the webpage such as submitting a form, navigating to another webpage, etc.

There are also various pre-defined classes with the help of which we can customize our bootstrap 5 button and making smaller buttons is one of them.

Small button using Bootstrap 5

The buttons can be resized to larger and smaller buttons. To create smaller buttons add the .btn-sm class with the .btn class.

Bootstrap 5 offers a predefined class with the help of which we can create buttons of smaller size. To create smaller buttons add the .btn-sm class with the .btn class.

Example: Creating a small button

In the given example, we have created a button with a smaller size using the class .btn-sm.

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap </title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet"> 
  <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.min.js" integrity="sha384-Atwg2Pkwv9vp0ygtn1JAojH0nYbwNJLPhwyoVbhoPwBhjQPR5VtM2+xf0Uwh9KtT" crossorigin="anonymous"></script>
</head>
<body>
	<button  class="btn btn-primary  " >
	  Button
	</button>
	<button class="btn btn-primary btn-sm">
	  small button
	</button>
</body>
</html>

Output

Here is the output showing the default sized button and the small size button.

small size button

Example: Creating a small button in various color

Here we have another example where we have also added contextual color to the small buttons.

Conclusion

So we can easily create a smaller button using bootstrap 5. Use the .btn-sm class to create smaller buttons. The smaller buttons can be required when you need to use a small space in the webpage for placing the buttons. So, customize the button size accordingly.



About the author: