Bootstrap 5.3.8

repository·main·Indexed 13 days ago

https://github.com/twbs/bootstrap

A powerful front-end framework for developing responsive, mobile-first websites. It provides a comprehensive collection of CSS and JavaScript tools, including components like Alerts, Buttons, Carousels, Collapse, and Dropdowns, available via a JavaScript API, jQuery plugins, or a Data API.

Tokens
171.5K
Snippets
530
Records
700
Agent score
100%

What's inside Bootstrap

  1. Understand the Bootstrap MIT License requirements and permissions

    main

    Bootstrap is released under the MIT license. When using Bootstrap in your projects, you must adhere to the following conditions:

    Requirements

    • Keep notices intact: You must retain the license and copyright notice included in Bootstrap’s CSS and JavaScript files when using them in your works.

    Permissions

    • Commercial & Private Use: You can freely download and use Bootstrap (in whole or in part) for personal, private, company internal, or commercial purposes.
    • Distribution: You can use Bootstrap in packages or distributions that you create.
    • Modification: You are permitted to modify the source code.
    • Sublicensing: You can grant a sublicense to modify and distribute Bootstrap to third parties.

    Prohibitions

    • No Liability: You cannot hold the authors, license owners, or copyright holders liable for damages; Bootstrap is provided without warranty.
    • No Improper Attribution: You cannot redistribute any piece of Bootstrap without proper attribution.
    • No Endorsement Claims: You cannot use Bootstrap's marks in a way that implies Bootstrap endorses your distribution, or implies that you created the Bootstrap software.

    What is NOT required

    • No Source Disclosure: You are not required to include the source of Bootstrap (or your modifications) in your redistribution.
    • No Forced Contributions: You are not required to submit your changes back to the Bootstrap project (though it is encouraged).
  2. Supported browsers and platforms

    main

    Bootstrap supports the latest, stable releases of all major browsers and platforms. This includes desktop browsers and the default browsers for major mobile platforms.

    Mobile Support

    Bootstrap supports the latest versions of each major platform's default browsers. Note that proxy browsers (e.g., Opera Mini, UC Browser Mini, Amazon Silk) are not supported.

    PlatformChromeFirefoxSafariAndroid Browser & WebView
    AndroidSupportedSupportedv6.0+
    iOSSupportedSupportedSupported

    Desktop Support

    PlatformChromeFirefoxMicrosoft EdgeOperaSafari
    MacSupportedSupportedSupportedSupportedSupported
    WindowsSupportedSupportedSupportedSupported

    Note: For Firefox, Bootstrap supports both the latest normal stable release and the latest Extended Support Release (ESR).

  3. Bootstrap's core design principles

    main

    Bootstrap follows several guiding principles to ensure components are easy to customize, extend, and maintain:

    • Mobile-first & Responsive: Styles use min-width media queries to apply styles as viewports grow, reducing the need for CSS overrides.
    • Base & Modifier Classes: Components use a base class for shared properties (e.g., .btn) and modifier classes for variations (e.g., .btn-primary).
    • Class-based Selectors: Styles avoid type selectors (like input[type="text"]) and nested parent selectors to keep specificity low and overrides easy.
    • HTML/CSS over JS: Prefer native browser functionality (like :valid/:invalid pseudo-classes) and HTML data attributes for JS plugins over custom JavaScript logic.
    • Utility-first: Use utility classes (single property-value pairs like .d-block) to reduce custom CSS bloat and improve performance.
    • Flexible HTML: Avoid strict HTML requirements and immediate children selectors (>) to allow for more flexible implementations.
  4. What is RFS (Responsive Font Sizes)?

    main

    RFS is Bootstrap's unit resizing engine designed to responsively scale CSS properties (like font-size, margin, padding, border-radius, or box-shadow) based on the browser viewport dimensions.

    Instead of static values, RFS compiles properties into calc() functions using a combination of rem and viewport units (vw). This allows elements to scale fluidly across different devices and viewports.

  5. How the Accordion component works

    main

    The Accordion component is built on top of the Collapse JavaScript plugin. It uses the collapse plugin internally to manage the expanding and collapsing of content sections. To render an accordion item that is expanded by default, you must:

    1. Add the .show class to the .accordion-collapse element.
    2. Remove the .collapsed class from the .accordion-button element.
    3. Set the aria-expanded attribute to true on the .accordion-button.

    Standard accordion items use the data-bs-parent attribute on the .accordion-collapse element to ensure that opening one item automatically closes others within the same parent container.

    <div class="accordion" id="accordionExample">
        <div class="accordion-item">
          <h2 class="accordion-header">
            <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
              Accordion Item #1
            </button>
          </h2>
          <div id="collapseOne" class="accordion-collapse collapse show" data-bs-parent="#accordionExample">
            <div class="accordion-body">
              Content goes here.
            </div>
          </div>
        </div>
      </div>
  6. Understanding Bootstrap's z-index scales

    main

    Bootstrap manages depth using two distinct z-index scales to prevent conflicts between component elements and UI overlays.

    1. Component Elements

    Used for elements within a single component that overlap (e.g., button groups, input groups, pagination).

    • 0: Default (initial)
    • 1: :hover
    • 2: :active / .active
    • 3: :focus (Highest priority for user attention)

    2. Overlay Components

    Used for components that sit on top of the UI (e.g., modals, tooltips). This scale starts at 1000 to provide a buffer from custom project styles.

    Order of precedence (highest to lowest):

    1. Popovers
    2. Tooltips
    3. Modals
    4. Fixed/Sticky Navbars
    5. Dropdowns
  7. Understand the z-index scale and overlay components

    main

    Bootstrap distinguishes between two types of z-index usage:

    1. Low-level utilities: Classes like z-0 through z-3 and z-n1. These are used for internal layout management of overlapping components (e.g., items in a list group or buttons in a group).
    2. High-level values: These are reserved for overlay components that sit on top of the entire interface. These include:
      • Dropdowns
      • Modals
      • Offcanvas
      • Popovers
      • Toasts
      • Tooltips

    Do not use low-level utilities to attempt to layer components like modals over your main content; use the built-in component logic to ensure correct layering.

  8. Understand Bootstrap's z-index layering system

    main

    Bootstrap uses a predefined z-index scale to manage the layering of components like navigation, tooltips, popovers, and modals. This ensures that overlays appear in the correct visual order (e.g., a modal appearing above a navbar).

    Key Principles

    • Standardized Scale: Bootstrap uses a specific set of high values for layered components to avoid conflicts between different UI elements.
    • Avoid Individual Customization: It is strongly discouraged to customize individual z-index values. If you need to change the layering behavior, you should update the entire scale to maintain consistency across all components.
    • Low-level Z-index for Borders: For handling overlapping borders (such as in input groups or button groups), Bootstrap uses low single-digit values (1, 2, and 3) to manage default, hover, and active states. This ensures that borders are correctly displayed when an element is hovered, focused, or active.
  9. How the CSS Grid system works

    main

    The CSS Grid system is a separate layout engine from the default Bootstrap flexbox grid. When enabled, you use different classes and structural approaches:

    • Container: Replace .row with .grid. The .grid class sets display: grid and establishes the grid template.
    • Columns: Replace .col-* classes with .g-col-* classes. These use the grid-column property instead of width.
    • Gaps: Instead of horizontal padding (gutters), the system uses the CSS gap property. Gaps are applied both horizontally and vertically by default.
    • Customization: Column counts and gutter sizes are controlled via CSS variables (--bs-columns and --bs-gap) applied to the .grid container.
  10. Accessibility considerations for dropdowns

    main

    Bootstrap dropdowns are designed to be generic and can contain various markup (like forms or search fields), which differs from the strict role="menu" requirements of the WAI-ARIA standard.

    Implementation details:

    • ARIA Roles: Bootstrap does not automatically add role or aria- attributes. If you need your dropdown to function as a formal ARIA menu, you must manually add the required attributes.
    • Keyboard Support: Bootstrap provides built-in support for standard keyboard interactions:
      • Use cursor keys to navigate through individual .dropdown-item elements.
      • Use the <kbd>Esc</kbd> key to close the menu.
  11. Using the [hidden] attribute

    main

    Bootstrap styles the HTML5 [hidden] attribute with display: none !important; to prevent accidental overrides of the element's visibility.

    Warning: [hidden] is not compatible with jQuery's $(...).hide() and $(...).show() methods.

    If you want to toggle visibility without removing the element from the document flow (i.e., keeping its space occupied), use the .invisible utility class instead of the [hidden] attribute.

    <input type="text" hidden>