Skip to content

highbiza/bootstrap

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23,181 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Bootstrap logo

Bootstrap

Sleek, intuitive, and powerful front-end framework for faster and easier web development.
Explore Bootstrap docs »

Report bug · Request feature · Blog

Fork: CSS-var-driven section theming

This is a fork of Bootstrap 5.3.8 that makes all component colors fully CSS-var-driven. Override a few base tokens on any element and all derived colors (contrast, emphasis, link, border, etc.) auto-update via modern CSS.

Usage

Set base colors on any element. Everything else auto-derives:

.color-schema-ocean {
  --bs-primary: #0077b6;
  --bs-primary-rgb: 0, 119, 182;
  --bs-body-bg: #f8f9fa;
  --bs-body-color: #1d3557;
}

Auto-derived tokens (no manual override needed):

Token Derived from Method
--bs-on-* (contrast text) --bs-{color} oklch lightness flip
--bs-emphasis-color --bs-body-bg oklch lightness flip
--bs-link-color --bs-primary var()
--bs-link-hover-color --bs-primary color-mix() shade 20%
--bs-secondary-color --bs-body-color color-mix() 75% opacity
--bs-tertiary-color --bs-body-color color-mix() 50% opacity
--bs-secondary-bg --bs-body-bg + --bs-body-color color-mix() 10% tint
--bs-tertiary-bg --bs-body-bg + --bs-body-color color-mix() 3% tint
--bs-border-color --bs-body-bg + --bs-body-color color-mix() 15%
--bs-border-color-translucent --bs-body-color color-mix() 17.5% opacity
--bs-focus-ring-color --bs-primary color-mix() 25% opacity

Modals and offcanvas

Modals and offcanvas are standalone overlays — they don't automatically inherit a section's theme. To theme them, set the base tokens directly:

<div class="modal" id="myModal"
     style="--bs-primary: #0077b6; --bs-primary-rgb: 0,119,182; --bs-body-bg: #f8f9fa; --bs-body-color: #1d3557;">
  ...
</div>

Tooltips and popovers are handled automatically — css-var-scoping.js copies all --bs-* custom properties from the trigger element to the tip.

Why derived tokens live on * (not :root)

CSS custom properties with var() references resolve where the property is defined, not where it's inherited. This creates a fundamental problem for section-level theming:

/* Vanilla Bootstrap approach — BROKEN for sections */
:root {
  --bs-primary: #0d6efd;
  --bs-link-color: var(--bs-primary);       /* resolves to #0d6efd at :root */
  --bs-focus-ring-color: color-mix(in srgb, var(--bs-primary) 25%, transparent);
}

.color-schema-ocean {
  --bs-primary: #0077b6;
  /* --bs-link-color is STILL #0d6efd — inherited from :root where it was computed */
}

The :root element computed --bs-link-color using its own --bs-primary value (#0d6efd). Children inherit the computed result, not the var() expression. Overriding --bs-primary on a child has no effect on --bs-link-color.

The fix: define derived tokens on *, so every element gets its own computation:

:root {
  --bs-primary: #0d6efd;
  --bs-link-color: #0d6efd;                 /* static fallback, wins on :root (specificity 0,1,0) */
}

* {
  --bs-link-color: var(--bs-primary);        /* re-resolves per element (specificity 0,0,0) */
}

.color-schema-ocean {
  --bs-primary: #0077b6;
  /* Now --bs-link-color resolves to #0077b6 inside this section */
}

Why this is safe:

  • * has specificity (0,0,0) — any class, attribute, or id selector overrides it
  • :root retains static fallbacks at specificity (0,1,0), winning on the <html> element
  • Dark mode (.dark-mode / [data-bs-theme=dark]) has specificity (0,1,0), always overriding *
  • CSS engines optimize custom property resolution — * does not cause measurable performance overhead
  • The pattern is used by design systems like Open Props and Material Web Components

What * does NOT do:

  • It does not apply layout, box model, or visual properties to every element
  • It only sets custom properties (which are inherited by default anyway)
  • It does not interfere with component-level CSS variable overrides

Why not component-level selectors?

The conventional advice is to define derived calculations at component level (e.g. .btn { --hover-bg: color-mix(...) }). This works when you have a handful of components, but breaks down when the derived tokens are cross-cutting — used by buttons, links, alerts, tables, focus rings, borders, and text utilities simultaneously. You'd need to repeat the same color-mix() expressions in dozens of selectors and keep them in sync.

The * selector is the only approach that lets consumers override a single base token (--bs-primary) and have all derived tokens update everywhere, without repeating calculations per component.

Opting out of *

If you don't need section-level theming, disable the * block:

$enable-derived-vars: false;
@import "bootstrap";

Bootstrap then behaves like vanilla — all tokens are static on :root. If you still want per-section theming without *, you must set all derived tokens yourself on each section class:

.color-schema-ocean {
  --bs-primary: #0077b6;
  --bs-primary-rgb: 0, 119, 182;

  /* All derived tokens — you must repeat these per section */
  --bs-on-primary: #fff;
  --bs-link-color: #0077b6;
  --bs-link-hover-color: color-mix(in srgb, #0077b6, black 20%);
  --bs-focus-ring-color: color-mix(in srgb, #0077b6 25%, transparent);
  --bs-border-color: color-mix(in srgb, var(--bs-body-bg), var(--bs-body-color) 15%);
  --bs-border-color-translucent: color-mix(in srgb, var(--bs-body-color) 17.5%, transparent);
  --bs-secondary-color: color-mix(in srgb, var(--bs-body-color) 75%, transparent);
  --bs-secondary-bg: color-mix(in srgb, var(--bs-body-bg), var(--bs-body-color) 10%);
  --bs-tertiary-color: color-mix(in srgb, var(--bs-body-color) 50%, transparent);
  --bs-tertiary-bg: color-mix(in srgb, var(--bs-body-bg), var(--bs-body-color) 3%);
  --bs-emphasis-color: oklch(from var(--bs-body-bg) calc((0.6 - l) * 999) 0 h);
}

Further reading:

Contrast text

--bs-on-* uses the oklch lightness trick: oklch(from var(--bs-primary) calc((0.6 - l) * 999) 0 h) — dark colors get white text, light colors get black text. Wrapped in @supports (color: oklch(from red l c h)) so older browsers fall back to the static values on :root.

Browser support

Tier 1 (color-mix(), unconditional): Chrome 111+, Firefox 113+, Safari 16.2+. Covers link, hover, secondary/tertiary, border, and focus ring tokens.

Tier 2 (oklch relative color syntax, @supports gated): Chrome 131+, Firefox 133+, Safari 18+. Covers --bs-on-* contrast tokens and --bs-emphasis-color. Without Tier 2, these tokens use static :root fallbacks — section overrides won't auto-derive contrast text, but all other theming works.

Tooltips and popovers

Bootstrap appends tooltips/popovers to <body>, outside any themed section. css-var-scoping.js handles this automatically: when a tip is inserted, it compares the trigger's computed --bs-* properties with :root and copies any differences to the tip element. No extra attributes or markup needed.

SVG icons

Bootstrap uses SVG data URIs for component icons (checkmarks, chevrons, togglers). SVGs can't reference CSS custom properties, so icon colors are normally hardcoded at compile time.

This fork uses CSS mask-image to decouple icon shape from color — the SVG becomes a shape mask and the visible color comes from background, which CAN use CSS vars:

Component Approach Icon color follows
Close button mask --bs-emphasis-color
Accordion chevron mask --bs-accordion-btn-color / --bs-accordion-active-color
Navbar toggler mask --bs-navbar-color

Dark-mode SVG overrides for these components are eliminated — the color adapts automatically.

Not convertible (element shares background-color with the icon):

Component Reason Mitigation
Form select chevron <select> has its own bg-color Dark-mode override via color-mode()
Form switch circles <input> track IS the bg-color Dark-mode override via color-mode()
Checkbox/radio/indeterminate White on primary bg — universally correct No change needed
Carousel arrows White on dark overlay — universally correct No change needed
Validation icons Colors track $form-validation-states map Already themeable via Sass

Bootstrap 5

Our default branch is for development of our Bootstrap 5 release. Head to the v4-dev branch to view the readme, documentation, and source code for Bootstrap 4.

Table of contents

Quick start

Several quick start options are available:

  • Download the latest release
  • Clone the repo: git clone https://github.com/twbs/bootstrap.git
  • Install with npm: npm install bootstrap@v5.3.8
  • Install with yarn: yarn add bootstrap@v5.3.8
  • Install with Bun: bun add bootstrap@v5.3.8
  • Install with Composer: composer require twbs/bootstrap:5.3.8
  • Install with NuGet: CSS: Install-Package bootstrap Sass: Install-Package bootstrap.sass

Read the Getting started page for information on the framework contents, templates, examples, and more.

Status

Build Status npm version Gem version Meteor Atmosphere Packagist Prerelease NuGet Coverage Status CSS gzip size CSS Brotli size JS gzip size JS Brotli size Open Source Security Foundation Scorecard Backers on Open Collective Sponsors on Open Collective

What’s included

Within the download you’ll find the following directories and files, logically grouping common assets and providing both compiled and minified variations.

Download contents
bootstrap/
├── css/
│   ├── bootstrap-grid.css
│   ├── bootstrap-grid.css.map
│   ├── bootstrap-grid.min.css
│   ├── bootstrap-grid.min.css.map
│   ├── bootstrap-grid.rtl.css
│   ├── bootstrap-grid.rtl.css.map
│   ├── bootstrap-grid.rtl.min.css
│   ├── bootstrap-grid.rtl.min.css.map
│   ├── bootstrap-reboot.css
│   ├── bootstrap-reboot.css.map
│   ├── bootstrap-reboot.min.css
│   ├── bootstrap-reboot.min.css.map
│   ├── bootstrap-reboot.rtl.css
│   ├── bootstrap-reboot.rtl.css.map
│   ├── bootstrap-reboot.rtl.min.css
│   ├── bootstrap-reboot.rtl.min.css.map
│   ├── bootstrap-utilities.css
│   ├── bootstrap-utilities.css.map
│   ├── bootstrap-utilities.min.css
│   ├── bootstrap-utilities.min.css.map
│   ├── bootstrap-utilities.rtl.css
│   ├── bootstrap-utilities.rtl.css.map
│   ├── bootstrap-utilities.rtl.min.css
│   ├── bootstrap-utilities.rtl.min.css.map
│   ├── bootstrap.css
│   ├── bootstrap.css.map
│   ├── bootstrap.min.css
│   ├── bootstrap.min.css.map
│   ├── bootstrap.rtl.css
│   ├── bootstrap.rtl.css.map
│   ├── bootstrap.rtl.min.css
│   └── bootstrap.rtl.min.css.map
└── js/
    ├── bootstrap.bundle.js
    ├── bootstrap.bundle.js.map
    ├── bootstrap.bundle.min.js
    ├── bootstrap.bundle.min.js.map
    ├── bootstrap.esm.js
    ├── bootstrap.esm.js.map
    ├── bootstrap.esm.min.js
    ├── bootstrap.esm.min.js.map
    ├── bootstrap.js
    ├── bootstrap.js.map
    ├── bootstrap.min.js
    └── bootstrap.min.js.map

We provide compiled CSS and JS (bootstrap.*), as well as compiled and minified CSS and JS (bootstrap.min.*). Source maps (bootstrap.*.map) are available for use with certain browsers’ developer tools. Bundled JS files (bootstrap.bundle.js and minified bootstrap.bundle.min.js) include Popper.

Bugs and feature requests

Have a bug or a feature request? Please first read the issue guidelines and search for existing and closed issues. If your problem or idea is not addressed yet, please open a new issue.

Documentation

Bootstrap’s documentation, included in this repo in the root directory, is built with Astro and publicly hosted on GitHub Pages at https://getbootstrap.com/. The docs may also be run locally.

Documentation search is powered by Algolia's DocSearch.

Running documentation locally

  1. Run npm install to install the Node.js dependencies, including Astro (the site builder).
  2. Run npm run test (or a specific npm script) to rebuild distributed CSS and JavaScript files, as well as our docs assets.
  3. From the root /bootstrap directory, run npm run docs-serve in the command line.
  4. Open http://localhost:9001 in your browser, and voilà.

Learn more about using Astro by reading its documentation.

Documentation for previous releases

You can find all our previous releases docs on https://getbootstrap.com/docs/versions/.

Previous releases and their documentation are also available for download.

Contributing

Please read through our contributing guidelines. Included are directions for opening issues, coding standards, and notes on development.

Moreover, if your pull request contains JavaScript patches or features, you must include relevant unit tests. All HTML and CSS should conform to the Code Guide, maintained by Mark Otto.

Editor preferences are available in the editor config for easy use in common text editors. Read more and download plugins at https://editorconfig.org/.

Community

Get updates on Bootstrap’s development and chat with the project maintainers and community members.

Versioning

For transparency into our release cycle and in striving to maintain backward compatibility, Bootstrap is maintained under the Semantic Versioning guidelines. Sometimes we screw up, but we adhere to those rules whenever possible.

See the Releases section of our GitHub project for changelogs for each release version of Bootstrap. Release announcement posts on the official Bootstrap blog contain summaries of the most noteworthy changes made in each release.

Creators

Mark Otto

Jacob Thornton

Thanks

BrowserStack

Thanks to BrowserStack for providing the infrastructure that allows us to test in real browsers!

Netlify

Thanks to Netlify for providing us with Deploy Previews!

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

OC sponsor 0 OC sponsor 1 OC sponsor 2 OC sponsor 3 OC sponsor 4 OC sponsor 5 OC sponsor 6 OC sponsor 7 OC sponsor 8 OC sponsor 9

Backers

Thank you to all our backers! 🙏 [Become a backer]

Backers

Copyright and license

Code and documentation copyright 2011-2025 the Bootstrap Authors. Code released under the MIT License. Docs released under Creative Commons.

About

The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • MDX 28.5%
  • JavaScript 25.9%
  • Astro 19.1%
  • SCSS 11.2%
  • CSS 9.3%
  • HTML 4.6%
  • Other 1.4%