网页
综合
更新时间 2026-11-16 04:34:16
Migration · Bootstrap v6.0
自动蜘蛛
getbootstrap.com
正文约 6000 字
Track and review changes to the Bootstrap source files, documentation, and components to help you migrate from v5 to v6.
Bootstrap 6 is a major release with many breaking changes to modernize our codebase, adopt newer build tools, and improve customization. Keep reading for a guide on how to migrate from v5 to v6, and a full changelog of what’s new.
Migrating with an AI coding agent? Bootstrap ships a v5-to-v6 migration skill (skills/bootstrap-v5-v6-migration) that walks coding agents through the upgrade phase by phase. Bootstrap 4 projects should start with the v4-to-v6 migration skill. Point your agent at the applicable SKILL.md file, then review its changes against this guide.
Bump your Bootstrap dependency:
Replace @popperjs/core with @floating-ui/dom. If you use Datepicker, add vanilla-calendar-pro. The bundled JavaScript includes both peer dependencies. The standalone JavaScript requires installed packages or an import map.
If using all of Bootstrap’s Sass files, include it in your Sass using @use:
With this, you can then easily override Bootstrap’s Sass variables and maps:
If using only certain parts of Bootstrap’s Sass files, you can use @use to import them individually. Be aware that our Sass file structure has changed and you may need to adjust your imports accordingly.
Update HTML and CSS per the changelog and updates in the documentation.
Recompile your Sass to see the changes.
Check your browser support first. Bootstrap 6 raises the minimum browser versions sharply: Chrome and Edge 130, Firefox 132, and Safari 18 on both macOS and iOS. Bootstrap 5 supported Chrome and Firefox 60, and Safari 12. We build on light-dark(), :has(), container queries, content-visibility, and the native <dialog> element, and v6 ships no fallbacks, prefixes, or polyfills below the floor. Pages will not render correctly in older browsers. Check your own analytics before you upgrade, and see Browsers & devices for the full policy and the reason behind each version.
The prefix syntax does not identify the query type. Utilities, grid columns, containers, drawers, and responsive tables use viewport queries. Stacks, CSS Grid columns, navbar expansion, horizontal list groups, card groups, and stacked tables use container queries. Add the query container that each component’s documentation requires.
show(), hide(), toggle(), and close() now return a promise. The promise resolves when the transition ends, so you can await these methods instead of listening for a shown.bs.* or hidden.bs.* event. In v5 they returned undefined. The events still fire, so existing code keeps working. This covers Alert, Collapse, Combobox, Datepicker, Dialog, Drawer, Menu, Popover, Tab, Toast, and Tooltip. Carousel’s next(), prev(), and to() are unchanged.
The promise resolves with no value, and it resolves even when the call does nothing — for example when the component is already open or a listener prevents the show.bs.* event. Check the component state yourself if you need to know whether it changed.
Bootstrap’s JavaScript is now ESM-only. We no longer ship UMD bundles. All dist files (bootstrap.js, bootstrap.bundle.js, and their minified versions) are native ES modules. The loading model changed, and several component APIs changed as listed below.
CDN <script> tags must add type="module":
In v5, the UMD bundle automatically created a window.bootstrap global. ES modules don’t do this, so there is no longer a bootstrap global object. If you called plugin APIs through the global namespace, you must update to explicit imports:
Data API initialization still runs automatically. Add type="module" to the script tag. You must also apply the component and data attribute renames in this guide.
For modern ESM-based bundlers (Vite, Webpack 5, Parcel 2, Rolldown, etc.), import { Tooltip } from 'bootstrap' still works and supports tree shaking. Install @floating-ui/dom for positioned components and vanilla-calendar-pro for Datepicker. Projects that use CommonJS require() calls must change to ESM import syntax.
The bootstrap.bundle.js files include Floating UI and Vanilla Calendar Pro. The standalone bootstrap.js files leave these peer dependencies external, so direct browser loading requires an import map.
Bootstrap’s JavaScript source is now TypeScript. The js/src files use the .ts extension. The package ships built-in type declarations in js/dist/*.d.ts, so you no longer need @types/bootstrap. Deep .js imports still work: bootstrap/js/src/alert.js now resolves to the compiled file in js/dist. To import the raw TypeScript source, use bootstrap/js/src/alert.ts.
We now build with Rolldown instead of Rollup and Babel. This only affects you if you build Bootstrap from source. Rolldown strips the TypeScript types and lowers the syntax itself, so Babel is gone, along with .babelrc.mjs and the @rollup/plugin-* packages. The published files in dist/ and js/dist/ are unchanged in format. If you bundle Bootstrap in your own project, keep using whatever bundler you prefer — Rollup is still a fine choice, and import { Tooltip } from 'bootstrap' works the same way. See the contribute guide for details.
Tab now throws when its element has no tab-panel ancestor. In v5 the constructor returned early and gave you an inert instance, which hid the markup error. Wrap your tab triggers in a .list-group, .nav, or [role="tablist"] container, as the Nav docs show.
Removed the separate bootstrap.esm.js and bootstrap.esm.min.js files — bootstrap.js is now the ESM entry point.
Removed js/index.umd.js entry point.
Removed jQuery support and the js-test-jquery test target.
Removed the internal util/backdrop, util/focustrap, and util/scrollbar helpers. They’re obsolete now that Dialog and Drawer build on the native <dialog> element—the browser provides the backdrop (::backdrop), focus trap, and an inert top layer, and the body scroll-lock is handled in CSS (:root.dialog-open with scrollbar-gutter: stable). If you imported any of these modules directly from bootstrap/js
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。