bootstrap-v5-v6-migration
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBootstrap v5 to v6 Migration
Bootstrap v5 至 v6 迁移
Workflow
工作流程
Work through each step in order. After each step, search the codebase for remaining v5 patterns before moving on.
- Step 1: Update dependencies and build setup
- Step 2: Rename CSS classes and data attributes
- Step 3: Restructure component HTML
- Step 4: Update JavaScript
- Step 5: Update Sass
- Step 6: Verify
按顺序执行每个步骤。每完成一步后,在代码库中搜索剩余的 v5 模式,再继续下一步。
- 步骤1:更新依赖与构建配置
- 步骤2:重命名 CSS 类名与数据属性
- 步骤3:重构组件 HTML 结构
- 步骤4:更新 JavaScript
- 步骤5:更新 Sass
- 步骤6:验证
Step 1: Dependencies & Build
步骤1:依赖与构建
- Update :
package.json"bootstrap": "6.0.0-alpha.1" - Replace with
@popperjs/core@floating-ui/dom - If using Datepicker, add peer dep
vanilla-calendar-pro - Sass: replace all with
@import(Node Sass is no longer supported)@use
bootstrap.bundle.jsbootstrap.jsscss
// v5
@import "bootstrap/scss/bootstrap";
// v6
@use "bootstrap/scss/bootstrap";
// v6 with overrides — customize CSS tokens through the token maps
@use "bootstrap/scss/bootstrap" with (
$root-tokens: (
--spacer: 1rem,
)
);Customize by overriding the CSS token maps — for global tokens and each component's map — rather than legacy Sass scalars. See Customize › Sass. Token names are written unprefixed in Sass (e.g. , ); Bootstrap's dist/CDN CSS runs PostCSS to add the prefix (), so when you compile the source yourself the properties stay unprefixed.
$root-tokens$*-tokens--spacer--border-radius--bs---bs-spacer- 更新 :
package.json"bootstrap": "6.0.0-alpha.1" - 将 替换为
@popperjs/core@floating-ui/dom - 如果使用 Datepicker,添加 peer 依赖
vanilla-calendar-pro - Sass:将所有 替换为
@import(不再支持 Node Sass)@use
bootstrap.bundle.jsbootstrap.jsscss
// v5
@import "bootstrap/scss/bootstrap";
// v6
@use "bootstrap/scss/bootstrap";
// v6 with overrides — customize CSS tokens through the token maps
@use "bootstrap/scss/bootstrap" with (
$root-tokens: (
--spacer: 1rem,
)
);通过覆盖 CSS 令牌映射进行自定义——全局令牌使用 ,每个组件有对应的 映射——而非传统的 Sass 标量变量。参见 自定义 › Sass。
令牌名称在 Sass 中不带前缀(例如 、);Bootstrap 的发布版/CDN CSS 会通过 PostCSS 添加 前缀(即 ),因此如果你自行编译源码,这些属性将保持无前缀状态。
$root-tokens$*-tokens--spacer--border-radius--bs---bs-spacerStep 2: CSS Class & Attribute Renames
步骤2:CSS 类名与属性重命名
Responsive & state prefix syntax
响应式与状态前缀语法
v6 moves breakpoints and pseudo-states from infix/suffix to prefix with colon. Also renames to .
xxl2xlPattern: becomes and becomes
.{class}-{bp}-{value}.{bp}:{class}-{value}.{class}-{bp}.{bp}:{class}| v5 | v6 |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
The prefix 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.
v6 将断点和伪状态从中缀/后缀改为带冒号的前缀形式。同时将 重命名为 。
xxl2xl模式: 变为 , 变为
.{class}-{bp}-{value}.{bp}:{class}-{value}.{class}-{bp}.{bp}:{class}| v5 | v6 |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
前缀并不标识查询类型。工具类、网格列、容器、Drawer 和响应式表格使用视口查询。堆叠布局、CSS Grid 列、导航栏展开、水平列表组、卡片组和堆叠表格使用容器查询。请添加各组件文档要求的查询容器。
Component renames
组件重命名
Three components have been fully renamed. Find-and-replace these prefixes across classes, data attributes, events, JS imports, and CSS variables.
有三个组件已完全重命名。请在类名、数据属性、事件、JS 导入和 CSS 变量中全局查找并替换这些前缀。
Modal -> Dialog
Modal -> Dialog
| Scope | v5 | v6 |
|---|---|---|
| Classes | | |
| Sizes | | |
| Data attrs | | |
| JS export | | |
| Events | | |
| CSS vars | | |
| Body class | | |
Remove and wrappers entirely — see Step 3.
.modal-dialog.modal-content| 范围 | v5 | v6 |
|---|---|---|
| 类名 | | |
| 尺寸 | | |
| 数据属性 | | |
| JS 导出 | | |
| 事件 | | |
| CSS 变量 | | |
| body 类名 | | |
请完全移除 和 包装器——参见步骤3。
.modal-dialog.modal-contentOffcanvas -> Drawer
Offcanvas -> Drawer
| Scope | v5 | v6 |
|---|---|---|
| Classes | | |
| Data attrs | | |
| JS export | | |
| Events | | |
| CSS vars | | |
| Sass | | |
| 范围 | v5 | v6 |
|---|---|---|
| 类名 | | |
| 数据属性 | | |
| JS 导出 | | |
| 事件 | | |
| CSS 变量 | | |
| Sass | | |
Dropdown -> Menu
Dropdown -> Menu
| Scope | v5 | v6 |
|---|---|---|
| Classes | | |
| Data attrs | | |
| JS export | | |
| Events | | |
| Sass | | |
Also remove: (no longer needed), wrapper, . See Step 3 for new markup.
.dropdown-toggle.dropdown.dropdown-toggle-split| 范围 | v5 | v6 |
|---|---|---|
| 类名 | | |
| 数据属性 | | |
| JS 导出 | | |
| 事件 | | |
| Sass | | |
同时移除:(不再需要)、 包装器、。新的标记结构参见步骤3。
.dropdown-toggle.dropdown.dropdown-toggle-splitButton & badge variants -> theme tokens
按钮与徽章变体 -> 主题令牌
Per-color classes are replaced by variant + composition. Built-in theme keys are , , , , , , , and . Apply both classes to the same element.
.theme-*primaryaccentsuccessdangerwarninginfoinversesecondary| v5 | v6 |
|---|---|
| |
| |
| |
| |
New button variants: , , , , , .
.btn-solid.btn-outline.btn-subtle.btn-text.btn-styled.btn-linkUse on a nested subtree to drop inherited tokens and return to component defaults.
.theme-reset--theme-*There are no or classes. Review v5 light and dark variants manually. Use neutral surface utilities, color modes, or as appropriate.
.theme-light.theme-dark.theme-inverse每种颜色对应的独立类已被替换为变体 + 的组合形式。内置的主题键包括 、、、、、、 和 。请将两个类同时应用在同一个元素上。
.theme-*primaryaccentsuccessdangerwarninginfoinversesecondary| v5 | v6 |
|---|---|
| |
| |
| |
| |
新增的按钮变体包括:、、、、、。
.btn-solid.btn-outline.btn-subtle.btn-text.btn-styled.btn-link在嵌套的子树中使用 可以清除继承的 令牌,恢复组件的默认样式。
.theme-reset--theme-*不存在 或 类。请手动检查 v5 的浅色和深色变体,根据需求使用中性表面工具类、颜色模式或 。
.theme-light.theme-dark.theme-inversePlaceholder animations
占位符动画
Use for the standard loading animation. Replace with when you want the old opacity animation. remains as a compatibility alias.
.placeholder-wave.placeholder-glow.placeholder-pulse.placeholder-glow标准加载动画使用 。如果需要旧的透明度动画,请将 替换为 。 作为兼容别名仍然保留。
.placeholder-wave.placeholder-glow.placeholder-pulse.placeholder-glowUtility class renames
工具类重命名
| v5 | v6 |
|---|---|
| |
| |
| |
| |
| |
| |
| Remove (no longer needed) |
| |
| |
| |
Remove through and . Compose their styles with and utilities. Review , , and ; use the v6 neutral surfaces and color modes described in the migration guide.
.display-1.display-6.lead.fs-*.fw-*.bg-light.bg-dark.bg-body-*| v5 | v6 |
|---|---|
| |
| |
| |
| |
| |
| |
| 移除(不再需要) |
| |
| |
| |
移除 到 以及 。使用 和 工具类组合实现它们的样式。
检查 、 和 ;请使用迁移指南中介绍的 v6 中性表面和颜色模式。
.display-1.display-6.lead.fs-*.fw-*.bg-light.bg-dark.bg-body-*Font size classes
字体大小类
v6 replaces the numeric scale with t-shirt sizes (ascending). The full v6 scale is . The rem values below are the v5 sizes, shown only to help you match each class.
xs sm md lg xl 2xl 3xl 4xl 5xl 6xl| v5 (size) | v6 |
|---|---|
| |
| |
| |
| |
| |
| |
Note: in v6, and larger are fluid values that scale with the viewport between a min and a max (e.g. is ); // stay fixed. So sizes won't match v5 exactly — the mapping preserves the relative scale, not the precise rem.
lgclamp()4xlclamp(2.25rem, 1.75rem + 2.5vw, 3rem)xssmmdv6 用T恤尺码(升序)替换了数字刻度。v6 的完整刻度为 。下方的 rem 值是v5的尺寸,仅用于帮助你匹配对应的类。
xs sm md lg xl 2xl 3xl 4xl 5xl 6xl| v5(尺寸) | v6 |
|---|---|
| |
| |
| |
| |
| |
| |
注意:在 v6 中, 及更大的尺寸是流式 值,会在最小值和最大值之间随视口缩放(例如 为 );// 保持固定值。因此尺寸不会与 v5 完全一致——该映射保留了相对比例,而非精确的 rem 值。
lgclamp()4xlclamp(2.25rem, 1.75rem + 2.5vw, 3rem)xssmmdSpacer scale
间距刻度
Keys 2-5 have changed values. To preserve v5 spacing: (0.5rem) -> , (1rem) -> , (1.5rem) -> , (3rem) -> .
.p-2.p-3.p-3.p-5.p-4.p-7.p-5.p-12| Key | v5 | v6 |
|---|---|---|
| 2 | | |
| 3 | | |
| 4 | | |
| 5 | | |
| 6-12 | — | |
键 2-5 的值已发生变化。若要保留 v5 的间距:(0.5rem)→ ,(1rem)→ ,(1.5rem)→ ,(3rem)→ 。
.p-2.p-3.p-3.p-5.p-4.p-7.p-5.p-12| 键 | v5 | v6 |
|---|---|---|
| 2 | | |
| 3 | | |
| 4 | | |
| 5 | | |
| 6-12 | — | |
Form validation
表单验证
| v5 | v6 |
|---|---|
| |
| Remove — |
| |
| |
| v5 | v6 |
|---|---|
| |
通过 JS 添加 | 移除——由 |
| |
| |
Step 3: Structural HTML Changes
步骤3:HTML 结构变更
These components have fundamentally new markup, not just class renames.
这些组件的标记结构发生了根本性变化,不仅仅是类名重命名。
Dialog (was Modal)
Dialog(原 Modal)
Remove the and wrappers. Use a single element. The backdrop is now native .
.modal-dialog.modal-content<dialog>::backdrophtml
<!-- v5 -->
<div class="modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">Content</div>
<div class="modal-footer">
<button class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- v6 -->
<dialog class="dialog" id="exampleDialog">
<div class="dialog-header">
<h5 class="dialog-title">Title</h5>
<button type="button" class="btn-close" data-bs-dismiss="dialog" aria-label="Close"></button>
</div>
<div class="dialog-body">Content</div>
<div class="dialog-footer">
<button class="btn-solid theme-secondary" data-bs-dismiss="dialog">Close</button>
</div>
</dialog>移除 和 包装器。使用单个 元素。背景现在使用原生的 。
.modal-dialog.modal-content<dialog>::backdrophtml
<!-- v5 -->
<div class="modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">Content</div>
<div class="modal-footer">
<button class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- v6 -->
<dialog class="dialog" id="exampleDialog">
<div class="dialog-header">
<h5 class="dialog-title">Title</h5>
<button type="button" class="btn-close" data-bs-dismiss="dialog" aria-label="Close"></button>
</div>
<div class="dialog-body">Content</div>
<div class="dialog-footer">
<button class="btn-solid theme-secondary" data-bs-dismiss="dialog">Close</button>
</div>
</dialog>Drawer (was Offcanvas)
Drawer(原 Offcanvas)
Use a native element. A renamed does not work.
<dialog><div class="drawer">html
<!-- v5 -->
<div class="offcanvas offcanvas-start" id="menu">...</div>
<!-- v6 -->
<dialog class="drawer drawer-start" id="menu">...</dialog>For responsive navbars, change to . Replace with a that contains and . Rename to , and remove or .
data-bs-toggle="collapse"data-bs-toggle="drawer".collapse.navbar-collapse<dialog class="drawer">.drawer-header.drawer-body.navbar-expand-md.md:navbar-expand.navbar-light.navbar-dark使用原生 元素。重命名后的 无法正常工作。
<dialog><div class="drawer">html
<!-- v5 -->
<div class="offcanvas offcanvas-start" id="menu">...</div>
<!-- v6 -->
<dialog class="drawer drawer-start" id="menu">...</dialog>对于响应式导航栏,将 改为 。将 替换为包含 和 的 。将 重命名为 ,并移除 或 。
data-bs-toggle="collapse"data-bs-toggle="drawer".collapse.navbar-collapse.drawer-header.drawer-body<dialog class="drawer">.navbar-expand-md.md:navbar-expand.navbar-light.navbar-darkAccordion
Accordion(手风琴)
Replace Collapse JS with native /. The attribute creates exclusive groups (replaces ). Add SVG inside . Remove and . New modifiers: for compact padding and type, to space items as separate rounded cards.
<details><summary>namedata-bs-parent.accordion-icon<summary>.accordion-button.accordion-collapse.accordion-sm.accordion-gaphtml
<!-- v5 -->
<div class="accordion" id="myAccordion">
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button" data-bs-toggle="collapse" data-bs-target="#collapseOne">
Item 1
</button>
</h2>
<div id="collapseOne" class="accordion-collapse collapse show" data-bs-parent="#myAccordion">
<div class="accordion-body">Content</div>
</div>
</div>
</div>
<!-- v6 -->
<div class="accordion">
<details class="accordion-item" name="myAccordion" open>
<summary class="accordion-header">
Item 1
<svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg>
</summary>
<div class="accordion-body">Content</div>
</details>
</div>用原生 / 替换 Collapse JS。 属性用于创建互斥组(替代 )。在 内添加 SVG。移除 和 。
新增修饰类: 用于紧凑内边距和字体, 用于将条目间距设为独立的圆角卡片样式。
<details><summary>namedata-bs-parent<summary>.accordion-icon.accordion-button.accordion-collapse.accordion-sm.accordion-gaphtml
<!-- v5 -->
<div class="accordion" id="myAccordion">
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button" data-bs-toggle="collapse" data-bs-target="#collapseOne">
Item 1
</button>
</h2>
<div id="collapseOne" class="accordion-collapse collapse show" data-bs-parent="#myAccordion">
<div class="accordion-body">Content</div>
</div>
</div>
</div>
<!-- v6 -->
<div class="accordion">
<details class="accordion-item" name="myAccordion" open>
<summary class="accordion-header">
Item 1
<svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg>
</summary>
<div class="accordion-body">Content</div>
</details>
</div>Cards
Cards(卡片)
Review card markup and any custom card CSS. v6 changes card borders, layout, and several helper classes.
- owns the background, outer border, radius, shadow, and height. Headers and footers draw only their divider border.
.card - is optional. It is now a flex column that removes direct-child block margins and uses
.card-bodyfor spacing. Add--card-body-gapfor a horizontal body..flex-row - Keep on list groups inside cards. Do not add
.list-group-flush; that class is not available..card-list - and
.card-titleno longer add styles. Keep them only as project hooks..card-textstill reduces the gap above the subtitle..card-subtitle - is removed. Use normal links and flex or gap utilities when you need a link row.
.card-link - Use for horizontal cards. Use
.card-rowor.card-subtlefor the new visual variants..card-translucent - Card groups now use a container query. Add to a parent or the cards remain stacked.
.contains-inline
检查卡片标记和任何自定义卡片 CSS。v6 更改了卡片的边框、布局和几个辅助类。
- 负责背景、外边框、圆角、阴影和高度。页眉和页脚仅绘制自身的分隔边框。
.card - 是可选的。它现在是一个 flex 列,会移除直接子元素的块级外边距,并使用
.card-body控制间距。添加--card-body-gap可实现水平 body 布局。.flex-row - 卡片内的列表组保留 。不要添加
.list-group-flush;该类不可用。.card-list - 和
.card-title不再添加样式。仅将它们作为项目的钩子保留。.card-text仍然会减少副标题上方的间距。.card-subtitle - 已移除。当需要链接行时,使用普通链接和 flex 或 gap 工具类。
.card-link - 水平卡片使用 。新的视觉变体使用
.card-row或.card-subtle。.card-translucent - 卡片组现在使用容器查询。在父元素上添加 ,否则卡片将保持堆叠状态。
.contains-inline
Menu (was Dropdown)
Menu(原 Dropdown)
Remove wrapper and . Flatten to . Toggle and are siblings.
.dropdown.dropdown-toggle<ul><li><a><div><a>.menuhtml
<!-- v5 -->
<div class="dropdown">
<button class="btn dropdown-toggle" data-bs-toggle="dropdown">Menu</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Other</a></li>
</ul>
</div>
<!-- v6 -->
<button class="btn-solid theme-secondary" data-bs-toggle="menu">Menu</button>
<div class="menu">
<a class="menu-item" href="#">Action</a>
<hr class="menu-divider">
<a class="menu-item" href="#">Other</a>
</div>移除 包装器和 。将 扁平化为 。触发器和 是兄弟元素。
.dropdown.dropdown-toggle<ul><li><a><div><a>.menuhtml
<!-- v5 -->
<div class="dropdown">
<button class="btn dropdown-toggle" data-bs-toggle="dropdown">Menu</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Other</a></li>
</ul>
</div>
<!-- v6 -->
<button class="btn-solid theme-secondary" data-bs-toggle="menu">Menu</button>
<div class="menu">
<a class="menu-item" href="#">Action</a>
<hr class="menu-divider">
<a class="menu-item" href="#">Other</a>
</div>Close button
关闭按钮
The markup does not change — stays an empty element. Do not add a child SVG (that double-renders the icon). What changed is internal: v6 draws the icon with a CSS () over , so the button now inherits the current text instead of a fixed image.
.btn-closemask--btn-close-iconbackground-color: currentcolorcolorhtml
<!-- v5 and v6 — identical markup -->
<button type="button" class="btn-close" aria-label="Close"></button>Because the icon is , the v5 variant is removed — to get a light close button, set the text color (e.g. place it in a dark context or add a / utility) instead.
currentcolor.btn-close-white.theme-*.fg-*color标记没有变化—— 仍然是空元素。不要添加子 SVG(会导致图标重复渲染)。变化在于内部实现:v6 使用 CSS ()叠加 绘制图标,因此按钮现在继承当前文本的 ,而非使用固定图片。
.btn-closemask--btn-close-iconbackground-color: currentcolorcolorhtml
<!-- v5 and v6 — identical markup -->
<button type="button" class="btn-close" aria-label="Close"></button>由于图标使用 ,v5 的 变体已被移除——要获得浅色关闭按钮,请设置文本颜色(例如将其放在深色 上下文中,或添加 / 工具类)。
currentcolor.btn-close-white.theme-*.fg-*colorCheckbox
Checkbox(复选框)
Apply directly on the . No wrapper and no inline SVG — the mark is a CSS on . Radios () follow the same pattern. Switches keep a wrapper around the input.
.check<input>mask::before.radio.switchhtml
<!-- v5 -->
<div class="form-check">
<input class="form-check-input" type="checkbox" id="check1">
<label class="form-check-label" for="check1">Check me</label>
</div>
<!-- v6 -->
<div class="form-field">
<input type="checkbox" id="check1" class="check">
<label for="check1">Check me</label>
</div>Radio and switch equivalents:
html
<!-- v6 radio -->
<div class="form-field">
<input type="radio" id="radio1" class="radio">
<label for="radio1">Pick me</label>
</div>
<!-- v6 switch -->
<div class="form-field">
<div class="switch">
<input type="checkbox" id="switch1" role="switch" switch>
</div>
<label for="switch1">Toggle me</label>
</div>直接在 上应用 。无需包装器,也无需内联 SVG——对勾是 上的 CSS 。单选框()遵循相同模式。开关(Switch)在输入框外保留 包装器。
<input>.check::beforemask.radio.switchhtml
<!-- v5 -->
<div class="form-check">
<input class="form-check-input" type="checkbox" id="check1">
<label class="form-check-label" for="check1">Check me</label>
</div>
<!-- v6 -->
<div class="form-field">
<input type="checkbox" id="check1" class="check">
<label for="check1">Check me</label>
</div>Radio 和 switch 等效示例:
html
<!-- v6 radio -->
<div class="form-field">
<input type="radio" id="radio1" class="radio">
<label for="radio1">Pick me</label>
</div>
<!-- v6 switch -->
<div class="form-field">
<div class="switch">
<input type="checkbox" id="switch1" role="switch" switch>
</div>
<label for="switch1">Toggle me</label>
</div>Toggle buttons
切换按钮
Input is now nested inside the label. goes on the label. No / needed.
.btn-checkidforhtml
<!-- v5 -->
<input type="checkbox" class="btn-check" id="toggle1" autocomplete="off">
<label class="btn btn-outline-primary" for="toggle1">Toggle</label>
<!-- v6 -->
<label class="btn-check btn-solid theme-primary">
<input type="checkbox" autocomplete="off">
Toggle
</label>输入框现在嵌套在标签内部。 应用在标签上。无需 /。
.btn-checkidforhtml
<!-- v5 -->
<input type="checkbox" class="btn-check" id="toggle1" autocomplete="off">
<label class="btn btn-outline-primary" for="toggle1">Toggle</label>
<!-- v6 -->
<label class="btn-check btn-solid theme-primary">
<input type="checkbox" autocomplete="off">
Toggle
</label>Range
Range(滑块)
.form-range.form-range-inputhtml
<!-- v5 -->
<input type="range" class="form-range">
<!-- v6 -->
<div class="form-range">
<input type="range" class="form-range-input">
</div>.form-range.form-range-inputhtml
<!-- v5 -->
<input type="range" class="form-range">
<!-- v6 -->
<div class="form-range">
<input type="range" class="form-range-input">
</div>Breadcrumbs
Breadcrumbs(面包屑)
Add on elements. Add empty separators between items (replaces pseudo-elements). An empty divider renders a default chevron via a CSS mask. The default bottom margin is gone (v5 used ).
.breadcrumb-link<a>.breadcrumb-divider::before$spacerhtml
<!-- v5 -->
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item active">Library</li>
</ol>
<!-- v6 -->
<ol class="breadcrumb">
<li class="breadcrumb-item"><a class="breadcrumb-link" href="#">Home</a></li>
<li class="breadcrumb-divider"></li>
<li class="breadcrumb-item"><a class="breadcrumb-link active" href="#">Library</a></li>
</ol>在 元素上添加 。在条目之间添加空的 分隔符(替代 伪元素)。空分隔符通过 CSS mask 渲染默认的 Chevron 图标。默认的下边距已移除(v5 使用 )。
<a>.breadcrumb-link.breadcrumb-divider::before$spacerhtml
<!-- v5 -->
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item active">Library</li>
</ol>
<!-- v6 -->
<ol class="breadcrumb">
<li class="breadcrumb-item"><a class="breadcrumb-link" href="#">Home</a></li>
<li class="breadcrumb-divider"></li>
<li class="breadcrumb-item"><a class="breadcrumb-link active" href="#">Library</a></li>
</ol>Step 4: JavaScript
步骤4:JavaScript
ESM-only
仅支持 ESM
All dist files are now ES modules. No more UMD bundles or global.
window.bootstraphtml
<!-- v5 -->
<script src="bootstrap.bundle.min.js"></script>
<!-- v6 -->
<script type="module" src="bootstrap.bundle.min.js"></script>Replace global namespace access with imports:
js
// v5 — global namespace
const tooltip = bootstrap.Tooltip.getOrCreateInstance(el)js
// v6 — explicit import
import { Tooltip } from './bootstrap.bundle.min.js'
const tooltip = Tooltip.getOrCreateInstance(el)Data API initialization still runs automatically after you add . Apply the component and data attribute renames in this skill. Bundler imports () work as before.
type="module"import { X } from 'bootstrap'The bundled build includes Floating UI and Vanilla Calendar Pro. The standalone build requires installed peers or a browser import map.
所有发布文件现在都是 ES 模块。不再提供 UMD 包或 全局对象。
window.bootstraphtml
<!-- v5 -->
<script src="bootstrap.bundle.min.js"></script>
<!-- v6 -->
<script type="module" src="bootstrap.bundle.min.js"></script>用导入替换全局命名空间访问:
js
// v5 — 全局命名空间
const tooltip = bootstrap.Tooltip.getOrCreateInstance(el)js
// v6 — 显式导入
import { Tooltip } from './bootstrap.bundle.min.js'
const tooltip = Tooltip.getOrCreateInstance(el)添加 后,数据 API 初始化仍然会自动运行。请应用本技能中提到的组件和数据属性重命名。打包器导入()的工作方式与之前相同。
type="module"import { X } from 'bootstrap'捆绑构建版本包含 Floating UI 和 Vanilla Calendar Pro。独立构建版本需要安装 peer 依赖或浏览器 import map。
Renamed JS exports
重命名的 JS 导出
| v5 | v6 |
|---|---|
| |
| |
| |
| v5 | v6 |
|---|---|
| |
| |
| |
Popper -> Floating UI
Popper -> Floating UI
Replace with . Rename the option to on Tooltip, Popover, and Menu.
@popperjs/core@floating-ui/dompopperConfigfloatingConfig将 替换为 。将 Tooltip、Popover 和 Menu 上的 选项重命名为 。
@popperjs/core@floating-ui/dompopperConfigfloatingConfigLifecycle methods return a promise
生命周期方法返回 Promise
show()hide()toggle()close()awaitshown.bs.*hidden.bs.*Hover and focus tooltips stay open while the pointer or focus is on the tip itself (WCAG 1.4.13). Press Escape or leave both the trigger and the tip to hide it.
Popup datepickers close on outside interaction, on <kbd>Escape</kbd>, or when focus leaves the input and calendar.
show()hide()toggle()close()awaitshown.bs.*hidden.bs.*悬停和聚焦的 Tooltip 在指针或焦点位于提示本身时会保持打开状态(符合 WCAG 1.4.13)。按 Escape 或同时离开触发器和提示即可隐藏。
弹出式日期选择器在外部交互、按下 <kbd>Escape</kbd> 或焦点离开输入框和日历的时候会关闭。
TypeScript declarations
TypeScript 声明
Bootstrap’s source is now TypeScript. The package includes type declarations, so remove . Deep imports resolve to compiled files.
@types/bootstrap.jsjs/distBootstrap 的源码现在是 TypeScript 编写的。包中包含类型声明,因此请移除 。深层 导入会解析到编译后的 文件。
@types/bootstrap.jsjs/distRemoved
已移除
- jQuery support
- /
bootstrap.esm.js— usebootstrap.esm.min.jsbootstrap.js js/index.umd.js
- jQuery 支持
- /
bootstrap.esm.js—— 使用bootstrap.esm.min.jsbootstrap.js js/index.umd.js
Validation JS
验证 JS
js
// v5
document.querySelectorAll('.needs-validation')
form.classList.add('was-validated')
// v6
document.querySelectorAll('form[data-bs-validate]')
// Remove the was-validated line entirelyjs
// v5
document.querySelectorAll('.needs-validation')
form.classList.add('was-validated')
// v6
document.querySelectorAll('form[data-bs-validate]')
// 完全移除 was-validated 相关代码Step 5: Sass
步骤5:Sass
Renamed files
重命名的文件
| v5 | v6 |
|---|---|
| |
| Removed (merged into |
| Removed |
| |
| |
| |
| |
| Removed |
| Removed |
| v5 | v6 |
|---|---|
| |
| 已移除(合并到 |
| 已移除 |
| |
| |
| |
| |
| 已移除 |
| 已移除 |
Renamed variables and functions
重命名的变量与函数
| v5 | v6 |
|---|---|
| |
| Removed — see the radius scale below |
| Use secondary color |
| |
| |
| |
| |
| |
| Removed — icon uses |
| |
| |
| |
| Removed — use PostCSS instead |
| v5 | v6 |
|---|---|
| |
| 已移除——参见下方的圆角刻度 |
| 使用次要颜色 |
| |
| |
| |
| |
| |
| 已移除——图标使用 |
| |
| |
循环 mixin 中的 | |
(CSS 变量前缀) | 已移除——改用 PostCSS |
Border radius scale
圆角刻度
The variables are gone. v6 uses a single base and a map (keys –, e.g. , ), exposed as – tokens (plus ). The utilities now span – and map to different values than v5, so shift class numbers up to keep the same roundness (e.g. → , → ). Override the base or the map entries rather than the old per-size variables:
$border-radius-*$radius: .5rem$radii095: $radius9: $radius * 2--radius-0--radius-9--radius-pill.rounded-*09.rounded-1.rounded-3.rounded-3.rounded-5scss
// $radius lives in _config.scss, so configure that module before loading Bootstrap
@use "bootstrap/scss/config" with (
$radius: .375rem // scales the whole map
);
@use "bootstrap/scss/bootstrap";$border-radius-*$radius: .5rem$radii095: $radius9: $radius * 2--radius-0--radius-9--radius-pill.rounded-*09.rounded-1.rounded-3.rounded-3.rounded-5scss
// $radius 定义在 _config.scss 中,因此请在加载 Bootstrap 前配置该模块
@use "bootstrap/scss/config" with (
$radius: .375rem // 按比例缩放整个映射
);
@use "bootstrap/scss/bootstrap";Removed (no replacement)
已移除(无替代方案)
$nested-kbd-font-weight- — dark mode is always compiled
$enable-dark-mode $enable-validation-icons- ,
$enable-caret,$caret-width,$caret-vertical-align$caret-spacing - ,
$accordion-button-focus-border-color$tooltip-arrow-color - ,
$popover-arrow-color$popover-arrow-outer-color - ,
$alert-bg-scale,$alert-border-scale$alert-color-scale - ,
$list-group-item-bg-scale$list-group-item-color-scale - ,
$carousel-dark-indicator-active-bg$carousel-dark-control-icon-filter $dropdown-header-padding- All variables — use
*-focus-box-shadowmixin withfocus-ring()CSS custom properties--focus-ring-* - RFS mixins — use for responsive sizing
clamp() - mixin
create-css-vars() - Caret mixins (,
caret(),caret-down(),caret-up(),caret-end()) — add an icon to the toggle markup insteadcaret-start() - ,
muted,black-50from text color utilities mapwhite-50
$nested-kbd-font-weight- —— 深色模式始终编译
$enable-dark-mode $enable-validation-icons- 、
$enable-caret、$caret-width、$caret-vertical-align$caret-spacing - 、
$accordion-button-focus-border-color$tooltip-arrow-color - 、
$popover-arrow-color$popover-arrow-outer-color - 、
$alert-bg-scale、$alert-border-scale$alert-color-scale - 、
$list-group-item-bg-scale$list-group-item-color-scale - 、
$carousel-dark-indicator-active-bg$carousel-dark-control-icon-filter $dropdown-header-padding- 所有 变量——使用
*-focus-box-shadowmixin 配合focus-ring()CSS 自定义属性--focus-ring-* - RFS mixins——使用 实现响应式尺寸
clamp() - mixin
create-css-vars() - 插入符号 mixin(、
caret()、caret-down()、caret-up()、caret-end())——改为在触发器标记中添加图标caret-start() - 文本颜色工具映射中的 、
muted、black-50white-50
Utility API
工具类 API
Removed , , and options. Use map and instead.
css-varcss-variable-namelocal-varspropertyvariables已移除 、 和 选项。改用 映射和 。
css-varcss-variable-namelocal-varspropertyvariablesTheme maps merge
主题映射合并
$theme-colors$theme-bgs$theme-fgs$theme-borders$badge-variantsdefaults()@use ... with ()nullRoot tokens emit on . Repeat overrides on if you use shadow DOM.
:root, :host:root:host$theme-colors$theme-bgs$theme-fgs$theme-borders$badge-variantsdefaults()@use ... with ()null根令牌会在 上输出。如果你使用 Shadow DOM,请在 上重复 的覆盖。
:root, :host:host:rootRebuilt behavior & new components
重构的行为与新增组件
Beyond the renames above, several things changed how a v5 project behaves or what's available. Check the docs for full markup/options.
除了上述重命名之外,还有一些功能改变了 v5 项目的行为方式,或新增了可用功能。完整的标记/选项请参阅文档。
Carousel — rebuilt on CSS scroll-snap
Carousel(轮播)——基于 CSS scroll-snap 重构
The markup ( → → ) and the JS API (////, / events) are preserved, but several things changed:
.carousel.carousel-inner.carousel-itemnextprevtocyclepauseslideslid- →
ride(boolean, opt-in).autoplaybecomesdata-bs-ride="carousel";data-bs-autoplay="true"becomes{ ride: 'carousel' }. Default is{ autoplay: true }, so a v5 carousel that auto-advanced now sits still until you opt in. Interacting with an autoplaying carousel now permanently stops it (WCAG 2.2.2).autoplay: false - →
wrap.ends→wrap: true(or the new defaultends: "wrap");"loop"→wrap: false. Set viaends: "stop". Thedata-bs-endsoption is removed (native scroll handles it).touch - Removed classes: (compose a
.carousel-control-prev/next+.btn-icon+data-bs-slide),.carousel-icon-prev/next(use your own markup),.carousel-caption(use.carousel-dark),data-bs-theme="dark"(now the default), and the transitional.carousel-stacked. Overlaid controls now require.carousel-item-start/end/next/prev. Control-icon classes renamed.carousel-overlay→.carousel-control-prev-icon(and.carousel-icon-prev).-next
标记( → → )和 JS API(////、/ 事件)保持不变,但有以下变化:
.carousel.carousel-inner.carousel-itemnextprevtocyclepauseslideslid- →
ride(布尔值,需主动开启)。autoplay变为data-bs-ride="carousel";data-bs-autoplay="true"变为{ ride: 'carousel' }。默认值为{ autoplay: true },因此 v5 中自动播放的轮播现在会静止,直到你主动开启。与自动播放的轮播交互后会永久停止播放(符合 WCAG 2.2.2)。autoplay: false - →
wrap。ends→wrap: true(或新的默认值ends: "wrap");"loop"→wrap: false。通过ends: "stop"设置。data-bs-ends选项已移除(由原生滚动处理)。touch - 已移除的类: (组合使用
.carousel-control-prev/next+.btn-icon+data-bs-slide实现)、.carousel-icon-prev/next(使用你自己的标记)、.carousel-caption(使用.carousel-dark)、data-bs-theme="dark"(现在是默认值),以及过渡用的.carousel-stacked。叠加的控件现在需要.carousel-item-start/end/next/prev。控件图标类已重命名:.carousel-overlay→.carousel-control-prev-icon(以及.carousel-icon-prev)。-next
ScrollSpy — rebuilt on IntersectionObserver
ScrollSpy(滚动监听)——基于 IntersectionObserver 重构
The markup and the event are unchanged, but detection is now driven by an activation line (no scroll-position polling), and the options changed:
data-bs-spy="scroll"activate.bs.scrollspy- Removed the deprecated and
offsetoptions (deprecated since v5.1.3) — no longer parsed.method - Added (default
topMargin) — positions the activation line as a12%or%value from the top of the scroll root (e.g.pxto sit below a sticky navbar). This is the everyday knob; use it instead of96px.rootMargin - is now an advanced override (default
rootMargin, wasnull); when set it takes precedence over'0px 0px -25%'and is passed straight to the observer.topMargin - default changed from
thresholdto[0.1, 0.5, 1].[0] - With , clicking a link now restores the URL hash (
smoothScroll) and moves focus to the target once the scroll settles (better keyboard/AT nav).history.replaceState - Target s are resolved with
id, so ids with dots, colons, slashes, or percent-encoding work without manual escaping.getElementById
data-bs-spy="scroll"activate.bs.scrollspy- 已移除弃用的 和
offset选项(自 v5.1.3 起弃用)——不再解析。method - 新增 (默认
topMargin)——将激活线定位在滚动根元素顶部的百分比或像素值位置(例如12%可让激活线位于粘性导航栏下方)。这是常用的调节参数;请用它替代96px。rootMargin - 现在是高级覆盖选项(默认
rootMargin,之前为null);设置后它会优先于'0px 0px -25%',并直接传递给观察者。topMargin - 默认值从
threshold改为[0.1, 0.5, 1]。[0] - 启用 后,点击链接现在会恢复 URL 哈希(
smoothScroll),并在滚动结束后将焦点移到目标元素(更好的键盘/辅助技术导航体验)。history.replaceState - 目标 通过
id解析,因此包含点、冒号、斜杠或百分号编码的 id 无需手动转义即可正常工作。getElementById
Collapse — simplified state and transitions
Collapse(折叠)——简化的状态与过渡
- Remove selectors and tests that depend on . Collapse now toggles
.collapsingand uses native size interpolation..show - Replace trigger selectors with
.collapsed.[aria-expanded="false"] - Remove the constructor option. Call
toggleorshow()when initialization must change state.hide()
- 移除依赖 的选择器和测试。Collapse 现在切换
.collapsing并使用原生尺寸插值。.show - 将触发器的 选择器替换为
.collapsed。[aria-expanded="false"] - 移除 构造函数选项。当初始化需要改变状态时,调用
toggle或show()。hide()
New components (didn't exist in v5)
新增组件(v5 中不存在)
| Component | Trigger / hook | Purpose |
|---|---|---|
| Combobox | | Filterable/autocomplete select built on Menu |
| Chip / Chip input | | Tags / tokens + interactive entry |
| Datepicker | | Date picker (peer dep |
| Range | | Enhanced range slider with a value bubble |
| Strength | | Password-strength meter |
| OTP input | | One-time-code input |
| Nav overflow | | Collapses overflowing nav items into a menu |
| Toggler | | Generic class/attribute toggler |
| Submenu | | Nested menus ( |
| Stepper | | Multi-step workflow (CSS-only) |
| Avatar | | Avatars with sizes, status, |
| Form adorn | | Icon/text decoration on inputs (CSS-only) |
| Prose | | Rich-typography scoping (CSS-only) |
| 组件 | 触发器/钩子 | 用途 |
|---|---|---|
| Combobox | | 基于 Menu 构建的可筛选/自动完成选择器 |
| Chip / Chip input | | 标签/令牌 + 交互式输入 |
| Datepicker | | 日期选择器(peer 依赖 |
| Range | | 带数值气泡的增强型滑块 |
| Strength | | 密码强度指示器 |
| OTP input | | 一次性验证码输入框 |
| Nav overflow | | 将溢出的导航项折叠到菜单中 |
| Toggler | | 通用类/属性切换器 |
| Submenu | (Menu 内的) | 嵌套菜单( |
| Stepper | | 多步骤工作流(仅 CSS) |
| Avatar | | 带尺寸、状态的头像,支持 |
| Form adorn | | 输入框上的图标/文本装饰(仅 CSS) |
| Prose | | 富文本排版作用域(仅 CSS) |
Removed / changed internals
已移除/变更的内部实现
- ,
util/backdrop.js, andutil/focustrap.jsremoved. Dialog and Drawer use the nativeutil/scrollbar.jselement, which provides the backdrop (<dialog>), the focus trap, and an inert top layer; the body scroll-lock is now CSS (::backdrop). If you imported:root.dialog-open,bootstrap/js/src/util/backdrop, or.../focustrapdirectly, they're gone..../scrollbar - CSS . Component styles are wrapped in cascade layers (
@layer). Author CSS outside any layer now wins over Bootstrap regardless of source order — if your v5 overrides relied on specificity or load order, re-check them.colors, theme, config, root, reboot, layout, content, forms, components, custom, helpers, utilities - variables removed. The
--bs-*-rgbSass vars and$*-rgbcustom properties are gone. Replace--bs-*-rgbwithrgba(var(--bs-primary-rgb), .5)(or use the color directly).color-mix(in oklab, var(--bs-primary), transparent 50%)
- 、
util/backdrop.js和util/focustrap.js已移除。 Dialog 和 Drawer 使用原生util/scrollbar.js元素,它提供了背景(<dialog>)、焦点陷阱和惰性顶层;body 滚动锁定现在由 CSS 实现(::backdrop)。如果你直接导入了:root.dialog-open、bootstrap/js/src/util/backdrop或.../focustrap,它们已不存在。.../scrollbar - CSS 。 组件样式被包裹在级联层中(
@layer)。任何层外的作者 CSS 现在都会优先于 Bootstrap,无论源码顺序如何——如果你的 v5 覆盖依赖于特异性或加载顺序,请重新检查。colors, theme, config, root, reboot, layout, content, forms, components, custom, helpers, utilities - 变量已移除。
--bs-*-rgbSass 变量和$*-rgb自定义属性已全部移除。将--bs-*-rgb替换为rgba(var(--bs-primary-rgb), .5)(或直接使用颜色)。color-mix(in oklab, var(--bs-primary), transparent 50%)
Step 6: Verify
步骤6:验证
- Build the project and fix any compilation errors.
- Search for remaining v5 patterns:
- classes/attributes (should be
modal)dialog - (should be
offcanvas)drawer - (should be
dropdown)menu - ,
d-md-,d-lg-, etc. (should usecol-md-prefix syntax)md: - ,
btn-primary(should usebtn-outline-).btn-solid .theme-* - ,
.text-primary(should be.text-danger).fg-* - in Sass (should be
@import)@use - (should be
form-select)form-control - ,
was-validated(should beneeds-validation)data-bs-validate - (should be
popperConfig)floatingConfig - (should be
form-check,check, orradio)switch - /
var(--bs-*-rgb)(removed — usergba(var(--bs-…-rgb))color-mix() - Sass vars (removed — use
$border-radius/$radius/$radii)--radius-* - child inside
<svg>(should be empty — icon is a CSS mask).btn-close - (removed — set text
.btn-close-whiteinstead)color - (must be a native
<div class="drawer">)<dialog class="drawer"> - (renamed to
data-bs-ride);data-bs-autoplaycarousel option (nowwrap:)ends: - ,
.carousel-control-prev/next,.carousel-caption,.carousel-dark(all removed).carousel-stacked - –
.fs-1(should be.fs-6….fs-4xl).fs-md - /
.link-offset-*(now.link-underline-*/.underline-offset-*).underline-* - ScrollSpy /
offsetoptions (removed — usemethod)topMargin - inline SVG inside (icon is a CSS mask on the input)
.check - full-map replacements (v6 merges via
$theme-colors)defaults() - ,
.collapsingtrigger selectors, and the Collapse.collapsedoptiontoggle - responsive stacks, CSS Grid, navbars, list groups, card groups, and stacked tables without a query container
- Test in browser — v6 requires support for and
oklch().color-mix()
- 构建项目并修复所有编译错误。
- 搜索剩余的 v5 模式:
- 类/属性(应为
modal)dialog - (应为
offcanvas)drawer - (应为
dropdown)menu - 、
d-md-、d-lg-等(应使用col-md-前缀语法)md: - 、
btn-primary(应使用btn-outline-).btn-solid .theme-* - 、
.text-primary(应为.text-danger).fg-* - Sass 中的 (应为
@import)@use - (应为
form-select)form-control - 、
was-validated(应为needs-validation)data-bs-validate - (应为
popperConfig)floatingConfig - (应为
form-check、check或radio)switch - /
var(--bs-*-rgb)(已移除——使用rgba(var(--bs-…-rgb))color-mix() - Sass 变量(已移除——使用
$border-radius/$radius/$radii)--radius-* - 内的子
.btn-close(应为空——图标是 CSS mask)<svg> - (已移除——改为设置文本
.btn-close-white)color - (必须是原生
<div class="drawer">)<dialog class="drawer"> - (已重命名为
data-bs-ride);轮播的data-bs-autoplay选项(现在是wrap:)ends: - 、
.carousel-control-prev/next、.carousel-caption、.carousel-dark(均已移除).carousel-stacked - –
.fs-1(应为.fs-6….fs-4xl).fs-md - /
.link-offset-*(现在是.link-underline-*/.underline-offset-*).underline-* - ScrollSpy 的 /
offset选项(已移除——使用method)topMargin - 内的内联 SVG(图标是输入框上的 CSS mask)
.check - 全映射替换(v6 通过
$theme-colors合并)defaults() - 、
.collapsing触发器选择器,以及 Collapse 的.collapsed选项toggle - 没有查询容器的响应式堆叠、CSS Grid、导航栏、列表组、卡片组和堆叠表格
- 在浏览器中测试——v6 需要支持 和
oklch()。color-mix()