Bootstrap 4 Pagination

Bootstrap 4 Pagination

Bootstrap pagination is used to show the existence of a series of web pages of the website. It allows navigation on multiple pages of a website.

In pagination, there is a block of connected links that are easily scalable. Pagination is created with the help of an HTML element List so that the users can see the number of available links.

Example

Almost every search engine uses pagination to show the number of search results on the web pages.

Bootstrap 4 Pagination

Steps for creating basic pagination

  • Use wrapping element <nav> for specifying navigation section.
  • Add unordered list <ul> element with .pagination class.
  • Add list item <li> element with .page-item class.
  • Add .page-link class within the <a> element to provide link
  • Add <a> element with .page-link class inside the <li> element.

Syntax

<nav>
     <ul class="pagination">
              <li class="page-item"><a class="page-link" href="#">Previous</a></li>
       </ul>
   </nav> 

Example

<!DOCTYPE html>
 <html lang="en">
 <head>
   <title>Bootstrap Pagination Example</title>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
 </head>
 <div class="container">
   <h2>Pagination</h2>
   <nav>                  
    <ul class="pagination"> 
     <li class="page-item"><a class="page-link" href="#">Previous</a></li>
     <li class="page-item"><a class="page-link" href="#">1</a></li>
     <li class="page-item"><a class="page-link" href="#">2</a></li>
     <li class="page-item"><a class="page-link" href="#">3</a></li>
     <li class="page-item"><a class="page-link" href="#">Next</a></li>
    </ul>
   </nav>
 </div>
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
 </body>
 </html> 

Output

Bootstrap 4 Pagination

Active and Disabled state - We can customize the pagination links as per the requirement. Pagination offers two classes for customizing links, these classes are .active class and .disable class.

The .disable class is used when we want to make our link un-clickable. This class uses CSS property “pointer-events: none;” to disable the functionality of links of <a> elements. Although, this property only disables mouse clicking. Users can still click on the disabled link with the help of keyboard keys. To make the link fully disabled we have to use the attribute  tabindex = “ -1” and some custom javascript.

The .active class is used to show or highlight the current page.

Example

<!DOCTYPE html>
 <html lang="en">
 <head>
   <title>Bootstrap Pagination Example</title>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
 </head>
 <div class="container">
   <h2>Active State</h2><br>
   <ul class="pagination">
     <li class="page-item"><a class="page-link" href="#">Previous</a></li>
     <li class="page-item active"><a class="page-link" href="#">1</a></li> 
     <li class="page-item"><a class="page-link" href="#">2</a></li>
     <li class="page-item"><a class="page-link" href="#">3</a></li>
     <li class="page-item"><a class="page-link" href="#">Next</a></li>
   </ul>
   <h2>Disabled State</h2><br>
   <ul class="pagination">
     <li class="page-item disabled"><a class="page-link" href="#">Previous</a></li> 
     <li class="page-item"><a class="page-link" href="#">1</a></li>
     <li class="page-item"><a class="page-link" href="#">2</a></li>
     <li class="page-item"><a class="page-link" href="#">3</a></li>
     <li class="page-item"><a class="page-link" href="#">Next</a></li>
   </ul>
 </div>
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
 </body>
 </html> 

Output

Bootstrap 4 Pagination

Pagination Sizing – Like other components of bootstrap 4, we can also customize the pagination size. There are two classes for resizing the pagination are given below.

  1. The .pagination-lg class is used to make the pagination size bigger than the default size.
  2. The .pagination-sm class is used to make the pagination size smaller than the default size.

Example

<!DOCTYPE html>
 <html lang="en">
 <head>
   <title>Bootstrap Pagination Example</title>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"> 
 </head>
 <div class="container">
   <h2>Pagination - Sizing</h2>
   <h5>Large</h5>
   <ul class="pagination pagination-lg">
     <li class="page-item"><a class="page-link" href="#">Previous</a></li>
     <li class="page-item"><a class="page-link" href="#">1</a></li> 
     <li class="page-item"><a class="page-link" href="#">2</a></li>
     <li class="page-item"><a class="page-link" href="#">3</a></li>
     <li class="page-item"><a class="page-link" href="#">Next</a></li>
   </ul>
   <h5>Default</h5>
   <ul class="pagination"> 
     <li class="page-item"><a class="page-link" href="#">Previous</a></li>
     <li class="page-item"><a class="page-link" href="#">1</a></li>
     <li class="page-item"><a class="page-link" href="#">2</a></li>
     <li class="page-item"><a class="page-link" href="#">3</a></li>
     <li class="page-item"><a class="page-link" href="#">Next</a></li>
   </ul>
   <h5>Small</h5> 
   <ul class="pagination pagination-sm">
     <li class="page-item"><a class="page-link" href="#">Previous</a></li>
     <li class="page-item"><a class="page-link" href="#">1</a></li>
     <li class="page-item"><a class="page-link" href="#">2</a></li>
     <li class="page-item"><a class="page-link" href="#">3</a></li>
     <li class="page-item"><a class="page-link" href="#">Next</a></li> 
   </ul>
 </div>
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
 </body>
 </html> 

Output

Bootstrap 4 Pagination

Pagination Alignment – The default alignment of the pagination component is left. By using some flexbox utilities we can also change the alignment of the pagination to the right or center.

  • Add the .justify-content-center class with the <ul> element to set the alignment of the pagination to the center.
  • Add the .justify-content-end class with the <ul> element to set the alignment of the pagination to the right.

Example

<!DOCTYPE html>
 <html lang="en">
 <head>
   <title>Bootstrap Pagination Example</title>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
 </head>
 <div class="container"> 
   <h2>Pagination-Alignment</h2>
   <h5>Default</h5>                 
   <ul class="pagination">
     <li class="page-item"><a class="page-link" href="javascript:void(0);">Previous</a></li>
     <li class="page-item"><a class="page-link" href="javascript:void(0);">1</a></li>
     <li class="page-item"><a class="page-link" href="javascript:void(0);">2</a></li>
     <li class="page-item"><a class="page-link" href="javascript:void(0);">Next</a></li> 
   </ul>
   <h5 style="text-align: center;">Center</h5>
   <ul class="pagination justify-content-center">
     <li class="page-item"><a class="page-link" href="javascript:void(0);">Previous</a></li>
     <li class="page-item"><a class="page-link" href="javascript:void(0);">1</a></li>
     <li class="page-item"><a class="page-link" href="javascript:void(0);">2</a></li>
     <li class="page-item"><a class="page-link" href="javascript:void(0);">Next</a></li>
   </ul> 
   <h5 style="text-align: right;">Right</h5>
   <ul class="pagination justify-content-end">
     <li class="page-item"><a class="page-link" href="javascript:void(0);">Previous</a></li>
     <li class="page-item"><a class="page-link" href="javascript:void(0);">1</a></li>
     <li class="page-item"><a class="page-link" href="javascript:void(0);">2</a></li>
     <li class="page-item"><a class="page-link" href="javascript:void(0);">Next</a></li>
   </ul> 
 </div>
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
 </body>
 </html> 

Output

Bootstrap 4 Pagination

Related Topics

Bootstrap Toast Example

What are toasts? Toasts are similar to notifications, and they are lightweight and act as push notifications from mobile and desktop operating systems. They’re built using flexbox in Bootstrap. They can...

4 minutes read.

Bootstrap 4 Scrollspy

Bootstrap 4 Scrollspy Bootstrap 4 offers a scrollspy component that is used to make the website more attractive and eye-catching. Basically, the scrollspy is used on the single-page website. The scrollspy highlights the nav...

5 minutes read.

Bootstrap 4 Grid System

Bootstrap 4 Grid System The bootstrap 4 grid system is used to create a responsive website layout. The bootstrap 4 offers a mobile-first flexbox grid system that allows you to divide...

4 minutes read.

Bootstrap 4 Dropdowns

Bootstrap Dropdowns Bootstrap 4 provides a dropdown component, which is a toggle and contextual layout, used to display a predefined list of links. It allows the user to select a value from the dropdown...

15 minutes read.

Bootstrap Time Picker Example

What is a Bootstrap Time picker? It is used to display the time in hours, minutes and seconds from a dropdown menu. In this section, we will create an example to...

4 minutes read.

Bootstrap 4 Layout

Containers Containers are the essential elements of the bootstrap layout. It is required when we are using a bootstrap grid system. Containers can also be nested, but most layouts do not need nested containers. Bootstrap has...

3 minutes read.

Bootstrap Buttons Groups

Bootstrap 4 Button Group Bootstrap 4 provides a feature button group that helps in creating a series of buttons together in a group. Basic Button Group  The .btn-group class is used within the <div> tag to create a...

6 minutes read.

Bootstrap 4 Tutorial

What is Bootstrap? Bootstrap is a CSS (Cascading Style Sheets) framework, which is used to develop a responsive website. It is an open-source and mobile-first front-end framework. It has design templates that are based...

4 minutes read.

Bootstrap Contact Us page

What is a “Contact Us” page? A “Contact Us” page is a web page available on the websites of various companies, organisations etc., for its users to contact the organisation or...

5 minutes read.

Bootstrap Datepicker

What is a Bootstrap Datepicker? It is used to display a calendar with the date, month, and time from a dropdown menu. We will use an example to see how the date...

5 minutes read.

Bootstrap 4 Media Objects

Bootstrap 4 Media Objects Bootstrap 4 offers a media object component that aligns the media objects and the content. The media object is used to create a repetitive and complex component...

7 minutes read.

Bootstrap 4 Grid System

Bootstrap 4 Grid Systems Bootstrap offers a responsive and mobile-first grid system with the help of which we can divide the screen of the web browser into 12 horizontal parts. It has predefined classes...

4 minutes read.

Bootstrap Tabs and Pills

Bootstrap Menus Bootstrap menu is used to create different types of menu. It can created horizontal with its .list-inlineclass. <div class="container">       <h3>Example of Bootstrap Menu</h3>       <ul class="list-inline">         <li><a href="#">Home</a></li>         <li><a href="#">About</a></li>         <li><a href="#">Contact</a></li>         <li><a href="#">services</a></li>       </ul>     </div> Try Now Bootstrap Tabs Bootstrap tabl is look like is menu but there is some difference....

4 minutes read.

Bootstrap Navigation bar

Navigation Bars In Bootstrap, We can create navigation bar like a navigation header. It is placed at the top of the page. We can collapse or extend it according to screen...

3 minutes read.

Bootstrap 4 Flex

Bootstrap 4 Flex Flex is a Bootstrap 4 component used to manage the layout, navigation bar, grid columns, sizing, alignment, and other components. The flexbox or flex utility is the replacement...

26 minutes read.

Bootstrap 4 Alerts

Bootstrap 4 Alerts Bootstrap 4 offers alerts that are used to provide feedback messages on the user’s actions. There is no boundation of text length in the alerts. Alerts can be created...

1 minute read.

Bootstrap List group

Bootstrap list group provides a group of a list of items. The most basic list is an unordered list. We can use <ul> element with .list-group class and <li> element with .lsit-group-item. Let us see...

3 minutes read.

Bootstrap With CSS

← Prev Next → ...

1 minute read.

Bootstrap 4 Margin classes

Bootstrap 4 contains a variety of brief, responsive margin and padding utility classes to change the appearance of an element. The Bootstrap 4 margin classes use for the outer spacing of...

8 minutes read.

Bootstrap Panels

A bootstrap panel is used to create bordered box with some padding around its content. It is created with the .panels classes, and .panel-body classes. There are following classes of the panel: Panel header Panel...

4 minutes read.