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 4 Content

Typography Typography is used for styling and formatting the content. It also helps in creating customized headings, sub-headings, lists, paragraphs, etc. Headings Bootstrap 4 offers HTML heading <h1> to <h6> that has bolder...

8 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 4 Collapse

Bootstrap 4 Collapse Collapse is a bootstrap component that is similar to the dropdown button. Collapse is used to hide or show the content such as paragraphs, sentences, etc.  When we click on a...

4 minutes read.

Bootstrap 4 Buttons

Bootstrap Buttons Bootstrap provides many custom button styles. These buttons are used in forms and dialog boxes for actions. Bootstrap offers various predefined classes for providing styles to buttons. There are many classes that are used...

7 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.

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.

Environment Setup

How to use Bootstrap? We can use bootstrap in our project either by downloading or by providing link of the library files. 1) Download Bootstrap files To download files, visit official site of bootstrap www.getbootstrap.com/download/ and...

1 minute read.

CakePHP Layouts & Elements

A layout includes a presentation code that can be wrapped out in your view. It means that what you want to see in your view should be well-positioned in layout. When you create...

9 minutes read.

Bootstrap First Example

1) Add HTML5 doctype Before starting the example of Bootstrap, we should know about the some basic rules of Bootstrap. We have to add HTML5 doctype with lang element and CSS properties. <!DOCTYPE html>   <html lang="en">     <head>       <meta charset="utf-8">      </head>   </html> 2) Bootstrap...

2 minutes read.

Bootstrap Glyphicons

Bootstrap Glyphicon is used to create different type of glyphicons It is used in the web project. It provides 260 Glyphicons from the Glyphivons Halflings set. There are various examples of...

1 minute read.

Bootstrap Images

Bootstrap 4 Images Bootstrap provides several classes for images to make them responsive and also helps to give some style to the images. Image Shapes Rounded Corners Bootstrap 4 offers .rounded class that makes the corners...

5 minutes read.

Dropdown & Dropup

Bootstrap Dropdowns The bootstrap dropdown menu is used to create a toggleable menu. It provides users to choose one value from a predefined list. Before creating dropdown menu, we have to know...

3 minutes read.

Bootstrap Badges and Labels

Bootstrap Badges Bootstrap Badges are numerical indicators. It is used to show that how many items are associated with a link.The .badge class is used to create of Bootstrap Badges. Let us see...

2 minutes read.

Bootstrap 4 navbar

A navigation navbar or navbar uses in every website to make it more user-friendly. Navigating through the website is easier, and the user can instantly search for the topic of...

8 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 4 Inputs

Bootstrap Inputs Bootstrap Form Inputs – Several pre-defined input types are available in HTML and Bootstrap. These input types help in styling the forms. When an input type is specified in the form, it means...

10 minutes read.

Bootstrap With CSS

← Prev Next → ...

1 minute read.

Bootstrap 4 Jumbotron

Bootstrap 4 Jumbotron Bootstrap offers Jumbotron, which is used to get more attention to specific content or information on the web page. It provides a gray background-color to the content to make that content...

2 minutes read.

Bootstrap Wells

In Bootstrap, well are used to add a rounded border around an element. It is default some padding and gray background color. It is like a container that displays the content....

1 minute read.

Bootstrap 4 Carousel

Bootstrap 4 Carousel Bootstrap 4 offers a carousel component, which is also known as a slider or slideshow. The carousel is used for the dynamic representation of content using images with...

7 minutes read.