Pagination is used to enable navigation between pages in a website. The pagination used in Bootstrap has a large block of connected links that are hard to miss and are easily scalable.
Basic Pagination: The basic pagination can be specified using the following classes.
- The .pagination class is used to specify pagination on a list group.
- The .page-item class is used to specify each pagination item in the group.
- The .page-link class is used to specify the link in the pagination item.
Example:
HTML
<!DOCTYPE html>
< html >
< head >
< title >Bootstrap 4 | Pagination</ title >
< meta charset = "utf-8" >
< meta name = "viewport"
content = "width=device-width, initial-scale=1" >
< link rel = "stylesheet" href =
< script src =
</ script >
< script src =
</ script >
< script src =
</ script >
</ head >
< body >
< div class = "container" >
< h1 >Bootstrap 4 | Basic Pagination</ h1 >
< 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 >
</ div >
</ body >
</ html >
|
Output:
Disabled State: The pagination links could be styled to make them appear unclickable by using the .disabled class. This may be used for disabling the ‘Previous’ or ‘Next’ button. The .disabled class internally makes use of ‘pointer-events: none’ to make the link unclickable, however, as this specification is not always implemented, it is preferred to make it not possible to be navigated to by setting the ‘tabindex’ property to -1. This property controls whether an element can be navigated using the tab key.
Example:
HTML
<!DOCTYPE html>
< html >
< head >
< title >Bootstrap 4 | Pagination</ title >
< meta charset = "utf-8" >
< meta name = "viewport"
content = "width=device-width, initial-scale=1" >
< link rel = "stylesheet" href =
< script src =
</ script >
< script src =
</ script >
< script src =
</ script >
</ head >
< body >
< div class = "container" >
< h1 >Bootstrap 4 | Pagination Disabled State</ h1 >
< ul class = "pagination" >
< li class = "page-item disabled" >
< a class = "page-link" href = "#" tabindex = "-1" >
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 >
</ body >
</ html >
|
Output:
Active State: The pagination links could be styled to highlight them as the current active page by using the .active class on the pagination item.
Example:
HTML
<!DOCTYPE html>
< html >
< head >
< title >Bootstrap 4 | Pagination</ title >
< meta charset = "utf-8" >
< meta name = "viewport"
content = "width=device-width, initial-scale=1" >
< link rel = "stylesheet" href =
< script src =
</ script >
< script src =
</ script >
< script src =
</ script >
</ head >
< body >
< div class = "container" >
< h1 >Bootstrap 4 | Pagination Active State</ h1 >
< 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 active" >
< a class = "page-link" href = "#" >3</ a >
</ li >
< li class = "page-item" >
< a class = "page-link" href = "#" >Next</ a >
</ li >
</ ul >
</ div >
</ body >
</ html >
|
Output:
Sizing the pagination group: The pagination group could be made larger or smaller by using additional classes. There are 3 possible sizes of input groups.
- The .pagination-sm class is used for a smaller size.
- The .pagination-lg class is used for a larger size.
- The .pagination class is the default size.
Example:
HTML
<!DOCTYPE html>
< html >
< head >
< title >Bootstrap 4 | Pagination</ title >
< meta charset = "utf-8" >
< meta name = "viewport"
content = "width=device-width, initial-scale=1" >
< link rel = "stylesheet" href =
< script src =
</ script >
< script src =
</ script >
< script src =
</ script >
</ head >
< body >
< div class = "container" >
< h1 >Bootstrap 4 | Pagination Sizing</ h1 >
< b >Large Pagination</ b >
< 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 >
< b >Small Pagination</ b >
< 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 >
< b >Normal Pagination</ b >
< 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 >
</ div >
</ body >
</ html >
|
Output:
Alignment of the pagination group: The pagination group could be aligned to the right or center by using the flexbox utility classes.
- The .justify-content-center class is used to align the group to the center.
- The .justify-content-end class is used to align the group to the right.
Example:
HTML
<!DOCTYPE html>
< html >
< head >
< title >Bootstrap 4 | Pagination</ title >
< meta charset = "utf-8" >
< meta name = "viewport"
content = "width=device-width, initial-scale=1" >
< link rel = "stylesheet" href =
< script src =
</ script >
< script src =
</ script >
< script src =
</ script >
</ head >
< body >
< div class = "container" >
< h1 >Bootstrap 4 | Pagination Alignment</ h1 >
< b >Align to the center</ b >
< ul class = "pagination justify-content-center" >
< 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 >
< b >Align to the right</ b >
< ul class = "pagination justify-content-end" >
< 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 >
</ body >
</ html >
|
Output:
Last Updated :
23 Jan, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...