# Bootstrap（前端框架）

**Bootstrap** 是一个免费、开源的前端框架，提供预制的 HTML 与 CSS 规范、响应式网格系统、工具类以及 [JavaScript](https://www.edgepedia.org/zh/javascript) 插件，用于构建网站和 Web 应用。它由设计师马克·奥托（Mark Otto）和开发者雅各布·桑顿（Jacob Thornton）于 2010 年中期在 Twitter 创建，公开发布前名为 Twitter Blueprint，现已成为世界上使用最广泛的前端框架和开源项目之一。<sup>[1](https://getbootstrap.com/docs/4.0/about/history/)</sup> 该项目自称“世界上最流行的 HTML、CSS 和 JS 库”，当前版本为 v5.3.8。<sup>[2](https://github.com/twbs/bootstrap/blob/main/config.yml)</sup>

| 关键事实 | 详情 |
|---|---|
| 创建者 | 马克·奥托（@mdo）与雅各布·桑顿（@fat），任职于 Twitter；自 2010 年中期起以 Twitter Blueprint 之名开发<sup>[1](https://getbootstrap.com/docs/4.0/about/history/)</sup> |
| 首次发布 | 2011 年 8 月 19 日，作为开源项目发布于 GitHub<sup>[3](https://blog.x.com/developer/en_us/a/2011/bootstrap-twitter)</sup> |
| 当前版本 | 5.3.8<sup>[2](https://github.com/twbs/bootstrap/blob/main/config.yml)</sup> |
| 网格 | 12 列，六个默认响应式层级（xs 为 576 px 以下，直至 1400 px 及以上的 xxl），1.5rem 间距，基于弹性盒子构建<sup>[4](https://getbootstrap.com/docs/5.3/layout/grid/)</sup> |
| 样式技术栈 | 以 Sass 编写；编译后的 CSS 包含带 `bs-` 前缀的 CSS 自定义属性，用于运行时定制<sup>[5](https://getbootstrap.com/docs/5.3/customize/sass/)</sup><sup> • </sup><sup>[6](https://getbootstrap.com/docs/5.3/customize/css-variables/)</sup> |
| JavaScript | 自 v5 起使用原生 JavaScript 插件（不再依赖 jQuery）；内置 Popper，用于下拉菜单、弹出框和工具提示的定位<sup>[7](https://getbootstrap.com/docs/5.2/migration/)</sup> |
| 许可证 | 代码采用 MIT 许可证；文档采用知识共享许可<sup>[8](https://blog.getbootstrap.com/2021/05/05/bootstrap-5/)</sup> |

## 历史

Bootstrap 最初是为了解决 Twitter 内部的一个实际问题：工程师各自使用自己熟悉的库，由此产生的不一致使应用难以扩展和维护。该项目在 Twitter 的第一个黑客周期间加速推进，在公开发布前作为公司内部样式指南使用了一年多。<sup>[1](https://getbootstrap.com/docs/4.0/about/history/)</sup> 2011 年 8 月 19 日的发布公告介绍了一套前端工具包，涵盖排版、表单、按钮、表格、网格和导航，经 gzip 压缩后仅 6k，使用 Less CSS 预处理器构建。<sup>[3](https://blog.x.com/developer/en_us/a/2011/bootstrap-twitter)</sup>

每个大版本都标志着一次架构转变。Bootstrap 2 以可选样式表的形式加入了响应式功能；Bootstrap 3 重写了该库，以移动优先的方式使响应式成为默认行为。<sup>[1](https://getbootstrap.com/docs/4.0/about/history/)</sup> Bootstrap 4 将源码从 Less 迁移到 Sass，并将网格迁移至 CSS 弹性盒子。<sup>[9](https://getbootstrap.com/docs/4.0/about/overview/)</sup> Bootstrap 5 历经三个 alpha 和三个 beta 版本后，于 2021 年 5 月 5 日发布稳定版，取消了 jQuery 依赖并用普通 JavaScript 重写了插件，从 Popper v1.x 升级到 Popper v2.x，以 Dart Sass 替换了已弃用的 Libsass 编译器，并放弃了对 [Internet Explorer](https://www.edgepedia.org/zh/internet-explorer) 10 和 11 以及若干旧版浏览器的支持。<sup>[8](https://blog.getbootstrap.com/2021/05/05/bootstrap-5/)</sup><sup> • </sup><sup>[7](https://getbootstrap.com/docs/5.2/migration/)</sup> 版本 5 还新增了从右到左（RTL）样式表支持。<sup>[7](https://getbootstrap.com/docs/5.2/migration/)</sup>

此后的 5.x 版本延续了这一模式。v5.2.0 将 CSS 变量应用于 `.btn` 等组件基类，以实现实时定制，并引入新的 `_maps.scss` 文件以修复 Sass 映射的继承问题。v5.3.0 增加了包括深色模式在内的内置颜色模式，并扩展了主题色变量。<sup>[10](https://getbootstrap.com/docs/5.3/migration/)</sup> 该项目还发布了 v6.0 文档，其中将 CSS 变量描述为首选的定制途径，即使在使用 Sass 时也是如此。<sup>[11](https://getbootstrap.com/docs/6.0/getting-started/approach/)</sup>

## 网格系统

Bootstrap 的布局系统是一个移动优先的弹性盒子网格，由容器、行和列构成。它采用十二列系统，包含六个默认响应式层级：xs（576 px 以下）、sm（576 px 及以上）、md（768 px）、lg（992 px）、xl（1200 px）和 xxl（1400 px），每级都定义了容器最大宽度，从 sm 的 540 px 到 xxl 的 1320 px。默认间距宽度为 1.5rem，即列两侧各 0.75rem，列可嵌套、可重新排序。<sup>[4](https://getbootstrap.com/docs/5.3/layout/grid/)</sup>

该网格由 Sass 变量生成，如 `$grid-columns: 12`、`$grid-gutter-width: 1.5rem` 和 `$grid-row-columns: 6`；修改这些值并重新编译即可生成一套新的预定义类，且网格断点值必须以像素为单位设置。<sup>[4](https://getbootstrap.com/docs/5.3/layout/grid/)</sup> 自 Bootstrap 5.1 起，还可选启用基于 CSS 网格布局模块的第二套网格，需通过 Sass 重新编译来开启。<sup>[12](https://getbootstrap.com/docs/5.3/layout/css-grid/)</sup>

## Sass、CSS 变量与工具类

Bootstrap 以 Sass 编写，这是一种为标准 CSS 增加变量、嵌套、混入和函数的 CSS 预处理器。其源 `.scss` 文件使用 Sass 映射来定义设计令牌，使用混入来生成重复模式，编译后生成驱动每个组件和工具类的 CSS。<sup>[5](https://getbootstrap.com/docs/5.3/customize/sass/)</sup> 主要、次要、成功、危险、警告、信息、浅色和深色等主题色定义在 `$theme-colors` Sass 映射中，`.btn-primary` 等组件修饰类则通过遍历该映射生成。<sup>[13](https://getbootstrap.com/docs/5.3/customize/color/)</sup><sup> • </sup><sup>[14](https://getbootstrap.com/docs/5.3/customize/components/)</sup>

编译后的 CSS 还附带 CSS 自定义属性（变量），全部带 `bs-` 前缀以避免与第三方 CSS 冲突，从而无需重新编译 Sass 即可在浏览器中实时定制。前缀本身可通过 `$prefix` Sass 变量配置。<sup>[6](https://getbootstrap.com/docs/5.3/customize/css-variables/)</sup> 自 v5.2.0 起，组件在其基类上携带局部 CSS 变量，因此只需重新赋值 `--bs-btn-bg`、`--bs-btn-hover-bg` 等变量即可构建自定义按钮变体，而无需从头编写新规则。<sup>[10](https://getbootstrap.com/docs/5.3/migration/)</sup>

**工具类。** Bootstrap 生成了大量单一用途的工具类，涵盖间距、颜色、弹性盒子等；例如间距工具类由默认 Sass 映射生成，范围从 0.25rem 到 3rem。<sup>[15](https://getbootstrap.com/docs/5.3/utilities/spacing/)</sup> 这些工具类由一个基于映射和函数的 Sass 工具 API 生成，项目可用其修改或扩展默认的类集合。<sup>[16](https://getbootstrap.com/docs/5.3/utilities/api/)</sup> 该项目的设计指南将工具类视为对抗 CSS 膨胀的手段，把常见的重复属性值对简化为单个类。<sup>[17](https://getbootstrap.com/docs/5.3/extend/approach/)</sup>

## 颜色模式

版本 5.3.0 引入了颜色模式，起初包含默认的浅色模式和新的深色模式。颜色模式由 `data-bs-theme` 属性控制，可应用于 `<html>` 元素以作用于全站，也可限定在单个组件和元素上。全站启用深色模式只需改动一个属性，而将 `$enable-dark-mode` Sass 变量设为 false 即可完全停用该模式。<sup>[18](https://getbootstrap.com/docs/5.3/customize/color-modes/)</sup>

默认实现使用数据属性而非媒体查询，因此应用可以提供用户控制的开关；通过 Sass 变量 `$color-mode-type` 可将输出切换为 `prefers-color-scheme` 媒体查询，以实现自动切换。定义新的 `data-bs-theme` 值并覆盖相关 CSS 变量，即可支持浅色和深色之外的自定义颜色模式。<sup>[18](https://getbootstrap.com/docs/5.3/customize/color-modes/)</sup> 为支持这一点，v5.3.0 扩展了颜色系统，新增 `secondary` 和 `tertiary` 文本色与背景色，以及可随当前颜色模式自适应的 `{color}-bg-subtle`、`{color}-border-subtle` 和 `{color}-text-emphasis` 变量；长期存在的 `.text-muted` 工具类在同一版本中被弃用。<sup>[13](https://getbootstrap.com/docs/5.3/customize/color/)</sup><sup> • </sup><sup>[10](https://getbootstrap.com/docs/5.3/migration/)</sup>

## JavaScript 插件

Bootstrap 的交互组件——包括模态框、下拉菜单、手风琴、工具提示和弹出框——由可选的 JavaScript 插件驱动。插件可单独引入，也可作为编译好的捆绑包引入；捆绑包内含 Popper，即下拉菜单、弹出框和工具提示所使用的定位库，不使用这些组件的项目可以省略它以减小文件体积。<sup>[19](https://getbootstrap.com/docs/5.3/getting-started/introduction/?hsPreviewerApp=blog_post)</sup> 组件通常通过带命名空间的数据属性激活，如 `data-bs-toggle="collapse"`，选项可通过数据属性或编程 API 传入；自 v5.2.0 起，组件还支持实验性的 `data-bs-config` 属性，用于承载 JSON 配置。<sup>[20](https://getbootstrap.com/docs/5.3/components/accordion/)</sup>

尽管 jQuery 不再是依赖项，Bootstrap 5 仍会检测 `window` 对象中的 jQuery，并在存在时将其组件注册到 jQuery 的插件系统中。<sup>[21](https://getbootstrap.com/docs/5.3/getting-started/javascript/)</sup> 文档指出了一个实际限制：Bootstrap CSS 可与任何框架配合使用，但 Bootstrap JavaScript 与 React、Vue 和 Angular 并不完全兼容，因为这些框架假定自己完全掌握 DOM，两者可能试图修改同一元素。对于这些技术栈，项目推荐使用框架专用包，如 React Bootstrap、BootstrapVueNext 或 ng-bootstrap。<sup>[21](https://getbootstrap.com/docs/5.3/getting-started/javascript/)</sup>

## 可访问性

Bootstrap 的文档指出，只要作者正确实现其标记、样式和脚本，使用它构建的项目即可满足 WCAG 2.2、Section 508 及类似标准。交互组件在设计上兼顾触摸、鼠标和键盘用户，并使用 WAI-ARIA 角色和属性，但由于组件刻意保持通用，作者可能需要补充更多 ARIA 属性以传达组件的精确功能。<sup>[22](https://getbootstrap.com/docs/5.3/getting-started/accessibility/)</sup>

文档还披露了一个已知限制：默认调色板中的某些颜色组合——用于按钮变体、警报变体和表单验证指示器——可能产生不足的对比度，低于 WCAG 2.2 规定的文本对比度 4.5:1 和非文本对比度 3:1，尤其是在浅色背景上。文档鼓励作者测试其颜色使用情况，并在需要时调整默认值。<sup>[22](https://getbootstrap.com/docs/5.3/getting-started/accessibility/)</sup>

## 分发与生态

Bootstrap 以可直接使用的编译版 CSS 和 JavaScript、源码版 Sass 和 JavaScript 以及通过包管理器和 CDN 的方式分发。编译版下载提供多种独立构建：完整捆绑包、含弹性盒子工具类的纯网格 CSS 文件、纯工具类文件，以及仅含 Reboot 重置的样式文件，每种均有默认版、RTL 版和压缩版。<sup>[23](https://getbootstrap.com/docs/5.3/getting-started/contents/)</sup> npm 包 `bootstrap` 在 5.3.8 版本下报告零运行时依赖，且约有 15,000 个包依赖它。<sup>[24](https://www.npmjs.com/package/bootstrap?activeTab=dependencies)</sup> 代码以 [MIT 许可证](https://www.edgepedia.org/zh/mit-license)发布，文档以[知识共享](https://www.edgepedia.org/zh/creative-commons)许可发布，项目遵循语义化版本规范。<sup>[8](https://blog.getbootstrap.com/2021/05/05/bootstrap-5/)</sup><sup> • </sup><sup>[25](https://github.com/twbs/bootstrap)</sup>

## References

1. [History, Bootstrap v4.0 documentation](https://getbootstrap.com/docs/4.0/about/history/)
2. [bootstrap/config.yml, twbs/bootstrap on GitHub](https://github.com/twbs/bootstrap/blob/main/config.yml)
3. [Bootstrap from Twitter, Twitter Developer Blog (August 19, 2011)](https://blog.x.com/developer/en_us/a/2011/bootstrap-twitter)
4. [Grid system, Bootstrap v5.3 documentation](https://getbootstrap.com/docs/5.3/layout/grid/)
5. [Sass, Bootstrap v5.3 documentation](https://getbootstrap.com/docs/5.3/customize/sass/)
6. [CSS variables, Bootstrap v5.3 documentation](https://getbootstrap.com/docs/5.3/customize/css-variables/)
7. [Migrating to v5, Bootstrap v5.2 documentation](https://getbootstrap.com/docs/5.2/migration/)
8. [Bootstrap 5, Bootstrap Blog (May 5, 2021)](https://blog.getbootstrap.com/2021/05/05/bootstrap-5/)
9. [About, Bootstrap v4.0 documentation](https://getbootstrap.com/docs/4.0/about/overview/)
10. [Migrating to v5, Bootstrap v5.3 documentation](https://getbootstrap.com/docs/5.3/migration/)
11. [Approach, Bootstrap v6.0 documentation](https://getbootstrap.com/docs/6.0/getting-started/approach/)
12. [CSS Grid, Bootstrap v5.3 documentation](https://getbootstrap.com/docs/5.3/layout/css-grid/)
13. [Color, Bootstrap v5.3 documentation](https://getbootstrap.com/docs/5.3/customize/color/)
14. [Components, Bootstrap v5.3 documentation](https://getbootstrap.com/docs/5.3/customize/components/)
15. [Spacing, Bootstrap v5.3 documentation](https://getbootstrap.com/docs/5.3/utilities/spacing/)
16. [Utility API, Bootstrap v5.3 documentation](https://getbootstrap.com/docs/5.3/utilities/api/)
17. [Approach, Bootstrap v5.3 documentation](https://getbootstrap.com/docs/5.3/extend/approach/)
18. [Color modes, Bootstrap v5.3 documentation](https://getbootstrap.com/docs/5.3/customize/color-modes/)
19. [Get started with Bootstrap, Bootstrap v5.3 documentation](https://getbootstrap.com/docs/5.3/getting-started/introduction/?hsPreviewerApp=blog_post)
20. [Accordion, Bootstrap v5.3 documentation](https://getbootstrap.com/docs/5.3/components/accordion/)
21. [JavaScript, Bootstrap v5.3 documentation](https://getbootstrap.com/docs/5.3/getting-started/javascript/)
22. [Accessibility, Bootstrap v5.3 documentation](https://getbootstrap.com/docs/5.3/getting-started/accessibility/)
23. [Contents, Bootstrap v5.3 documentation](https://getbootstrap.com/docs/5.3/getting-started/contents/)
24. [bootstrap on npm](https://www.npmjs.com/package/bootstrap?activeTab=dependencies)
25. [twbs/bootstrap on GitHub](https://github.com/twbs/bootstrap)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Development tools and collaboration infrastructure › Frameworks, libraries, and APIs › Web frameworks and libraries

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/bootstrap-front-end-framework

English original: https://www.edgepedia.org/bootstrap-front-end-framework
