Lesson 23: Modals in Bootstrap 5

Modals in Bootstrap 5 are elements that display a popup window at the top of the current page. Below is how to create a dialog box or popup using Bootstrap 5.

Modals in Bootstrap 5 are elements that display a popup window at the top of the current page. Below is how to create a dialog box or popup using Bootstrap 5.

 

How to create a modal in Bootstrap 5

The following sample code shows how to create a basic modal:

   
   Modal body.   

For example:

 Bootstrap Example 

Modal template in Bootstrap 5

Click the button to open the modal.

   
   Modal body.   

 

Add effects

Use a class .fadeto add a fade-in effect when opening and closing a modal:

Sample code:

  

For example:

 Bootstrap Example 

Example of a modal blur effect.

Click the button to open the modal.

   
   Modal body.   

 

Modal size

Change the size of a modal by adding a class .modal-smfor small modals (maximum width 300px), a class .modal-lgfor large modals (maximum width 800px), or .modal-xlfor extra-large modals (maximum width 1140px). The default maximum width is 500px.

Add a size class to the element with the class   .modal-dialog:

Small modal:

For example:

 Bootstrap Example 

Small Modal

Click the button to open the modal.

   
   Modal body.   

 

Large modal:

 

For example:

 Bootstrap Example 

Large Modal

Click the button to open the modal.

   
   Modal body.   

Extremely large modal:

 

For example:

 Bootstrap Example 

Extra large Modal

Click the button to open this modal.

   
   Modal body.   

 

By default, modals are medium-sized (maximum width 500px).

Full-screen modal

If you want the modal to extend across the entire width and height of the page, use the class .modal-fullscreen:

Sample code:

 

For example:

 Bootstrap Example 

Full-screen modal

Click the button to open the modal in full screen.

   
   Modal body.   

Full-screen responsive modal

You can also control how the modal is fully displayed for each screen size, with the class .modal-fullscreen-*-*:

Class Describe
.modal-fullscreen-sm-down Full screen under 576px
.modal-fullscreen-md-down Full screen under 768px
.modal-fullscreen-lg-down Full screen under 992px
.modal-fullscreen-xl-down Full screen under 1200px
.modal-fullscreen-xxl-down Full screen under 1400px

Center of modal

Align modals vertically and horizontally on the same page using the class .modal-dialog-centered:

 

For example:

 Bootstrap Example 

For example, centering a modal vertically.

   
   Modal body.   

 

Modal in roll form

When there is a lot of content inside a modal, a scroll bar will be added to the page. The basic code is as follows:

 

For example:

 Bootstrap Example 

Modal in roll form

   
  

Some text to enable scrolling.

Some text to enable scrolling. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Some text to enable scrolling. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Some text to enable scrolling. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

   

However, you can scroll only within the modal, instead of the page itself, by adding .modal-dialog-scrollableit..modal-dialog:

 

For example:

 Bootstrap Example 

Rolled Modal

Click the button to open this modal.

   
  

Some text to enable scrolling.

Some text to enable scrolling. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Some text to enable scrolling. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Some text to enable scrolling. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

   

Above are the things you need to know about creating modals in Bootstrap 5. Hopefully, this article helps you better understand how to build a popup window for your website or application using Bootstrap 5 .

Related posts
Other Program articles
  • Lesson 22: Carousel in Bootstrap 5

    carousel trong bootstrap 5 là một plugin được dùng để duyệt các phần tử như slide, ảnh… dưới đây là cách dùng carousel trong bootstrap 5.
  • Lesson 20: Navs in Bootstrap 5

    navs trong bootstrap 5 là thành phần giúp bạn thiết kế cách điều hướng trên web, ứng dụng hoặc phần mềm. dưới đây là cách dùng navs trong bootstrap 5.
  • Lesson 19: How to use Collapse in Bootstrap 5

    collapse trong bootstrap 5 giúp bạn ẩn, hiện nội dung trên trang bằng một số class và plugin javascript. dưới đây là những điều bạn cần biết về collapse trong bootstrap 5.
  • Lesson 18: Creating a Dropdown Menu in Bootstrap 5

    dropdown hay tạo menu xổ xuống trong bootstrap 5 là một tính năng thú vị bạn không nên bỏ qua. dưới đây là cách dùng dropdown trong bootstrap 5.
  • Lesson 16: List Groups in Bootstrap 5

    list group hay nhóm danh sách trong bootstrap 5 là một thành phần linh hoạt và mạnh mẽ để hiển thị một chuỗi thông tin.hãy cùng quantrimang.com tìm hiểu cách dùng list-group trong bootstrap 5 nhé!
  • Lesson 15: Pagination in Bootstrap 5

    phần bài học bootstrap cơ bản này sẽ thảo luận về tính năng phân trang hay pagination. bootstrap 5 xử lý danh sách không theo đúng thứ tự giống như rất nhiều các nhân tố khác trên giao diện.
Category

System

Windows XP

Windows Server 2012

Windows 8

Windows 7

Windows 10

Wifi tips

Virus Removal - Spyware

Speed ​​up the computer

Server

Security solution

Mail Server

LAN - WAN

Ghost - Install Win

Fix computer error

Configure Router Switch

Computer wallpaper

Computer security

Mac OS X

Mac OS System software

Mac OS Security

Mac OS Office application

Mac OS Email Management

Mac OS Data - File

Mac hardware

Hardware

USB - Flash Drive

Speaker headset

Printer

PC hardware

Network equipment

Laptop hardware

Computer components

Advice Computer

Game

PC game

Online game

Mobile Game

Pokemon GO

information

Technology story

Technology comments

Quiz technology

New technology

British talent technology

Attack the network

Artificial intelligence

Technology

Smart watches

Raspberry Pi

Linux

Camera

Basic knowledge

Banking services

SEO tips

Science

Strange story

Space Science

Scientific invention

Science Story

Science photo

Science and technology

Medicine

Health Care

Fun science

Environment

Discover science

Discover nature

Archeology

Life

Travel Experience

Tips

Raise up child

Make up

Life skills

Home Care

Entertainment

DIY Handmade

Cuisine

Christmas

Application

Web Email

Website - Blog

Web browser

Support Download - Upload

Software conversion

Social Network

Simulator software

Online payment

Office information

Music Software

Map and Positioning

Installation - Uninstall

Graphic design

Free - Discount

Email reader

Edit video

Edit photo

Compress and Decompress

Chat, Text, Call

Archive - Share

Electric

Water heater

Washing machine

Television

Machine tool

Fridge

Fans

Air conditioning

Program

Unix and Linux

SQL Server

SQL

Python

Programming C

PHP

NodeJS

MongoDB

jQuery

JavaScript

HTTP

HTML

Git

Database

Data structure and algorithm

CSS and CSS3

C ++

C #

AngularJS

Mobile

Wallpapers and Ringtones

Tricks application

Take and process photos

Storage - Sync

Security and Virus Removal

Personalized

Online Social Network

Map

Manage and edit Video

Data

Chat - Call - Text

Browser and Add-on

Basic setup