Author: saqibkhan

  • Ratio

    This chapter discusses about the aspect ratio. In Bootstrap, aspect ratio is used to maintain the proportions of a responsive element, such as an image or video, relative to its parent container. It is specified using the .ratio class along with a modifier class that represents the desired aspect ratio.

    • To manage the aspect ratios of external content like <iframe>s, <embed>s, <video>s, and <object>s, use the ratio-* class.
    • The ratio helper can also be used on standard HTML child element, such as a <div> or <img>
    • The styles are applied from the parent .ratio class directly to the child element.
    • The * in the aspect ratio modifier class can be replaceable with:
      • ratio-21×9: creates a responsive element with a 21:9 aspect ratio
      • ratio-16×9: creates a responsive element with a 16:9 aspect ratio
      • ratio-4×3: creates a responsive element with a 4:3 aspect ratio
      • ratio-1×1: creates a responsive element with a 1:1 aspect ratio

    Here’s an example of how aspect ratios are used with the <iframe> element. Here we are using the 16×9 aspect ratio:https://www.tutorialspoint.com/bootstrap/examples/ratio_16x9.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Ratio</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h2 class="text-success text-center">
    
            Aspect Ratio 16x9
        &lt;/h2&gt;&lt;hr&gt;&lt;div class="ratio ratio-16x9"&gt;&lt;iframe src="https://www.youtube.com/embed/4PWVFBiFVVU"
                    title="YouTube video" allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Here's an example of how aspect ratios are used with the <iframe> element. Here we are using the 21x9 aspect ratio:https://www.tutorialspoint.com/bootstrap/examples/ratio_21x9.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Ratio</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h2 class="text-success text-center">
    
            Aspect Ratio - 21x9
        &lt;/h2&gt;&lt;hr&gt;&lt;div class="ratio ratio-21x9"&gt;&lt;iframe src="https://www.youtube.com/embed/4PWVFBiFVVU"
                    title="YouTube video" allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Custom Ratios

    In Bootstrap, a custom ratio allows you to define your own aspect ratio for a responsive element using a combination of CSS and JavaScript.

    This can be useful if you have a specific aspect ratio that is not covered by the built-in aspect ratio modifier classes. Following example demonstrates by setting --bs-aspect-ratio: 50% on the .ratio.

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Ratio</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h1 class="text-success text-center">
    
    	  Ratio
    </h1><hr><div class="text-center"><h2 class="text-success">Bootstrap 5 Custom ratios</h2></div><br><div class="ratio" style="--bs-aspect-ratio: 10%;"><div class="bg-success"><h1>success</h1></div></div><div class="ratio" style="--bs-aspect-ratio: 30%;"><div class="bg-secondary"><h1>secondary</h1></div></div></body></html>

  • Position

    This chapter discusses about configuration of position of an element.

    Bootstrap provides a set of helper classes to set the position of an element on a page. Some of the classes provided by Bootstrap are as follows:.

    • .fixed-top
    • .fixed-bottom
    • .sticky-top
    • .sticky-bottom

    Let us see examples for each set of classes.

    Fixed top

    The class .fixed-top sets the position of an element at the top of the viewport, from edge to edge.

    This is useful for creating navigation bars or headers that remain visible at the top of the screen even as the user scrolls down.https://www.tutorialspoint.com/bootstrap/examples/position_fixed_top.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html><head><title>Position - Fixed top</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body style="height:1500px"><nav class="navbar navbar-expand-lg text-bg-success navbar-dark fixed-top"><div class="container-fluid"><a class="navbar-brand" href="#">Use of .fixed-top class</a></div></nav><div class="container-fluid" style="margin-top:80px"><h4>Position fixed at top</h4><p>The class .fixed-top of Bootstrap sets the position of the element at top of the screen.</p><h1>Scroll down the page to see the position</h1></div></body></html>

    Fixed bottom

    The class .fixed-bottom sets the position of an element at the bottom of the viewport, from edge to edge.

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html><head><title>Position - Fixed bottom</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body style="height:1500px"><nav class="navbar navbar-expand-lg text-bg-primary navbar-dark fixed-bottom"><div class="container-fluid"><a class="navbar-brand" href="#">Use of .fixed-bottom class</a></div></nav><div class="container-fluid" style="margin-top:80px"><h4>Position fixed at bottom</h4><p>The class .fixed-bottom of Bootstrap sets the position of the element at the bottom of the page.</p><h1>Scroll down the page to see the position</h1></div></body></html>

    Sticky top

    The class .sticky-top is used to create a sticky element that remains at the top of the screen, from edge to edge, but only after you scroll past it.https://www.tutorialspoint.com/bootstrap/examples/position_sticky_top.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Position - Sticky top</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body style="height:1500px"><div class="container-fluid mt-3"><h3>Sticky Navbar</h3><p>The class <b>.sticky-top</b> is used to create a sticky element that remains at the top of the screen, from edge to edge, but only after you scroll past it.</p><p>Scroll down the page to see the effect.</p></div><nav class="navbar navbar-expand-lg bg-dark navbar-dark sticky-top"><div class="container-fluid"><a class="navbar-brand" href="#">Sticky top</a></div></nav><div class="container-fluid"><p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p></div></body></html>

    Responsive sticky top

    Responsive sticky top classes are used in web design to create a navigation menu or header that sticks to the top of the screen as the user scrolls down the page. This ensures that the navigation menu is always visible and easily accessible, even as the user moves further down the page.

    Some of the responsive sticky top classes provided by Bootstrap are as follows:

    • .sticky-sm-top sticks the position of element(s) to top on small sized viewports
    • .sticky-md-top sticks the position of element(s) to top on medium sized viewports
    • .sticky-lg-top sticks the position of element(s) to top on large sized viewports
    • .sticky-xl-top sticks the position of element(s) to top on extra large sized viewports
    • .sticky-xxl-top sticks the position of element(s) to top on extra extra large sized viewports

    Let us see an example:

    Note: Resize your browser to see the change.

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Position - Responsive Sticky top</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body style="height:1500px"><div class="container-fluid mt-3"><h3>Sticky Navbar</h3><p>The class <b>.sticky-lg-top</b> is a responsive class, used to create a sticky element that remains at the top of the screen, from edge to edge, but only after you scroll past it.</p><p>Scroll down the page to see the effect.</p></div><nav class="navbar navbar-expand-lg bg-dark navbar-dark sticky-lg-top"><div class="container-fluid"><a class="navbar-brand" href="#">Responsive Sticky top</a></div></nav><div class="container-fluid"><p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p></div></body></html>

    Sticky bottom

    The class .sticky-bottom is used to create a sticky element that remains at the bottom of the screen, from edge to edge, but only after you scroll past it.https://www.tutorialspoint.com/bootstrap/examples/position_sticky_bottom.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html><head><title>Position - sticky bottom</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body style=height:1000px class="d-flex flex-column"><!-- Navbar --><nav class="navbar navbar-expand-lg navbar-light bg-light"><div class="container"><a class="navbar-brand" href="#">Sticky Bottom Example</a></div></nav><!-- Content --><div class="container-fluid flex-grow-1"><h4>sticky bottom</h4><p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p><p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p><p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p><p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p></div><!-- Sticky Footer --><footer class="footer text-bg-info py-3 sticky-bottom"><div class="container"><span class="display-6 text-dark">Sticky bottom</span></div></footer></body></html>

    Responsive sticky bottom

    Some of the responsive sticky bottom classes provided by Bootstrap are as follows:

    • .sticky-sm-bottom sticks the position of element(s) to bottom on small sized viewports
    • .sticky-md-bottom sticks the position of element(s) to bottom on medium sized viewports
    • .sticky-lg-bottom sticks the position of element(s) to bottom on large sized viewports
    • .sticky-xl-bottom sticks the position of element(s) to bottom on extra large sized viewports
    • .sticky-xxl-bottom sticks the position of element(s) to bottom on extra extra large sized viewports

    Let us seen an example for a responsive sticky bottom class:

    Note: Resize your browser to see the change.https://www.tutorialspoint.com/bootstrap/examples/position_responsive_sticky_bottom.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html><head><title>Position - Responsive sticky bottom</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body style=height:1000px class="d-flex flex-column"><!-- Navbar --><nav class="navbar navbar-expand-lg navbar-light bg-light"><div class="container"><a class="navbar-brand" href="#">Responsive Sticky Bottom Example</a></div></nav><!-- Content --><div class="container-fluid flex-grow-1"><h4>Responsive sticky bottom</h4><p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p><p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p><p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p><p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p></div><!-- Sticky Footer --><footer class="footer text-bg-warning py-3 sticky-lg-bottom"><div class="container"><span class="display-6 text-dark">Sticky bottom</span></div></footer></body></html>

  • Icon link

    This chapter discusses about icon links, through which you can stylize the hyperlinks and other icons.

    In Bootstrap, an icon link is a link that is accompanied by an icon. The icon can be positioned either before or after the link text, and it is typically used to provide additional context or visual cues to the user.

    Icon links can be useful for adding visual interest and interactivity to your website or application, and they can be used in a variety of contexts such as navigation menus, buttons, or calls to action. The default link styles are modified by the icon link helper classes. They automatically align any pairing of icon and text and thus enhance their appearance on the page.

    Bootstrap icons along with any icon or image can be used in the icon links.

    • Icons that are added only with the purpose of decoration, should be hidden from assistive technologies using aria-hidden=”true”.
    • Icons that are added with purpose of conveying some meaning or information, provide an appropriate text alternative by adding role=”img” along with appropriate aria-label.
    https://www.tutorialspoint.com/bootstrap/examples/icon_link.php

    Example

    • To a regular <a> element, add .icon-link
    • Insert an icon on either side of the link text.
    • The .icon-link class will automatically size, place and color the icon.

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Icon Link</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script><link rel="apple-touch-icon" href="/docs/5.3/assets/img/favicons/apple-touch-icon.png" sizes="180x180"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon-32x32.png" sizes="32x32" type="image/png"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon-16x16.png" sizes="16x16" type="image/png"><link rel="manifest" href="/docs/5.3/assets/img/favicons/manifest.json"><link rel="mask-icon" href="/docs/5.3/assets/img/favicons/safari-pinned-tab.svg" color="#712cf9"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon.ico"><link rel="canonical" href="https://icons.getbootstrap.com/icons/search/"><script src="/assets/js/color-modes.js"></script><link rel="stylesheet" href="/assets/font/bootstrap-icons.min.css"><link rel="stylesheet" href="/assets/css/docs.css"></head><body><nav class="navbar navbar-inverse navbar-fixed-top text-bg-light" role="navigation"><div class="container"><div class="navbar-header"><h1 class="logo"><a title="tutorialspoint"><img alt="tutorialspoint" src="http://www.tutorialspoint.com/green/images/logo.png"
    
                            style="height: auto; width: auto; display: inline-block; top: 0px;"&gt;&lt;/a&gt;&lt;/h1&gt;&lt;/div&gt;&lt;/div&gt;&lt;/nav&gt;&lt;div class="container mt-2"&gt;&lt;svg xmlns="http://www.w3.org/2000/svg" style="display: none;"&gt;&lt;symbol id="box-seam" viewBox="0 0 16 16"&gt;&lt;path d="M8.186 1.113a.5.5 0 0 0-.372 0L1.846 3.5l2.404.961L10.404 2l-2.218-.887zm3.564 1.426L5.596 5 8 5.961 14.154 3.5l-2.404-.961zm3.25 1.7-6.5 2.6v7.922l6.5-2.6V4.24zM7.5 14.762V6.838L1 4.239v7.923l6.5 2.6zM7.443.184a1.5 1.5 0 0 1 1.114 0l7.129 2.852A.5.5 0 0 1 16 3.5v8.662a1 1 0 0 1-.629.928l-7.185 2.874a.5.5 0 0 1-.372 0L.63 13.09a1 1 0 0 1-.63-.928V3.5a.5.5 0 0 1 .314-.464L7.443.184z"&gt;&lt;/path&gt;&lt;/symbol&gt;&lt;/svg&gt;&lt;div class="feature col"&gt;&lt;h3 class="fs-2 text-danger"&gt;Icon link example&lt;/h3&gt;&lt;p&gt;Icon link feature of Bootstrap allows a user to add an icon along with an hyperlink and even the icon works as a link.&lt;/p&gt;&lt;a class="icon-link" href="#"&gt;&lt;svg class="bi" aria-hidden="true"&gt;&lt;use xlink:href="#box-seam"&gt;&lt;/use&gt;&lt;/svg&gt;
    			    	Box Icon with text link
                &lt;/a&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Let us see another example where icon is placed after the text in an icon link:https://www.tutorialspoint.com/bootstrap/examples/icon_after_link.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Icon Link</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script><link rel="apple-touch-icon" href="/docs/5.3/assets/img/favicons/apple-touch-icon.png" sizes="180x180"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon-32x32.png" sizes="32x32" type="image/png"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon-16x16.png" sizes="16x16" type="image/png"><link rel="manifest" href="/docs/5.3/assets/img/favicons/manifest.json"><link rel="mask-icon" href="/docs/5.3/assets/img/favicons/safari-pinned-tab.svg" color="#712cf9"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon.ico"><link rel="canonical" href="https://icons.getbootstrap.com/icons/search/"><script src="/assets/js/color-modes.js"></script><link rel="stylesheet" href="/assets/font/bootstrap-icons.min.css"><link rel="stylesheet" href="/assets/css/docs.css"></head><body><nav class="navbar navbar-inverse navbar-fixed-top text-bg-light" role="navigation"><div class="container"><div class="navbar-header"><h1 class="logo"><a title="tutorialspoint"><img alt="tutorialspoint" src="http://www.tutorialspoint.com/green/images/logo.png"
    
                            style="height: auto; width: auto; display: inline-block; top: 0px;"&gt;&lt;/a&gt;&lt;/h1&gt;&lt;/div&gt;&lt;/div&gt;&lt;/nav&gt;&lt;div class="container mt-2"&gt;&lt;svg xmlns="http://www.w3.org/2000/svg" style="display: none;"&gt;&lt;symbol id="airplane-fill" viewBox="0 0 16 16"&gt;&lt;path d="M6.428 1.151C6.708.591 7.213 0 8 0s1.292.592 1.572 1.151C9.861 1.73 10 2.431 10 3v3.691l5.17 2.585a1.5 1.5 0 0 1 .83 1.342V12a.5.5 0 0 1-.582.493l-5.507-.918-.375 2.253 1.318 1.318A.5.5 0 0 1 10.5 16h-5a.5.5 0 0 1-.354-.854l1.319-1.318-.376-2.253-5.507.918A.5.5 0 0 1 0 12v-1.382a1.5 1.5 0 0 1 .83-1.342L6 6.691V3c0-.568.14-1.271.428-1.849Z"&gt;&lt;/path&gt;&lt;/symbol&gt;&lt;/svg&gt;&lt;div class="feature col"&gt;&lt;h3 class="fs-2 text-success"&gt;Icon link example&lt;/h3&gt;&lt;p&gt;Icon link feature of Bootstrap allows a user to add an icon along with an hyperlink and even the icon works as a link. Here the icon is placed after the text in the icon link.&lt;/p&gt;&lt;a class="icon-link" href="#"&gt;Icon after the text
    		    	&lt;svg class="bi" aria-hidden="true"&gt;&lt;use xlink:href="#airplane-fill"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Style on hover

    In order to move the icon in an icon link to right, add the utility class .icon-link-hover to the class .icon-link.

    Let us see an example:https://www.tutorialspoint.com/bootstrap/examples/icon_link_hover.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Icon Link</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script><link rel="apple-touch-icon" href="/docs/5.3/assets/img/favicons/apple-touch-icon.png" sizes="180x180"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon-32x32.png" sizes="32x32" type="image/png"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon-16x16.png" sizes="16x16" type="image/png"><link rel="manifest" href="/docs/5.3/assets/img/favicons/manifest.json"><link rel="mask-icon" href="/docs/5.3/assets/img/favicons/safari-pinned-tab.svg" color="#712cf9"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon.ico"><link rel="canonical" href="https://icons.getbootstrap.com/icons/search/"><script src="/assets/js/color-modes.js"></script><link rel="stylesheet" href="/assets/font/bootstrap-icons.min.css"><link rel="stylesheet" href="/assets/css/docs.css"></head><body><nav class="navbar navbar-inverse navbar-fixed-top text-bg-light" role="navigation"><div class="container"><div class="navbar-header"><h1 class="logo"><a title="tutorialspoint"><img alt="tutorialspoint" src="http://www.tutorialspoint.com/green/images/logo.png"
    
                            style="height: auto; width: auto; display: inline-block; top: 0px;"&gt;&lt;/a&gt;&lt;/h1&gt;&lt;/div&gt;&lt;/div&gt;&lt;/nav&gt;&lt;div class="container mt-2"&gt;&lt;svg xmlns="http://www.w3.org/2000/svg" style="display: none;"&gt;&lt;symbol id="chevron-right" viewBox="0 0 16 16"&gt;&lt;path d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"&gt;&lt;/path&gt;&lt;/symbol&gt;&lt;/svg&gt;&lt;/div&gt;&lt;div class="feature col"&gt;&lt;h3 class="fs-2 text-success"&gt;Icon link example - hover&lt;/h3&gt;&lt;p&gt;Icon link feature of Bootstrap allows a user to add an icon along with an hyperlink and even the icon works as a link. Here the icon moves to the right on hovering.&lt;/p&gt;&lt;a class="icon-link icon-link-hover" href="#"&gt;&lt;strong&gt;Icon link hover&lt;/strong&gt;&lt;svg class="bi" aria-hidden="true"&gt;&lt;use xlink:href="#chevron-right"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Utilities

    In order to modify the underline color and offset of the icon link, use the custom link utilities provided by Bootstrap.

    • To add color to the iconlink, use the class link-* (where * can be any color-modes like danger, success, warning, info, etc.)
    • To add color to the line under the iconlink, use the class link-underline-* where * can be any color-modes like danger, success, warning, info, etc.)
    • To add opacity to the line under the iconlink, use the class link-underline-opacity-* (where * can be the percentage number such as 50, 55, 75, etc.)

    Let us see an example of modifying the icon link using the predefined utilities:https://www.tutorialspoint.com/bootstrap/examples/icon_link_utilities.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Icon Link</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script><link rel="apple-touch-icon" href="/docs/5.3/assets/img/favicons/apple-touch-icon.png" sizes="180x180"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon-32x32.png" sizes="32x32" type="image/png"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon-16x16.png" sizes="16x16" type="image/png"><link rel="manifest" href="/docs/5.3/assets/img/favicons/manifest.json"><link rel="mask-icon" href="/docs/5.3/assets/img/favicons/safari-pinned-tab.svg" color="#712cf9"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon.ico"><link rel="canonical" href="https://icons.getbootstrap.com/icons/search/"><script src="/assets/js/color-modes.js"></script><link rel="stylesheet" href="/assets/font/bootstrap-icons.min.css"><link rel="stylesheet" href="/assets/css/docs.css"></head><body><nav class="navbar navbar-inverse navbar-fixed-top text-bg-light" role="navigation"><div class="container"><div class="navbar-header"><h1 class="logo"><a title="tutorialspoint"><img alt="tutorialspoint" src="http://www.tutorialspoint.com/green/images/logo.png"
    
                                style="height: auto; width: auto; display: inline-block; top: 0px;"&gt;&lt;/a&gt;&lt;/h1&gt;&lt;/div&gt;&lt;/div&gt;&lt;/nav&gt;&lt;div class="container mt-2"&gt;&lt;svg xmlns="http://www.w3.org/2000/svg" style="display: none;"&gt;&lt;symbol id="airplane-fill" viewBox="0 0 16 16"&gt;&lt;path d="M6.428 1.151C6.708.591 7.213 0 8 0s1.292.592 1.572 1.151C9.861 1.73 10 2.431 10 3v3.691l5.17 2.585a1.5 1.5 0 0 1 .83 1.342V12a.5.5 0 0 1-.582.493l-5.507-.918-.375 2.253 1.318 1.318A.5.5 0 0 1 10.5 16h-5a.5.5 0 0 1-.354-.854l1.319-1.318-.376-2.253-5.507.918A.5.5 0 0 1 0 12v-1.382a1.5 1.5 0 0 1 .83-1.342L6 6.691V3c0-.568.14-1.271.428-1.849Z"&gt;&lt;/path&gt;&lt;/symbol&gt;&lt;/svg&gt;&lt;div class="feature col"&gt;&lt;h3 class="fs-2 text-success"&gt;Icon link customization&lt;/h3&gt;&lt;p&gt;Icon link feature of Bootstrap allows a user to add an icon along with an hyperlink and even the icon works as a link. Here the appearance of icon link is modified using the link utility classes.&lt;/p&gt;&lt;a class="icon-link icon-link-hover link-danger link-underline-success link-underline-opacity-55" href="#"&gt;&lt;strong&gt;Icon link utility&lt;/strong&gt;&lt;svg class="bi" aria-hidden="true"&gt;&lt;use xlink:href="#airplane-fill"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

  • Focus ring

    This chapter discusses about adding and modifying custom focus ring styles to various elements and components.

    In Bootstrap 5, the focus ring is a visual indicator that appears around an element when it receives focus. The focus ring is a circular outline that appears around the element, typically in a contrasting color, to indicate that the element is currently active and ready to receive input from the user.

    Bootstrap 5 provides a built-in focus ring that is applied to interactive elements such as buttons, links, and form controls by default.

    The default outline on :focus is removed by the helper class .focus-ring, thus replacing it with a box-shadow.

    Let’s see an example showing the usage of .focus-ring:https://www.tutorialspoint.com/bootstrap/examples/focus_ring.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Helper</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container-fluid flex-grow-1"><h4>Focus ring</h4><a href="#" class="d-inline-flex focus-ring py-1 px-2 text-bg-light border rounded-2">
    
          Example focus ring
        &lt;/a&gt;&lt;button class="button focus-ring py-1 px-2 text-bg-light border rounded-2"&gt;Click Me&lt;/button&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Customize focus ring

    Focus ring can be customized using the CSS variables, Sass variables, utilities, or custom styles.

    CSS variables

    In order to change the default appearance of a focus ring, modify the CSS variables --bs-focus-ring-*

    Let's see an example of customizing the CSS variables --bs-focus-ring-*:https://www.tutorialspoint.com/bootstrap/examples/focus_ring_CSS.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Helper</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container-fluid flex-grow-1"><h4>Focus ring - Customize CSS variable</h4><a href="#" class="d-inline-flex focus-ring py-1 px-2 text-decoration-none border rounded-2" style="--bs-focus-ring-color: rgba(var(--bs-danger-rgb), .25)">
    
          Red focus ring
        &lt;/a&gt;&lt;div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Let's see an example of customizing the CSS variables --bs-focus-ring-* in order to make the focus ring blurry:https://www.tutorialspoint.com/bootstrap/examples/focus_ring_CSS_blur.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Helper</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container-fluid flex-grow-1"><h4>Focus ring - Customize CSS variable</h4><a href="#" class="d-inline-flex focus-ring py-1 px-2 text-decoration-none border rounded-2" style="--bs-focus-ring-x: 20px; --bs-focus-ring-y: 20px; --bs-focus-ring-blur: 6px">
    
          Blur focus ring
        &lt;/a&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Utilities

    Bootstrap provides several utilities .focus-ring-* to modify the default settings.

    For example, modify the color of the focus ring with any of the theme colors.

    Let's see an example of customizing the utility .focus-ring-*:https://www.tutorialspoint.com/bootstrap/examples/focus_ring_utilities.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Helper</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container-fluid flex-grow-1"><h4>Focus ring - Customize utilities</h4><p><a href="#" class="d-inline-flex focus-ring focus-ring-success py-1 px-2">Success focus ring</a></p><p><a href="#" class="d-inline-flex focus-ring focus-ring-info py-1 px-2">Info focus ring</a></p><p><a href="#" class="d-inline-flex focus-ring focus-ring-warning py-1 px-2">Warning focus ring</a></p><p><a href="#" class="d-inline-flex focus-ring focus-ring-danger py-1 px-2">Danger focus ring</a></p><p><a href="#" class="d-inline-flex focus-ring focus-ring-secondary py-1 px-2">Secondary focus ring</a></p><p><a href="#" class="d-inline-flex focus-ring focus-ring-primary py-1 px-2">Primary focus ring</a></p><p><a href="#" class="d-inline-flex focus-ring focus-ring-dark py-1 px-2">Dark focus ring</a></p><p><a href="#" class="d-inline-flex focus-ring focus-ring-light py-1 px-2">Light focus ring</a></p></div></body></html>

  • Colored links

    This chapter discusses about the colored link feature of helper classes. The Bootstrap 5 colored links are used to add colors to the link elements.

    In order to make the links colored, use .link-* classes. These classes have :hover and :focus states, unlike the .text-* classes.

    In order to make the links legible, that have relatively light foreground color, use them on a dark background.

    .link-body-emphasis is the only colored link that is unique and high contrast link color. It comes with :hover and :focus styles.

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Colored link</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container p-2"><h4>Colored links</h4><br><p><a href="#" class="link-primary">Primary Color Link</a></p><p><a href="#" class="link-secondary">Secondary Color Link</a></p><p><a href="#" class="link-info">Info Color Link</a></p><p><a href="#" class="link-success">Success Color Link</a></p><p><a href="#" class="link-light bg-dark">Light Color Link on dark background</a></p><p><a href="#" class="link-dark">Dark Color Link</a></p><p><a href="#" class="link-warning">Warning Color Link</a></p><p><a href="#" class="link-danger">Danger Color Link</a></p><p><a href="#" class="link-body-emphasis">Custom Emphasis Link</a></p></div></body></html>

    Accessibility tip: Use of color just provides a visual indication, and this will not be helpful to users of assistive technologies like screen readers. Make sure that the meaning is clear from the content itself.

    Use alternative means to add clarity to the content using the .visually-hidden class.

    Link utilities

    Bootstrap provides a range of link utilities such as link opacity, link offset, underline color, underline opacity, and so on.

    Similarly colored links can also be modified using the link utilities. Let us see an example:https://www.tutorialspoint.com/bootstrap/examples/colored_link_utilities.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Colored link</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container p-2"><h4>Colored link utilities</h4><br><p><a href="#" class="link-offset-1 link-primary link-opacity-50 link-underline-warning link-underline-opacity-75">Primary Color Link</a></p><p><a href="#" class="link-offset-1 link-secondary link-opacity-50 link-underline-danger link-underline-opacity-50">Secondary Color Link</a></p><p><a href="#" class="link-offset-2 link-info link-opacity-25 link-underline-success link-underline-opacity-100">Info Color Link</a></p><p><a href="#" class="link-offset-2 link-success link-opacity-75 link-underline-danger link-underline-opacity-70">Success Color Link</a></p></div></body></html>

  • Color and background

    This chapter discusses about setting the background color with appropriate contrasting foreground or text color.

    These color and background helper classes combine the .text-* utilities and .bg-* utilities in one common class, namely .text-bg-*.

    In order to make the links legible, that have relatively light foreground color, use on a dark background.https://www.tutorialspoint.com/bootstrap/examples/color_background.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Helper</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h4>Color and background utilities</h4><br><div class="text-bg-primary p-3">Primary background with contrasting text color</div><div class="text-bg-secondary p-3">Secondary background with contrasting text color</div><div class="text-bg-success p-3">Success background with contrasting text color</div><div class="text-bg-danger p-3">Danger background with contrasting text color</div><div class="text-bg-warning p-3">Warning background with contrasting text color</div><div class="text-bg-info p-3">Info background with contrasting text color</div><div class="text-bg-light p-3">Light background with contrasting text color</div><div class="text-bg-dark p-3">Dark background with contrasting text color</div></body></html>

    Accessibility tip: Use of color to the progress bars just provides a visual indication, and this will not be helpful to users of assistive technologies like screen readers. Make sure that the meaning is clear from the content itself.

    Use alternative means to add clarity to the content using the .visually-hidden class.

    With components

    The color and background helper classes can be used in place of combined .text-* and .bg-* classes, such as on badges.

    In order to make the links legible, that have relatively light foreground color, use on a dark background.https://www.tutorialspoint.com/bootstrap/examples/color_background_badges.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Helper</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h4>Color and background utilities - badges</h4><br><span class="badge text-bg-success">Success</span><span class="badge text-bg-info">Info</span><span class="badge text-bg-warning">Warning</span></body></html>

    The color and background helper classes can be used in place of combined .text-* and .bg-* classes, such as on cards.

    In order to make the links legible, that have relatively light foreground color, use on a dark background.https://www.tutorialspoint.com/bootstrap/examples/color_background_cards.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Helper</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h4>Color and background utilities - cards</h4><br><div class="card text-bg-info mb-3" style="max-width: 18rem;"><div class="card-header fw-bold">Card Header</div><div class="card-body"><p class="card-text">Card showing the text and background color classes used together.</p></div></div><div class="card text-bg-warning mb-3" style="max-width: 18rem;"><div class="card-header fw-bold">Card Header</div><div class="card-body"><p class="card-text">Card showing the text and background color classes used together.</p>s
    
          &lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

  • Clearfix

    This chapter discusses the clearfix feature of helper classes. The clearfix feature in Bootstrap is used to clear floated elements within a container. When elements within a container are floated, the container’s height can sometimes be collapsed, causing issues with the layout.

    Here’s an example of how to use the .clearfix class in Bootstrap:https://www.tutorialspoint.com/bootstrap/examples/clearfix_create.php

    Example

    The example below shows the usage of clearfix. Without the clearfix, the wrapping div would not span around the buttons which would cause a broken layout.

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Clearfix</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h4>Clearfix example</h4><br><div class="bg-success clearfix"><button type="button" class="btn btn-secondary float-start">Button floated left</button><button type="button" class="btn btn-secondary float-end">Button floated right</button></div></body></html>

  • Validation

    This chapter will discuss about Bootstrap validation. Bootstrap 5 Validation enhances HTML5 form validation by offering useful feedback to users, supporting default browser behavior, custom styles, and JavaScript.

    The client-side custom validation styles and tooltips are inaccessible because they are not visible to assistive technology. It is recommended to use either the server-side option or the default browser validation technique, while we work on the solution.

    How form validation works in Bootstrap

    • The two pseudo-classes :invalid and :valid in CSS are used to provide HTML form validation. It applies to the <textarea><select>, and <input> elements.
    • Bootstrap applies the :invalid and :valid styles to the parent .was-validated class. Fields without a value show as invalid when the page loads. You choose when to activate them (usually after a form submission).
    • To restore the original appearance of the form after dynamic submissions using Ajax, the class .was-validated should be removed from the <form> to reset its appearance.
    • The pseudo-classes can be replaced with the .is-invalid and .is-valid classes for server-side validation as a fallback, without the need for a .was-validated parent class.
    • Currently, CSS limitations prevent us from directly applying styles to a <label> element that precedes a form control in the DOM without the help of custom JavaScript.
    • The constraint validation API, which consists of various JavaScript methods for validating form controls, is supported by all contemporary web browsers.
    • Use browser default styles or create custom feedback styles using HTML/CSS.
    • Use setCustomValidity method in JavaScript for unique validity messages.

    Let’s look at some examples of custom form validation styles, optional server-side classes and browser defaults.

    Custom styles

    • Add novalidate boolean attribute to the <form> to receive custom validation messages from Bootstrap.
    • Browser default feedback tooltips are disabled with above boolean attribute but JavaScript validation APIs still work. Submitting this form will trigger JavaScript to provide feedback, displaying :invalid and :valid styles on form controls.
    • Custom feedback styles improve feedback communication by adding colors, borders, focus styles, and backdrop icons. Backdrop icons for <select> are only available for .form-select, and not .form-control.

    This example demonstrates a Bootstrap form with validation features, to ensure that the required fields are filled out correctly before the form can be submitted.https://www.tutorialspoint.com/bootstrap/examples/custom_style.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Validation</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="row g-3 needs-validation" novalidate><div class="col-md-4"><label for="validationCustomName" class="form-label">Full Name</label><input type="text" class="form-control" id="validationCustomName" value="Jhon Miller" required><div class="invalid-feedback">
    
           Correct input!
       &lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-4"&gt;&lt;label for="validationCustomEmail" class="form-label"&gt;Email Id&lt;/label&gt;&lt;div class="input-group has-validation"&gt;&lt;input type="text" class="form-control" id="validationCustomEmail" aria-describedby="inputGroupPrepend" required&gt;&lt;span class="input-group-text" id="inputGroupPrepend"&gt;@tutorialspoint.com&lt;/span&gt;&lt;div class="invalid-feedback"&gt;
            Please enter correct mail id.
         &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-4"&gt;&lt;label for="validationCustomPhone" class="form-label"&gt;Mobile no&lt;/label&gt;&lt;input type="text" class="form-control" id="validationCustomPhone" required&gt;&lt;div class="invalid-feedback"&gt;
          please enter correct mobile no.
       &lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-6"&gt;&lt;label for="validationAddress" class="form-label"&gt;Address&lt;/label&gt;&lt;input type="text" class="form-control" id="validationAddress" value="XYZ - 123" required&gt;&lt;div class="valid-feedback"&gt;
          Correct input!
         &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-3"&gt;&lt;label for="validationCustom" class="form-label"&gt;Gender&lt;/label&gt;&lt;select class="form-select" id="validationCustom" required&gt;&lt;option selected disabled value=""&gt;Choose...&lt;/option&gt;&lt;option&gt;Male&lt;/option&gt;&lt;option&gt;Female&lt;/option&gt;&lt;option&gt;Others&lt;/option&gt;&lt;/select&gt;&lt;div class="invalid-feedback"&gt;
          Please select gender.
       &lt;/div&gt;&lt;/div&gt;&lt;div class="col-12"&gt;&lt;div class="form-check"&gt;&lt;input class="form-check-input" type="checkbox" value="" id="invalidCheck" required&gt;&lt;label class="form-check-label" for="invalidCheck"&gt;
            I have reviewed and agree to Terms of Services and Privacy Policy.
         &lt;/label&gt;&lt;div class="invalid-feedback"&gt;
            You must agree before submitting.
         &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-12"&gt;&lt;button class="btn btn-primary" type="submit"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;/form&gt;&lt;script&gt;
    (() =&gt; {
    'use strict'
    // Fetch all the forms we want to apply custom Bootstrap validation styles to
    const forms = document.querySelectorAll('.needs-validation')
    // Loop over them and prevent submission
    Array.from(forms).forEach(form =&gt; {
      form.addEventListener('submit', event =&gt; {
        if (!form.checkValidity()) {
          event.preventDefault()
          event.stopPropagation()
        }
        form.classList.add('was-validated')
      }, false)
    })
    })() </script></body></html>

    The following JavaScript code snippet disables form submissions if there are invalid fields. It achieves this by adding event listeners to the forms and preventing the default form submission behavior if the form is not valid.

        // Example JavaScript starter for disabling form submissions if there are invalid fields
    
    (() =&gt; {
      'use strict'
      // Fetch all the forms we want to apply custom Bootstrap validation styles to
      const forms = document.querySelectorAll('.needs-validation')
      // Loop over them and prevent submission
      Array.from(forms).forEach(form =&gt; {
        form.addEventListener('submit', event =&gt; {
          if (!form.checkValidity()) {
            event.preventDefault()
            event.stopPropagation()
          }
          form.classList.add('was-validated')
        }, false)
      })
    })()

    Browser defaults

    • We can also use browser default messages instead of custom validation message. Depending on your browser and OS, feedback style varies slightly.
    • Although CSS cannot be used to style these feedback styles, JavaScript can still be used to alter the feedback text.

    Try submitting the form in the following example to how default browser validation messages show up.https://www.tutorialspoint.com/bootstrap/examples/validation_browser_default.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Form - Validation</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="row g-3"><div class="col-md-4"><label for="validationDefaultName" class="form-label">Full Name</label><input type="text" class="form-control" id="validationDefaultName" value="name" required></div><div class="col-md-4"><label for="validationDefaultEmail" class="form-label">Email Id</label><div class="input-group"><input type="text" class="form-control" id="validationDefaultEmail" aria-describedby="inputGroupPrepend" required><span class="input-group-text" id="inputGroupPrepend">@tutorialspoint.com</span></div></div><div class="col-md-4"><label for="validationDefaultMob" class="form-label">Mobile No</label><input type="text" class="form-control" id="validationDefaultMob" value="" required></div><div class="col-md-6"><label for="validationDefaultAddress" class="form-label">Address</label><input type="text" class="form-control" id="validationDefaultAddress" required></div><div class="col-md-3"><label for="validationDefaultGender" class="form-label">Gender</label><select class="form-select" id="validationDefaultGender" required><option selected disabled value="">Choose...</option><option>Male</option><option>Female</option><option>Others</option></select></div><div class="form-check"><input class="form-check-input" type="checkbox" value="" id="invalidCheck2" required><label class="form-check-label" for="invalidCheck2">
    
              I have reviewed and agree to Terms of Services and Privacy Policy.
            &lt;/label&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-12"&gt;&lt;button class="btn btn-primary" type="submit"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Server-side

    • Client-side validation is recommended, but in case of server-side validation, use .is-invalid and .is-valid directives to indicate form field status. Also consider using .invalid-feedback with these classes.
    • Use aria-describedby attribute to link invalid feedback/error message to the form field in the case of invalid fields. (Allows more than one id to be referenced if field connects to other form text.)
    • Input groups need an additional .has-validation class for dealing with issues with border radius.
    https://www.tutorialspoint.com/bootstrap/examples/validation_server_side.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Validation</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="row g-3"><div class="col-md-4"><label for="validationServerName" class="form-label">Full name</label><input type="text" class="form-control is-valid" id="validationServerName" value="Mark" required><div class="valid-feedback">
    
          enter your name
        &lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-4"&gt;&lt;label for="validationServerEmail" class="form-label"&gt;Email Id&lt;/label&gt;&lt;div class="input-group has-validation"&gt;&lt;input type="text" class="form-control is-invalid" id="validationServerEmail"
            aria-describedby="inputGroupPrepend3 validationServerEmailFeedback" required&gt;&lt;span class="input-group-text" id="inputGroupPrepend3"&gt;@tutorialspoint.com&lt;/span&gt;&lt;div id="validationServerEmailFeedback" class="invalid-feedback"&gt;
            Please enter mail id.
          &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-4"&gt;&lt;label for="validationServerMob" class="form-label"&gt;Mobile no&lt;/label&gt;&lt;input type="text" class="form-control is-valid" id="validationServerMob" value="" required&gt;&lt;div class="valid-feedback"&gt;
          Please enter mobile no
        &lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-6"&gt;&lt;label for="validationServerAddress" class="form-label"&gt;Address&lt;/label&gt;&lt;input type="text" class="form-control is-invalid" id="validationServerAddress"
          aria-describedby="validationServerAddressFeedback" required&gt;&lt;div id="validationServerAddressFeedback" class="invalid-feedback"&gt;
          Please enter a valid Address.
        &lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-3"&gt;&lt;label for="validationServer04" class="form-label"&gt;Gender&lt;/label&gt;&lt;select class="form-select is-invalid" id="validationServer04" aria-describedby="validationServer04Feedback"
          required&gt;&lt;option selected disabled value=""&gt;Choose...&lt;/option&gt;&lt;option&gt;Male&lt;/option&gt;&lt;option&gt;Female&lt;/option&gt;&lt;option&gt;Others&lt;/option&gt;&lt;/select&gt;&lt;div id="validationServer04Feedback" class="invalid-feedback"&gt;
          Please select a valid gender.
        &lt;/div&gt;&lt;/div&gt;&lt;div class="col-12"&gt;&lt;div class="form-check"&gt;&lt;input class="form-check-input is-invalid" type="checkbox" value="" id="invalidCheckPolicy"
            aria-describedby="invalidCheckFeedback" required&gt;&lt;label class="form-check-label" for="invalidCheckPolicy"&gt;
            I have reviewed and agree to Terms of Services and Privacy Policy.
          &lt;/label&gt;&lt;div id="invalidCheckFeedback" class="invalid-feedback"&gt;
            You must agree before submitting.
          &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-12"&gt;&lt;button class="btn btn-primary" type="submit"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;;

    Supported elements

    The following form controls and components support validation styles:

    • <textarea> and <input> using the .form-control (allowing input groups to contain up to one .form-control).
    • <select> using .form-select
    • .form-check
    https://www.tutorialspoint.com/bootstrap/examples/validation_supported_elements.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Form - Validation</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="was-validated"><div class="mb-3"><label for="validationTextarea" class="form-label">Add comment</label><textarea class="form-control" id="validationTextarea" placeholder="Comment Here" required></textarea><div class="invalid-feedback">
    
            Add comment
          &lt;/div&gt;&lt;/div&gt;&lt;div class="form-check mb-3"&gt;&lt;input type="checkbox" class="form-check-input" id="validationFormCheck" required&gt;&lt;label class="form-check-label" for="validationFormCheck"&gt;Item One&lt;/label&gt;&lt;div class="invalid-feedback"&gt;Invalid Answer&lt;/div&gt;&lt;/div&gt;&lt;div class="form-check"&gt;&lt;input type="radio" class="form-check-input" id="validationFormRadio1" name="radio-stacked" required&gt;&lt;label class="form-check-label" for="validationFormRadio1"&gt;Item Two&lt;/label&gt;&lt;/div&gt;&lt;div class="form-check mb-3"&gt;&lt;input type="radio" class="form-check-input" id="validationFormRadio2" name="radio-stacked" required&gt;&lt;label class="form-check-label" for="validationFormRadio2"&gt;Item Three&lt;/label&gt;&lt;div class="invalid-feedback"&gt;Invalid Answer&lt;/div&gt;&lt;/div&gt;&lt;div class="mb-3"&gt;&lt;select class="form-select" required aria-label="select example"&gt;&lt;option value=""&gt;Gender&lt;/option&gt;&lt;option value="1"&gt;Male&lt;/option&gt;&lt;option value="2"&gt;Female&lt;/option&gt;&lt;option value="3"&gt;Others&lt;/option&gt;&lt;/select&gt;&lt;div class="invalid-feedback"&gt;Invalid selection&lt;/div&gt;&lt;/div&gt;&lt;div class="mb-3"&gt;&lt;input type="file" class="form-control" aria-label="file example" required&gt;&lt;div class="invalid-feedback"&gt;File size more than 256kb&lt;/div&gt;&lt;/div&gt;&lt;div class="mb-3"&gt;&lt;button class="btn btn-primary" type="submit" disabled&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Tooltips

    • To display validation feedback in a styled tooltip, swap the classes .{valid|invalid}-feedback for .{valid|invalid}-tooltip if the layout permits it.
    • To position the tooltip, make sure the parent has the property position: relative.
    https://www.tutorialspoint.com/bootstrap/examples/validation_Tooltips.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Validation</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="row g-3 needs-validation" novalidate><div class="col-md-4 position-relative"><label for="validationTooltipName" class="form-label">Full Name</label><input type="text" class="form-control" id="validationTooltipName" value="Jhon Miller" required><div class="valid-tooltip">
    
          Correct Input!
        &lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-4 position-relative"&gt;&lt;label for="validationTooltipEmail" class="form-label"&gt;Email Id&lt;/label&gt;&lt;div class="input-group has-validation"&gt;&lt;input type="text" class="form-control" id="validationTooltipEmail" aria-describedby="validationTooltipEmailPrepend" required&gt;&lt;span class="input-group-text" id="validationTooltipEmailPrepend"&gt;@tutorialspoint.com&lt;/span&gt;&lt;div class="invalid-tooltip"&gt;
           Please enter mail id.
          &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-4 position-relative"&gt;&lt;label for="validationTooltipMob" class="form-label"&gt;Mobile no&lt;/label&gt;&lt;input type="text" class="form-control" id="validationTooltipMob" required&gt;&lt;div class="invalid-tooltip"&gt;
          Please enter mobile no.
        &lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-6 position-relative"&gt;&lt;label for="validationTooltipAddress" class="form-label"&gt;Address&lt;/label&gt;&lt;input type="text" class="form-control" id="validationTooltipAddress" value="XYZ - 123" required&gt;&lt;div class="valid-tooltip"&gt;
         Correct Input!
        &lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-3 position-relative"&gt;&lt;label for="validationTooltip04" class="form-label"&gt;Gender&lt;/label&gt;&lt;select class="form-select" id="validationTooltip04" required&gt;&lt;option selected disabled value=""&gt;Choose...&lt;/option&gt;&lt;option&gt;Male&lt;/option&gt;&lt;option&gt;Female&lt;/option&gt;&lt;option&gt;Others&lt;/option&gt;&lt;/select&gt;&lt;div class="invalid-tooltip"&gt;
          Please select a valid gender.
        &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-12"&gt;&lt;button class="btn btn-primary" type="submit"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;/form&gt;&lt;script&gt;
      (() =&gt; {
    'use strict'
    // Fetch all the forms we want to apply custom Bootstrap validation styles to
    const forms = document.querySelectorAll('.needs-validation')
    // Loop over them and prevent submission
    Array.from(forms).forEach(form =&gt; {
      form.addEventListener('submit', event =&gt; {
        if (!form.checkValidity()) {
          event.preventDefault()
          event.stopPropagation()
        }
        form.classList.add('was-validated')
      }, false)
    })
    })()
    &lt;/script&gt;&lt;/body&gt;&lt;/html&gt;</pre>

  • Form Layout

    This chapter will discuss about Bootstrap form layout. Add structure to your forms with form layout options, from inline to horizontal to implementing custom grids.

    Form layout

    • Bootstrap gives no default styling for the <form> element, but there are a few capable browser highlights that are given by default. Each group of form fields must be inside a <form> element.
    • Ensure to be specify and include a type attribute for <button>s within a <form> as they default to type=”submit”.
    • Forms are stacked vertically by default. Bootstrap uses display: block and width: 100% to nearly all form controls. To change layout of each form, use additional classes.

    Utilities

    • To add some structure to forms should be use margin utilities. Use basic grouping of labels, controls, optional form text, and form validation messages.
    • For consistency, sticking to margin-bottom utilities and employing a single direction all through the form is recommended.
    https://www.tutorialspoint.com/bootstrap/examples/layout_utilities.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout </title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="mb-3"><label for="formGroupExampleInput" class="form-label">Username</label><input type="text" class="form-control" id="formGroupExampleInput" placeholder="Username"></div><div class="mb-3"><label for="formGroupExampleInput2" class="form-label">Password</label><input type="text" class="form-control" id="formGroupExampleInput2" placeholder="password"></div></body></html>

    Form grid

    Use grid classes for building the more complex forms. Form a grid for form layouts that require multiple columns, varied widths, and additional alignment options. You need to enable Sass variable using $enable-grid-classes.https://www.tutorialspoint.com/bootstrap/examples/layout_form_grid.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="row mt-2"><div class="col"><input type="text" class="form-control" placeholder="Username" aria-label="Username"></div><div class="col"><input type="text" class="form-control" placeholder="Password" aria-label="Password"></div></div></body></html>

    Gutters

    To control over the gutter width in the inline as block direction use the gutter modifier classes. By using $enable-grid-classes you can enable Sass variable.https://www.tutorialspoint.com/bootstrap/examples/layout_gutters.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="row g-3 mt-2"><div class="col"><input type="text" class="form-control" placeholder="Username" aria-label="Username"></div><div class="col"><input type="text" class="form-control" placeholder="Password" aria-label="Password"></div></div></body></html>

    Create more complex layouts using the grid system.

    https://www.tutorialspoint.com/bootstrap/examples/layout_complex_layout_using_grid_system.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="row g-3"><div class="col-md-6"><label for="inputFirst" class="form-label">First name</label><input type="text" class="form-control" id="inputFirst"></div><div class="col-md-6"><label for="inputLast" class="form-label">Last name</label><input type="text" class="form-control" id="inputLast"></div><div class="col-md-6"><label for="inputEmail" class="form-label">Email</label><input type="email" class="form-control" id="inputEmail"></div><div class="col-6"><label for="inputPassword" class="form-label">Password</label><input type="Password" class="form-control" id="inputPassword" placeholder="password"></div><div class="col-12"><label for="inputAddress" class="form-label">Address</label><input type="text" class="form-control" id="inputAddress" placeholder="Address"></div><div class="col-md-6"><label for="inputAdharno" class="form-label">Adharcard no</label><input type="text" class="form-control" id="inputAdharno"></div><div class="col-md-6"><label for="inputMobno" class="form-label">Mobile no</label><input type="text" class="form-control" id="inputMobno"></div><div class="col-12"><div class="form-check"><input class="form-check-input" type="checkbox" id="gridCheck"><label class="form-check-label" for="gridCheck">
    
              I agree to terms and conditions
            &lt;/label&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-12"&gt;&lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Horizontal form

    • Use the class .row to form groups to create horizontal forms with the grid. Use the class .col-*-* to define the width of the labels and controls.
    • To make a form vertically centered with their associated form controls, use the class .col-form-label to <label>.
    https://www.tutorialspoint.com/bootstrap/examples/layout_horizontal_form.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form><div class="row mb-3"><label for="inputEmail3" class="col-sm-2 col-form-label">Email</label><div class="col-sm-10"><input type="email" class="form-control" id="inputEmail3"></div></div><div class="row mb-3"><label for="inputPassword3" class="col-sm-2 col-form-label">Password</label><div class="col-sm-10"><input type="password" class="form-control" id="inputPassword3"></div></div><fieldset class="row mb-3"><legend class="col-form-label col-sm-2 pt-0">Language Known</legend><div class="col-sm-10"><div class="form-check"><input class="form-check-input" type="checkbox" name="gridCheck" id="gridCheck1" value="option1" checked><label class="form-check-label" for="gridCheck1">
    
                English
              &lt;/label&gt;&lt;/div&gt;&lt;div class="form-check"&gt;&lt;input class="form-check-input" type="checkbox"  name="gridCheck" id="gridCheck2" value="option2"&gt;&lt;label class="form-check-label" for="gridCheck2"&gt;
                Hindi
              &lt;/label&gt;&lt;/div&gt;&lt;div class="form-check"&gt;&lt;input class="form-check-input" type="checkbox"  name="gridCheck" id="gridCheck2" value="option2"&gt;&lt;label class="form-check-label" for="gridCheck2"&gt;
                  marathi
                &lt;/label&gt;&lt;/div&gt;&lt;div class="form-check disabled"&gt;&lt;input class="form-check-input"type="checkbox"  name="gridCheck" id="gridCheck3" value="option3" disabled&gt;&lt;label class="form-check-label" for="gridCheck3"&gt;
                Others
              &lt;/label&gt;&lt;/div&gt;&lt;/div&gt;&lt;/fieldset&gt;&lt;div class="row mb-3"&gt;&lt;div class="col-sm-10 offset-sm-2"&gt;&lt;div class="form-check"&gt;&lt;input class="form-check-input" type="radio" id="gridRadio1"&gt;&lt;label class="form-check-label" for="gridRadio1"&gt;
                Radio Button
              &lt;/label&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Horizontal form label sizing

    Use the classes .col-form-label-sm or .col-form-label-lg to your <label> or <legend> to follow the size of .form-control-sm and .form-control-lg respectively.https://www.tutorialspoint.com/bootstrap/examples/layout_horizontal_form_label_sizing.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="row mb-3"><label for="colFormSm" class="col-sm-2 col-form-label col-form-label-sm">Username</label><div class="col-sm-10"><input type="email" class="form-control form-control-sm" id="colFormSm" placeholder="Username"></div></div><div class="row mb-3"><label for="colFormLabel" class="col-sm-2 col-form-label">Password</label><div class="col-sm-10"><input type="text" class="form-control" id="colFormLabel" placeholder="Password"></div></div><div class="row"><label for="colFormLg" class="col-sm-2 col-form-label col-form-label-lg">Email</label><div class="col-sm-10"><input type="email" class="form-control form-control-lg" id="colFormLg" placeholder="email"></div></div></body></html>

    Column sizing

    As mentioned in the previous example, the grid system allows any number of .cols within a .row. Divide the available width evenly between them. You can also use a specific column class like .col-sm-7 to select a subset of columns to occupy more or less space while the remaining .col divides the rest evenly.https://www.tutorialspoint.com/bootstrap/examples/layout_column_sizing.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="row g-3"><div class="col-sm-6"><input type="text" class="form-control" placeholder="Email" aria-label="Email"></div><div class="col-sm-3"><input type="text" class="form-control" placeholder="Mobile no" aria-label="Mobile no"></div><div class="col-sm-2"><input type="text" class="form-control" placeholder="Age" aria-label="Age"></div></div></body></html>

    Auto-sizing

    In the below example, use flexbox utility to center the content vertically and change .col to .col-auto. So that the column only takes up as much space as it needs. In other words, the column size depends on the content.https://www.tutorialspoint.com/bootstrap/examples/layout_auto_sizing.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="row gy-2 gx-3 align-items-center"><div class="col-auto"><label class="visually-hidden" for="inputName">Name</label><input type="text" class="form-control" id="inputName" placeholder="Name"></div><div class="col-auto"><label class="visually-hidden" for="inputGroup"></label><div class="input-group"><input type="text" class="form-control" id="inputGroup" placeholder="Username"><div class="input-group-text">@gmail.com</div></div></div><div class="col-auto"><label class="visually-hidden" for="selectLanguage">Language</label><select class="form-select" id="selectLanguage"><option selected>Choose...</option><option value="1">English</option><option value="2">Hindi</option><option value="3">Marathi</option></select></div><div class="col-auto"><div class="form-check"><input class="form-check-input" type="checkbox" id="autoSizingCheck"><label class="form-check-label" for="autoSizingCheck">
    
            Remember me
          &lt;/label&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-auto"&gt;&lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Then you can remix again with size-specific column classes.https://www.tutorialspoint.com/bootstrap/examples/layout_autosizing_size_specific.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="row gx-3 gy-2 align-items-center mt-2"><div class="col-sm-3"><label class="visually-hidden" for="inputName">Name</label><input type="text" class="form-control" id="inputName" placeholder="Name"></div><div class="col-sm-3"><label class="visually-hidden" for="specificSizeInputGroupUsername">Username</label><div class="input-group"><input type="text" class="form-control" id="specificSizeInputGroupUsername" placeholder="Email"><div class="input-group-text">@gmail.com</div></div></div><div class="col-sm-3"><label class="visually-hidden" for="selectLanguage">Language</label><select class="form-select" id="selectLanguage"><option selected>Choose...</option><option value="1">English</option><option value="2">Hindi</option><option value="3">Marathi</option></select></div><div class="col-auto"><div class="form-check"><input class="form-check-input" type="checkbox" id="autoSizingCheck2"><label class="form-check-label" for="autoSizingCheck2">
    
            Remember me
          &lt;/label&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-auto"&gt;&lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Inline forms

    • To build responsive horizontal layouts use the classes .row-cols-*.
    • Use gutter modifier classes to have gutters in horizontal and vertical directions.
    • In narrow mobile viewports, .col-12 is useful for stacking form controls, etc.
    • To align the form elements at the middle and make the .form-check align properly use the class .align-items-center.
    https://www.tutorialspoint.com/bootstrap/examples/layout_inline_form.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="row row-cols-lg-auto g-3 align-items-center"><div class="col-12"><label class="visually-hidden" for="inlineFormInputGroupUsername">Username</label><div class="input-group"><input type="text" class="form-control" id="inlineFormInputGroupUsername" placeholder="Username"><div class="input-group-text">@gmail.com</div></div></div><div class="col-12"><label class="visually-hidden" for="selectLanguage">Language</label><select class="form-select" id="selectLanguage"><option selected>Choose...</option><option value="1">English</option><option value="2">Hindi</option><option value="3">Marathi</option></select></div><div class="col-12"><div class="form-check"><input class="form-check-input" type="checkbox" id="inlineFormCheck"><label class="form-check-label" for="inlineFormCheck">
    
            Remember me
          &lt;/label&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-12"&gt;&lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Print Page

  • Floating Labels

    This chapter will discuss about Bootstrap floating labels. Floating labels refer to form labels that float over the input fields.

    Basic example

    • To allow floating labels with Bootstrap’s textual form fields, include a pair of <input class=”form-control”> and <label> elements in .form-floating.
    • Each <input> must have a placeholder since the technique for CSS-only floating labels employs the :placeholder-shown pseudo-element. The <input> needs to be placed first to make use of a sibling selector like (~).
    https://www.tutorialspoint.com/bootstrap/examples/floating_labels_basic_example.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-floating mb-3 mt-2"><input type="text" class="form-control" id="floatingUsername" placeholder="[email protected]"><label for="floatingUsername">Username</label></div><div class="form-floating"><input type="password" class="form-control" id="floatingPassword" placeholder="Password"><label for="floatingPassword">Password</label></div></body></html>

    When a value is already assigned, <label> elements will automatically align their position to float over the input field.https://www.tutorialspoint.com/bootstrap/examples/floating_labels_floated_location.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="form-floating mt-2"><input type="email" class="form-control" id="floatingInputValue" placeholder="[email protected]" value="[email protected]"><label for="floatingInputValue">Username</label></form></body></html>

    By using form validation styles like is-invalid, you can provide visual feedback to users when they submit incorrect data.https://www.tutorialspoint.com/bootstrap/examples/floating_labels_floated_location.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="form-floating"><input type="text" class="form-control is-invalid" id="floatingInvalidInput" placeholder="Password" value="Password"><label for="floatingInvalidInput">Invalid Password</label></form></body></html>

    Textareas

    The height of <textarea> with the class .form-control is automatically set to have the same height as <input>.https://www.tutorialspoint.com/bootstrap/examples/floating_labels_textareas.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-floating"><textarea class="form-control" placeholder="Text Here" id="floatingTextarea"></textarea><label for="floatingTextarea">Text Here</label></div></body></html>

    Don’t use the rows attribute if you want to customize the height of your <textarea>. Instead, specify a height explicitly (either inline or using customized CSS). In the below example we have used inline styling.https://www.tutorialspoint.com/bootstrap/examples/floating_labels_customize_textareas.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-floating"><textarea class="form-control" placeholder="Add a comment" id="floatingTextarea" style="height: 100px"></textarea><label for="floatingTextarea">Add a comment</label></div></body></html>

    Selects

    • Floating labels are only accessible on .form-selects, in addition to .form-control.
    • The same concepts apply to them, except unlike <input>s, they always display the <label> in its floated state. Size-based and multiple selects are not supported.
    https://www.tutorialspoint.com/bootstrap/examples/floating_labels_selects.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-floating"><select class="form-select" id="floatingSelect" aria-label="Floating label select menu"><option selected>Language</option><option value="1">English</option><option value="2">Hindi</option><option value="3">Marathi</option></select><label for="floatingSelect">Others</label></div></body></html>

    Disabled

    Add the disabled boolean attribute on an input. This gives grayed-out appearance to an input, textarea, or select. It also removes pointer events, and prevents focusing.https://www.tutorialspoint.com/bootstrap/examples/floating_labels_disabled.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-floating mb-3"><input type="email" class="form-control" id="floatingInputDisabled" placeholder="name" disabled><label for="floatingInputDisabled">Name</label></div><div class="form-floating mb-3"><textarea class="form-control" placeholder="[email protected]" id="floatingEmailDisabled" disabled></textarea><label for="floatingEmailDisabled">Email Id</label></div><div class="form-floating mb-3"><textarea class="form-control" placeholder="Add a comment" id="floatingTextareaDisabled" style="height: 120px" disabled></textarea><label for="floatingTextareaDisabled">Add a comment</label></div><div class="form-floating"><select class="form-select" id="floatingSelectDisabled" aria-label="Floating label disabled select example" disabled><option selected>Select Language</option><option value="1">English</option><option value="2">Hindi</option><option value="3">Marathi</option></select><label for="floatingSelectDisabled">Others</label></div></body></html>

    Readonly plaintext

    When switching from an editable <input> to a plaintext value without changing the page layout, .form-control-plaintext can be useful.https://www.tutorialspoint.com/bootstrap/examples/floating_labels_readonly_plaintext.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-floating mb-3 mt-2"><input type="text" readonly class="form-control" id="floatingEmptyPlaintextInput" style="height: 80px" placeholder="Block the comment" value="Block the comment"><label for="floatingEmptyPlaintextInput">Block the comment</label></div><div class="form-floating mb-3"><input type="text" readonly class="form-control" id="floatingPlaintextInput" style="height: 80px" placeholder="Add a comment" value="Add a comment"><label for="floatingPlaintextInput">Add a comment</label></div></body></html>

    Input groups

    Similarly, floating labels support .input-group.https://www.tutorialspoint.com/bootstrap/examples/floating_labels_input_groups.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="input-group mb-3"><div class="form-floating"><input type="email" class="form-control" id="floatingInputGroup" placeholder="email"><label for="floatingInputGroup">Email Id</label></div><span class="input-group-text">[email protected]</span></div></body></html>

    The -feedback (it is a validation class to provide valuable feedback to users before submitting the form.) should be positioned outside of the .form-floating but inside of the .input-group when using .input-group and .form-floating along with form validation.https://www.tutorialspoint.com/bootstrap/examples/floating_labels_has_validation.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="input-group has-validation"><div class="form-floating is-invalid"><input type="text" class="form-control is-invalid" id="floatingInputGroup" placeholder="Password" required><label for="floatingInputGroup">Password</label></div><div class="invalid-feedback">
    
                Wrong Password
            &lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Layout

    • When using a grid system, the implementation of floating labels layout becomes beneficial as it enables the placement of form elements within column classes.
    • There is no pre-defined classes in bootstrap, so we must utilize form classes and position them according to our requirement.
    https://www.tutorialspoint.com/bootstrap/examples/floating_labels_layout.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="row g-2"><div class="col-md"><div class="form-floating"><input type="email" class="form-control" id="floatingGrid" placeholder="[email protected]" value="[email protected]"><label for="floatingGrid">Email Id</label></div></div><div class="col-md"><div class="form-floating"><select class="form-select" id="floatingSelectGrid"><option selected>Language</option><option value="1">English</option><option value="2">Hindi</option><option value="3">Marathi</option></select><label for="floatingSelectGrid">Others</label></div></div></div></html>