Bootstrap – Forms ”; Previous Next This chapter will discuss about Bootstrap forms. A form facilitate user to enter data such as name, email address, password etc, which can then be sent to server for processing. Bootstrap provides classes to create a variety of forms with varied styles, layouts and custom components. Basic form Form controls in Bootstrap extend Rebooted form styles with classes. For consistent rendering across browsers and devices with customized display, use these classes . To use more recent input controls, such as email verification, number selection, and other features, be sure to use an appropriate type attribute on all inputs (e.g., email for email addresses or the number for numerical data). Following example demonstrates Boostrap”s basic form. Example You can edit and try running this code using Edit & Run option. <!DOCTYPE html> <html lang=”en”> <head> <title>Bootstrap – Form</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=”mb-3″> <label for=” sampleInputEmail” class=”form-label”>Username</label> <input type=”email” class=”form-control” id=” sampleInputEmail” aria-describedby=”emailHelp”> </div> <div class=”mb-3″> <label for=”sampleInputPassword” class=”form-label”>Password</label> <input type=”password” class=”form-control” id=”sampleInputPassword”> </div> <div class=”mb-3 form-check”> <input type=”checkbox” class=”form-check-input” id=”sampleCheck”> <label class=”form-check-label” for=”sampleCheck”>Remember me</label> </div> <button type=”submit” class=”btn btn-primary”>Log in</button> </form> </body> </html> Disabled forms To prevent user interactions and make an input appear lighter, use the disabled boolean attribute. To disable all the controls in a <fieldset>, add the disabled attribute. The <input>, <select>, and <button> elements of native form controls contained within a fieldset <disabled> are all treated by browsers as disabled, preventing keyboard and mouse interactions with them. If form has custom button-like elements, such as <a class=”btn btn-*”>…</a>, they have pointer-events: none set, which means they are still focusable and keyboard-operable. To prevent them from receiving focus use tabindex=”-1″ and use aria-disabled=”disabled” to signal their state to assistive technologies. Example You can edit and try running this code using Edit & Run option. <!DOCTYPE html> <html lang=”en”> <head> <title>Bootstrap – Form</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> <fieldset disabled> <div class=”mb-3″> <label for=”disabledEmailInput” class=”form-label”>Disabled Input</label> <input type=”text” id=”disabledEmailInput” class=”form-control” placeholder=”Email Id”> </div> <div class=”mb-3″> <label for=”disabledPasswordInput” class=”form-label”>Disabled Input</label> <select id=”disabledPasswordInput” class=”form-select”> <option>Password</option> </select> </div> <div class=”mb-3″> <div class=”form-check”> <input class=”form-check-input” type=”checkbox” id=”disabledcheckbox” disabled> <label class=”form-check-label” for=”disabledcheckbox”> Disabled Check Box </label> </div> </div> <button type=”submit” class=”btn btn-primary”>Disabled Button</button> </fieldset> </form> </body> </html> Accessibility Every form control has an appropriate accessible name for assistive technology users. Using label elements or descriptive text within <button>…</button> is the simplest method to achieve this. When a visible “label” or appropriate text content is not provided then use other approaches for accessible names, for example: Use the class .visually-hidden to hide the <label> elements. Use aria-labelledby to pointing an existing element that behaves as a <label>. Including a title attribute. Use aria-label to set the element accessible name. When none of these are available, for accessible name assistive technology use placeholder attribute as a fallback on <input> and <textarea> elements. Using visually hidden content will help assistive technology users, however certain users may still have issues with a lack of visible label text. Print Page Previous Next Advertisements ”;
Category: bootstrap
Bootstrap – Color and background ”; Previous Next 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. 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. 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. 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 </div> </div> </body> </html> Print Page Previous Next Advertisements ”;
Bootstrap – Spacing
Bootstrap – Spacing ”; Previous Next This chapter discusses about the utility classes provided by Bootstrap for spacing. Bootstrap provides predefined range of responsive margin, padding and gap utility classes that can be used to modify the appearance of an element. These utility classes work for all types of breakpoints, such as: breakpoint size xs sm >=576px md >=768px lg >=992px xl >=1200px xxl >=1400px The naming format of these classes is as follows: breakpoint naming format xs {property}{sides}-{size} sm, md, lg, xl, xxl {property}{sides}-{breakpoint}-{size} where property can be one of the following: property value m margin p padding where sides can be one of the following: side value t margin-top/padding-top b margin-bottom/padding-bottom s margin-left/padding-left e margin-right/padding-right x margin-left and margin-right or padding-left and padding-right y margin-top and margin-bottom or padding-top and padding-bottom blank margin and padding on all four sides where size can be one of the following: size value 0 margin/padding – 0 1 margin/padding – 0.25rem 2 margin/padding – 0.5rem 3 margin/padding – 1rem 4 margin/padding – 1.5rem 5 margin/padding – 3rem auto margin – auto Note: More sizes can be added by adding entries to the $spacers Sass map variable. Let us see an example for margin utilities: Example You can edit and try running this code using the Edit & Run option. <!DOCTYPE html> <html> <head> <title>Bootstrap – Spacing</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 mt-3″> <h4 class=”display-4″>Spacing margin utilities</h4> <p><u>Set the spacing (margin) of an element with the {property}{sides}-{breakpoint}-{size} classes.</u></p> <div class=”mt-4 bg-info”>Only top margin (1.5rem)</div> <div class=”mb-5 bg-light”>Only bottom margin (1rem)</div> <div class=”ms-5 bg-warning”>Only left margin (3rem)</div> <div class=”me-5 bg-warning”>Only right margin (3rem)</div> <div class=”mx-5 text-bg-secondary”>Both left and right margins (3rem)</div> <div class=”my-5 bg-primary”>Both top and bottom margins (3rem)</div> </div> </body> </html> Let us see an example for padding utilities: Example You can edit and try running this code using the Edit & Run option. <!DOCTYPE html> <html> <head> <title>Bootstrap – Spacing</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 mt-3″> <h4 class=”display-4″>Spacing padding utilities</h4> <p><u>Set the spacing (padding) of an element with the {property){sides}-{breakpoint}-{size} classes.</u></p> <div class=”pt-4 bg-info”>Only top padding (1.5rem)</div> <div class=”pb-5 text-bg-success”>Only bottom padding (1rem)</div> <div class=”ps-5 bg-warning”>Only left padding (3rem)</div> <div class=”pe-5 text-bg-danger”>Only right padding (3rem)</div> <div class=”px-5 text-bg-secondary”>Both left and right padding (3rem)</div> <div class=”py-5 text-bg-primary”>Both top and bottom padding (3rem)</div> </div> </body> </html> Horizontal centering For horizontal centering fixed-width block level content, Bootstrap provides .mx-auto class. Let us see an example: Example You can edit and try running this code using the Edit & Run option. <!DOCTYPE html> <html> <head> <title>Bootstrap – Spacing</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 mt-3″> <h4 class=”display-5″>Horizontal centering</h4><br> <div class=”mx-auto p-2 text-bg-success” style=”width: 200px;”> Horizontally centered </div> </div> </body> </html> By default, negative values can be used with margin properties in CSS. The negative values cannot be used with padding. It is possible to enable the negative margins by setting the variable $enable-negative-margins to true. Gap utilities You can make use of gap utilities on the parent element, while using display: grid or display: flex. By default the gap utilities are responsive. It can hold the values for all the six sizes from the $spacers map (0-5). There is no .gap-auto class, as it is same as .gap-0. Let us see an example: Example You can edit and try running this code using the Edit & Run option. <!DOCTYPE html> <html> <head> <title>Bootstrap – Spacing</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 mt-3″> <h4 class=”display-6″> gap utility </h4> <h4>gap utility class <i>.gap-*</i></h4> <div class=”d-grid gap-0 p-3 border border-primary bg-light”> <div class=”p-2 bg-light border”> gap-0 </div> <div class=”p-2 bg-light border”> gap-0 </div> </div> <div class=”d-grid gap-1 p-3 border border-danger bg-primary-subtle”> <div class=”p-2 bg-light border”> gap-1 </div> <div class=”p-2 bg-light border”> gap-1 </div> </div> <div class=”d-grid gap-2 p-3 border border-success bg-danger-subtle”> <div class=”p-2 bg-light border”> gap-2 </div> <div class=”p-2 bg-light border”> gap-2 </div> </div> </div> </body> </html> row-gap In order to set the vertical space between children items in a specified container, use the utility class .row-gap. Let us see an example: Example You can edit and try running this code using the Edit & Run option. <!DOCTYPE html> <html> <head> <title>Bootstrap – Spacing</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 mt-3″> <h4 class=”display-6″> gap utility </h4> <h4>row gap utility class <i>.row-gap-*</i></h4> <div class=”d-grid gap-0 row-gap-4″> <div class=”p-2 border bg-primary”> row gap-4 </div> <div class=”p-2 border bg-info”> row gap-4 </div> <div class=”p-2 border bg-warning”> row gap-4 </div> <div class=”p-2 border bg-danger-subtle”> row
Bootstrap – Colors
Bootstrap – Colors ”; Previous Next This chapter will discuss about Bootstrap Colors classes. You can use Bootstrap’s custom classes to add color to the text or the background and hence adding some meaning to your content. Text Colors Add the color utilities like .text-* to colorize the text. The color utilities like .text-* that generated from Bootstrap”s original $theme-colors Sass map don’t yet respond to color modes. This will be resolved in version 6. Example You can edit and try running this code using the Edit & Run option. <!DOCTYPE html> <html lang=”en”> <head> <title>Bootstrap Textual Colors</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 mt-3″> <h4>Contextual Colors</h4> <p>Use the contextual classes to provide “meaning through colors”:</p> <p class=”text-muted”>Text marked by this class is muted.</p> <p class=”text-primary”>Text marked by this class is important.</p> <p class=”text-primary-emphasis”>Text marked by this class is darker than that displayed by .text-primary class.</p> <p class=”text-success”>Text marked by this class indicates success.</p> <p class=”text-success-emphasis”>Text marked by this class is darker than that displayed by .text-success class.</p> <p class=”text-info”>Text marked by this class represents some information.</p> <p class=”text-info-emphasis”>Text marked by this class is darker than that displayed by .text-info class.</p> <p class=”text-warning”>Text marked by this class represents a warning.</p> <p class=”text-warning-emphasis”>Text marked by this class is darker than that displayed by .text-warning class.</p> <p class=”text-danger”>Text marked by this class represents danger.</p> <p class=”text-danger-emphasis”>Text marked by this class is darker than that displayed by .text-danger class.</p> <p class=”text-secondary”>Text marked by this class is secondary text.</p> <p class=”text-secondary-emphasis”>Text marked by this class is darker than that displayed by .text-secondary class.</p> <p class=”text-dark”>Text marked by this class is displayed dark grey in color.</p> <p class=”text-dark-emphasis”>Text marked by this class is darker than that displayed by .text-dark class.</p> <p class=”text-body”>This class marks the default body color i.e. black.</p> <p class=”text-body-emphasis”>Text marked by this class is darker than that displayed by .text-body class.</p> <p class=”text-body-secondary”>Text marked by this class is lighter than that displayed by .text-body class.</p> <p class=”text-body-tertiary”>Text marked by this class is lighter than that displayed by .text-body-secondary class.</p> <p class=”text-light”>This class represents the text in light grey color, on a white background.</p> <p class=”text-light-emphasis”>Text marked by this class is lighter than that displayed by .text-light class.</p> <p class=”text-white bg-dark”>This class represents the text in white. on white background. In order to make the white text look clear, <b>bg-dark</b> class is used.</p> <p class=”text-black bg-white”>This class represents the text in black color. In order to make the black text color clear, <b>bg-white</b> class is used.</p> </div> </body> </html> Deprecation: The text utilities like .text-black-50 and .text-white-50 are deprecated as of v5.1.0 and they will be removed from v6.0.0. New utilities like .text-opacity-* are added. Deprecation: The .text-muted has been deprecated as of v5.3.0, due to addition of new theme colors and variables. It will be removed from v6.0.0. Its default value is reassigned to a CSS variable –bs-secondary-color. Background Colors Bootstrap provides a set of predefined CSS classes for background colors that can be applied to HTML elements using the bg-* classes. These classes allow you to easily apply background colors to various components in your web page without having to write custom CSS. Here are the list of background color classes provided by Bootstrap: .bg-primary .bg-success .bg-info .bg-warning .bg-danger .bg-secondary .bg-dark .bg-light Example You can edit and try running this code using the Edit & Run option. <!DOCTYPE html> <html lang=”en”> <head> <title>Bootstrap Background Colors</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 mt-3″> <h4>Background Colors</h4> <p>Use of background classes provided by Bootstrap to add meaning through colors.</p> <div class=”bg-primary p-3″>Sets the background color to the primary color defined in the Bootstrap theme.</div> <div class=”bg-success p-3″>Sets the background color to indicate success, typically green.</div> <div class=”bg-info p-3″>Sets the background color to indicate information, typically blue.</div> <div class=”bg-warning p-3″>Sets the background color to indicate a warning or caution, typically yellow.</div> <div class=”bg-danger p-3″>Sets the background color to indicate danger, typically red.</div> <div class=”bg-secondary p-3″>Sets the background color to the secondary color defined in the Bootstrap theme.</div> <div class=”bg-dark p-3″>Sets the background color to a dark color, typically a dark gray.</div> <div class=”bg-light p-3″>Sets the background color to a light color, typically a light gray.</div> </div> </body> </html> Background Text Colors Bootstrap provides a set of predefined CSS classes for text colors that can be applied to HTML elements to customize the color of the text. These classes are used in conjunction with background color classes such as .bg-* classes, to control the color of the text within elements that have a background color applied to them. Here are the list of background text color classes provided by Bootstrap: .text-bg-primary .text-bg-success .text-bg-info .text-bg-warning .text-bg-danger .text-bg-secondary .text-bg-dark .text-bg-light Example You can edit and try running this code using the Edit & Run option. <!DOCTYPE html> <html lang=”en”> <head> <title>Bootstrap Colors – background text color</title> <meta charset=”UTF-8″> <meta http-equiv=”X-UA-Compatible” content=”IE=edge”> <meta name=”viewport” content=”width=device-width, initial-scale=1″> <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 mt-3″> <h4>Contrasting text Color as per the background color</h4> <p class=”text-bg-primary”>Sets the text color to the primary color defined in the Bootstrap theme.</p> <p class=”text-bg-success”>Sets the text color to indicate success, typically green.</p> <p class=”text-bg-info”>Sets the text color to indicate information, typically blue.</p> <p class=”text-bg-warning”>Sets the text color to indicate a warning or caution, typically yellow.</p> <p class=”text-bg-danger”>Sets the text color to indicate danger, typically red.</p> <p class=”text-bg-secondary”>Sets the text color to the secondary color defined in the
Bootstrap – Range
Bootstrap – Range ”; Previous Next This chapter will discuss about Bootstrap form range. Range is an interactive component. The user can quickly scroll and slide through possible values spread across the required range. Basic example Use class .form-range to create unique controls for <input type=”range”>. Both track and thumb have the same appearance across all browsers. Bootstrap doesn”t support “filling” their range”s track from left to right of the thumb as a means to visually indicate progress. This is only supported on firefox. Example You can edit and try running this code using Edit & Run option. <!DOCTYPE html> <html lang=”en”> <head> <title>Bootstrap Form – Range</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> <label for=”basicRange” class=”form-label”>Range</label> <input type=”range” class=”form-range” id=”basicRange”> </body> </html> Disabled The disabled attribute is used to disable the Range. Disabled range cannot be focused, appears greyed out, and has no pointer events. Example You can edit and try running this code using Edit & Run option. <!DOCTYPE html> <html lang=”en”> <head> <title>Bootstrap Form – Range</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> <label for=”disabledRange” class=”form-label”>Range</label> <input type=”range” class=”form-range” id=”disabledRange” disabled> </body> </html> Min and max Default range input for min is 0 and max is 100. If you are using min and max attributes, new values can be specified. Example You can edit and try running this code using Edit & Run option. <!DOCTYPE html> <html lang=”en”> <head> <title>Bootstrap Form – Range</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> <label for=”minmaxrange” class=”form-label”>Range</label> <input type=”range” class=”form-range” min=”0″ max=”9″ id=”minmaxrange”> </body> </html> Steps Range step determines how much the range input value will increase or decrease in one step. Number of steps is doubled when step=”0.5″ is used. Example You can edit and try running this code using Edit & Run option. <!DOCTYPE html> <html lang=”en”> <head> <title>Bootstrap Form – Range</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> <label for=”stepRange” class=”form-label”>Range</label> <input type=”range” class=”form-range” min=”0″ max=”7″ step=”0.5″ id=”stepRange”> </html> Print Page Previous Next Advertisements ”;
Bootstrap – Object Fit
Bootstrap – Object fit ”; Previous Next This chapter discusses about the object fit utilities. These utility classes are used to resize the content of the replaced elements, such as <img> or <video> to fit its container. The object-fit property either preserves the aspect ratio or stretches to take up as much as space available of the content in the container. The format of this property is .object-fit-{value}. Following are the values that .object-fit class takes up: contain – The entire content will be scaled down or up to fit within the container, while maintaining its original aspect ratio. cover – The content will be scaled to cover the entire container, potentially cropping parts of it. The aspect ratio will be maintained. fill – This is the default value. The image or video will fill the entire container, possibly stretching or squishing its original aspect ratio. scale (for scale down) – The content will be scaled down to fit within the container, but only if it would be scaled up by using the contain value. Otherwise, it behaves as none. none – This does not bring any change in the display of the content. Let us see an example for .object-fit: none: Example You can edit and try running this code using the Edit & Run option. <!DOCTYPE html> <html> <head> <title>Bootstrap – Object fit</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> <style> img { width:200px; height:400px; } </style> </head> <body> <div class=”container mt-3″> <h4>Object fit value – none</h4> <img src=”/bootstrap/images/tutimg.png” width=”667″ height=”184″ class=”object-fit-none”> </div> </body> </html> Let us see an example for another value object-fit: contain: Example You can edit and try running this code using the Edit & Run option. <!DOCTYPE html> <html> <head> <title>Bootstrap – Object fit</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> <style> img { width:200px; height:400px; } </style> </head> <body> <div class=”container mt-3″> <h4>Object fit value – contain</h4> <img src=”/bootstrap/images/tutimg.png” width=”667″ height=”184″ class=”object-fit-contain”> </div> </body> </html> Responsive The utility class .object-fit includes responsive variations for various breakpoints, such as sm, md, lg, xl, xxl, using the format .object-fit-{breakpoint}-{value}. Let us see an example for breakpoint (md): Example You can edit and try running this code using the Edit & Run option. <!DOCTYPE html> <html> <head> <title>Bootstrap – Object fit</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> <style> img { width:200px; height:400px; } </style> </head> <body> <div class=”container mt-3″> <h4>Object fit value (contain) – breakpoint (md)</h4> <img src=”/bootstrap/images/tutimg.png” width=”667″ height=”184″ class=”object-fit-md-contain”> </div> </body> </html> Let us see an example for breakpoint (xxl): Example You can edit and try running this code using the Edit & Run option. <!DOCTYPE html> <html> <head> <title>Bootstrap – Object fit</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> <style> img { width:200px; height:400px; } </style> </head> <body> <div class=”container mt-3″> <h4>Object fit value (fill) – breakpoint (xxl)</h4> <img src=”/bootstrap/images/tutimg.png” width=”667″ height=”184″ class=”object-fit-xxl-fill”> </div> </body> </html> Video The .object-fit utility classes also work on <video> elements. Let us see an example: Example You can edit and try running this code using the Edit & Run option. <!DOCTYPE html> <html> <head> <title>Bootstrap – Object fit</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> <style> video { border: 5px groove darkblue; padding: 30px; width: auto; height: auto; } </style> </head> <body> <div class=”container mt-3″> <h4>Object fit value (cover) – video</h4> <video src=”/bootstrap/images/foo.mp4″ class=”object-fit-cover” autoplay> </video> </div> </body> </html> Print Page Previous Next Advertisements ”;
Bootstrap – Ratio
Bootstrap – Ratio ”; Previous Next 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: 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 16×9 </h2> <hr> <div class=”ratio ratio-16×9″> <iframe src=”https://www.youtube.com/embed/4PWVFBiFVVU” title=”YouTube video” allowfullscreen> </iframe> </div> </body> </html> Here”s an example of how aspect ratios are used with the <iframe> element. Here we are using the 21×9 aspect 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> <h2 class=”text-success text-center”> Aspect Ratio – 21×9 </h2> <hr> <div class=”ratio ratio-21×9″> <iframe src=”https://www.youtube.com/embed/4PWVFBiFVVU” title=”YouTube video” allowfullscreen> </iframe> </div> </body> </html> 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> Print Page Previous Next Advertisements ”;
Bootstrap – Select
Bootstrap – Form Select ”; Previous Next This chapter will discuss about Bootstrap form select menu. Custom CSS can be used to alter the default appearance of the native <select> elements. Default Custom class .form-select is required for custom <select> menus, to trigger the custom styles. Due to browser restrictions, custom styles are only able to change the <select>”s default appearance and cannot change the <options>s. Example You can edit and try running this code using Edit & Run option. <!DOCTYPE html> <html lang=”en”> <head> <title>Bootstrap – Select Menu</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> <select class=”form-select” aria-label=”Default select example”> <option selected>Select Menu</option> <option value=”1″>Item 1</option> <option value=”2″>Item 2</option> <option value=”3″>Item 3</option> </select> </body> </html> Sizing In order to match the similar sized text inputs, you may also select from small and large custom selects. Example You can edit and try running this code using Edit & Run option. <!DOCTYPE html> <html lang=”en”> <head> <title>Bootstrap – Select Menu</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> <select class=”form-select form-select-lg mb-3″ aria-label=”.form-select-lg example”> <option selected>Large Sized Select Menu</option> <option value=”1″>Item 1</option> <option value=”2″>Item 2</option> <option value=”3″>Item 3</option> </select> <select class=”form-select form-select-sm” aria-label=”.form-select-sm example”> <option selected>Small Sized Select Menu</option> <option value=”1″>Item 1</option> <option value=”2″>Item 2</option> <option value=”3″>Item 3</option> </select> </body> </html> You can give multiple options in drop-down list using multiple attribute. Example You can edit and try running this code using Edit & Run option. <!DOCTYPE html> <html lang=”en”> <head> <title>Bootstrap – Select Menu</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> <select class=”form-select” multiple aria-label=”multiple select example”> <option selected>Select Menu</option> <option value=”1″>Item 1</option> <option value=”2″>Item 2</option> <option value=”3″>Item 3</option> </select> </body> </html> A size attribute restricts the number of options in a drop-down list. Example You can edit and try running this code using Edit & Run option. <!DOCTYPE html> <html lang=”en”> <head> <title>Bootstrap – Select Menu</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> <select class=”form-select” size=”4″ aria-label=”size 3 select example”> <option selected>Select Menu</option> <option value=”1″>Item 1</option> <option value=”2″>Item 2</option> <option value=”3″>Item 3</option> <option value=”3″>Item 4</option> </select> </html> Disabled In order to make a select appear greyed out and eliminate pointer events, add the disabled boolean attribute to it. Example You can edit and try running this code using Edit & Run option. <!DOCTYPE html> <html lang=”en”> <head> <title>Bootstrap Form – Select Menu</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> <select class=”form-select” aria-label=”Disabled select example” disabled> <option selected>Select Menu</option> <option value=”1″>Item 1</option> <option value=”2″>Item 2</option> <option value=”3″>Item 3</option> </select> </html> Print Page Previous Next Advertisements ”;
Bootstrap – Colored Links
Bootstrap – Colored links ”; Previous Next 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: 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> Print Page Previous Next Advertisements ”;
Bootstrap – Interactions
Bootstrap – Interactions ”; Previous Next This chapter discuss about Bootstrap utility classess that change the way users interact with contents of a website. Text selection This section demostrates how Bootstrap utility classess user-select-* change the way in which content is selected during user interactions. Example You can edit and try running this code using Edit & Run option. <!DOCTYPE html> <html lang=”en”> <head> <title>Bootstrap – Interactions</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> <p class=”user-select-all”>When the user clicks on this paragraph, the entire text will be selected.</p> <p class=”user-select-auto”>The select behavior of this paragraph is set to its default state.</p> <p class=”user-select-none”>When the user clicks on this paragraph, it will not be selectable.</p> </body> </html> Pointer events Bootstrap classes .pe-none and .pe-auto classes prevents and enabling of element interactions as demostrated in the following example. Example You can edit and try running this code using Edit & Run option. <!DOCTYPE html> <html lang=”en”> <head> <title>Bootstrap – Interactions</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> <p>Use the “pe-none” class to make the <a href=”#” class=”pe-none” tabindex=”-1″ aria-disabled=”true”>link</a> inactive.</p> <p>Use the “pe-auto” class to make the <a href=”#” class=”pe-auto”>link</a> active.</p> <p class=”pe-none”><a href=”#” tabindex=”-1″ aria-disabled=”true”>This link </a> is not active due to the inherited pointer-events property. Now, <a href=”#” class=”pe-auto”>This link</a> is an active.</p> </body> </html> The .pe-none class, along with the pointer-events CSS property it applies, is designed to disable interactions specifically with a pointer, such as a mouse, stylus, or touch input. By default, links, and controls with .pe-none remain functional and accessible for keyboard users. In order to achieve full neutralization for keyboard users, additional attributes can be included for keyboard users. These attributes may include tabindex=”-1″ to prevent keyboard focus, aria-disabled=”true” to indicate their disabled state to assistive technologies, and JavaScript could also be utilized to fully prevent any action on them. If possible, it can be done in a simpler way: For form controls: You can add the disabled attribute in the HTML. For links: Remove the “href” attribute from links, effectively making them non-interactive or placeholder elements. Print Page Previous Next Advertisements ”;