バージョン4へのマイグレーション
Bootstrap 4 は全体的に書き換えています。主な変更を以下に要約し, 関連するコンポーネントの具体的な変更内容を記します。
安定版での変更点
Beta3 から安定版は大きな変更はありませんが, 注目すべきいくつかの変更があります。
印刷
- 印刷ユーテリティの問題を修正しました。以前は
.d-print-*
を使うと他の.d-*
よりも優先されていました. 今は印刷(@media print
)のときだけ適用されます。 - 印刷ユーテリティを拡張しました。Beta3 以前は
block
,inline-block
,inline
, そしてnone
だけでした。安定版ではflex
,inline-flex
,table
,table-row
, そしてtable-cell
を追加しました。 @page
size
で指定した印刷プレビューのレンダリングを修正しました。
Beta3 での変更
Beta2 では大きな変更がありましたが, Beta3 では更に対応しないければいけないものがいつくかあります。
いろいろ
- 未使用の余分な
$thumbnail-transition
変数を削除しました。 - npm パッケージは, ソースと dist ファイルだけです。それ以外のファイルに依存して
node_module
で実行している場合は, 開発環境を調整する必要があります。
Forms
-
標準およびカスタムフォームのチェックボックスとラジオボタンを書き直しました。同じ HTML 構造とスタイルが一致しています。そのため, 入力状態によってラベルを変更することができ,
disabled
属性が使いやすくなり, バリデーションもサポートしやすくなりました。カスタムフォームのチェックボックスやラジオボタンで複数の
background-image
を管理するための CSS を変更しました。以前は.custom-control-indicator
要素に背景色やグラデーション, SVG アイコンがありました。背景色のグラデーションを変更するたびに, すべてを置き換えなければなりませんでした。今後は塗りつぶすための.custom-control-label::before
とアイコン用の.custom-control-label::after
に分離しています。カスタムチェックインラインを作成するには
.custom-control-inline
を追加します。 -
input ベースのボタングループのセレクタを更新しました。JavaScript/CSS は
[data-toggle="buttons"] { }
を使いません。JavaScript はdata
属性を使い, CSS は.btn-group-toggle
を使います。 -
.col-form-legend
を削除し,.col-form-label
をちょっと改善しました。.col-form-label-sm
と.col-form-label-lg
はn<legend>
要素で簡単に使用できます。 -
カスタムのファイルインプットは Sass 変数の
$custom-file-text
で変更できるようになります。ブラウザのChoose file
テキストは.custom-file-label
から取得されるようになります。
Input groups
-
インプットグループのアドオンはインプットフィールドに対する配置固有のものになりました。
.input-group-addon
と.input-group-btn
を削除し,.input-group-prepend
と.input-group-append
を追加しましうた。明示的に append および prepend を使えば CSS を単純化できます。prepend/append の中では.input-group-text
でテキストをラップします。 -
複数のフォーム要素を対象にバリデーションスタイルがサポートされるようになりました。(ただし, グループごとに1つのフォーム要素のみ)
-
サイズはそれぞれのフォーム要素ではなく, 親の
.input-group
に指定する必要があります。
Beta2 での変更
Beta 版ではなるべく大きな変更をしないように留意しています。しかし, 物事は計画通りに進むとは限りません。以下は Beta から Beta2 に移行する際の大きな変更点です。
削除したもの
.badge
における$badge-color
と使い方を削除しました。background-color
に基づくcolor
を使うので変数は不要です。- CSS の
grayscale
フィルタとの衝突を回避するためにgrayscale()
関数をgray()
にリネームしました。 .table-inverse
,.thead-inverse
, そして.thead-default
を.*-dark
と.*-light
に変更しました。- レスポンシブテーブルは各ブレイクポイントごとに生成されるようになりました。Beta では
.table-responsive
だったものが.table-responsive-md
のようになります。必要に応じて.table-responsive
または.table-responsive-{sm,md,lg,xl}
を使うことができます。 - パッケージマネージャ Bower のサポートをやめました。(代替のパッケージマネージャ: Yarn, npm) 詳細は bower/bower#2298
- Bootstrap には jQuery 1.9.1 以降が必要ですが, バージョン3 以降を推奨します。バージョン3 以降は Bootstrap と同じサポートブラウザで, いくつかのセキュリティ上の対策がされているからです。
- 未使用の
.form-control-label
を削除しました。これは<label>
と垂直方向に配置した.col-form-label
と重複しているからです。 color-yiq
をcolor
を含む mixin から関数に変更し, あした。これを使えば任意の CSS プロパティに使用できます。例えばcolor-yiq(#000)
の代わりにcolor: color-yiq(#000);
のように記述できます。
ハイライト
.modal-dialog
で新しいpointer-events
を導入しました。pointer-events: none
を設定すれば, 外側の.modal-dialog
クリックを無効にできます。pointer-events: auto
を設定すれば有効にできます。
サマリー
ここからは Bootstrap3 から Bootstrap4 に移行する際に, 気をつけるべき大きな変更点について紹介します。
サポートブラウザ
- IE8, IE9, iOS6 をサポートから外しました。Bootstrap4 は IE10+ と iOS 7+ のみです。どちらかを必要とする場合は Bootstrap3 を使ってください。
- Android 5.0 Lolipop のブラウザと WebView をサポートに追加しました。以前の Android のブラウザと WebView はサポートしません。
全体的な変更点
- flexbox が標準で有効になりました。
- CSS ソースが Less から Sass に変更になりました。
- CSSの標準単位を
px
からrem
に切り替えました。デバイスの viewport やメディアクエリは影響を受けないので引き続きpx
を使います。 - ベースフォントサイズを
14px
から16px
に変更しました。 - 5 番目のオプション(
576px
以下のデバイスに対応)を追加し, クラスから-xs
を削除しました。 (例:.col-6.col-sm-4.col-md-3
) - 独立したオプションのテーマを設定可能な SCSS 変数 に置き換えました。(例:
$enable-gradients: true
) - Grunt の代わりに npm scripts を使用するようにシステムを改良しました。すべての scripts については
package.json
を, ローカル開発のニーズについてはプロジェクトの readme を参照してください。 - Bootstrap のレスポンシブ無効化はサポートされなくなりました。
- オンラインカスタマイザーを廃止し, 幅広いセットアップドキュメントとカスタマイズされたビルドシステムが導入されました。
- utility classes に余白やパッディングの新しいユーティリティクラスが追加されました。
Grid system
- flexbox に移行
- グリッドミックスインと定義されたクラスに flexbox がサポートされるようになりました。
- flexbox の機能として, 垂直方向および水平方向の配置がサポートされるようになりました。
- 更新されたグリッドクラス名と新しいグリッド
- Added a new
sm
grid tier below768px
for more granular control. We now havexs
,sm
,md
,lg
, andxl
. This also means every tier has been bumped up one level (so.col-md-6
in v3 is now.col-lg-6
in v4). xs
grid classes have been modified to not require the infix to more accurately represent that they start applying styles atmin-width: 0
and not a set pixel value. Instead of.col-xs-6
, it’s now.col-6
. All other grid tiers require the infix (e.g.,sm
).
- Added a new
- Updated grid sizes, mixins, and variables.
- Grid gutters now have a Sass map so you can specify specific gutter widths at each breakpoint.
- Updated grid mixins to utilize a
make-col-ready
prep mixin and amake-col
to set theflex
andmax-width
for individual column sizing. - Changed grid system media query breakpoints and container widths to account for new grid tier and ensure columns are evenly divisible by
12
at their max width. - Grid breakpoints and container widths are now handled via Sass maps (
$grid-breakpoints
and$container-max-widths
) instead of a handful of separate variables. These replace the@screen-*
variables entirely and allow you to fully customize the grid tiers. - Media queries have also changed. Instead of repeating our media query declarations with the same value each time, we now have
@include media-breakpoint-up/down/only
. Now, instead of writing@media (min-width: @screen-sm-min) { ... }
, you can write@include media-breakpoint-up(sm) { ... }
.
Components
- Dropped panels, thumbnails, and wells for a new all-encompassing component, cards.
- Dropped the Glyphicons icon font. If you need icons, some options are:
- the upstream version of Glyphicons
- Octicons
- Font Awesome
- See the Extend page for a list of alternatives. Have additional suggestions? Please open an issue or PR.
- Dropped the Affix jQuery plugin.
- We recommend using
position: sticky
instead. See the HTML5 Please entry for details and specific polyfill recommendations. One suggestion is to use an@supports
rule for implementing it (e.g.,@supports (position: sticky) { ... }
)/ - If you were using Affix to apply additional, non-
position
styles, the polyfills might not support your use case. One option for such uses is the third-party ScrollPos-Styler library.
- We recommend using
- Dropped the pager component as it was essentially slightly customized buttons.
- Refactored nearly all components to use more un-nested class selectors instead of over-specific children selectors.
By component
This list highlights key changes by component between v3.x.x and v4.0.0.
Reboot
New to Bootstrap 4 is the Reboot, a new stylesheet that builds on Normalize with our own somewhat opinionated reset styles. Selectors appearing in this file only use elements—there are no classes here. This isolates our reset styles from our component styles for a more modular approach. Some of the most important resets this includes are the box-sizing: border-box
change, moving from em
to rem
units on many elements, link styles, and many form element resets.
Typography
- Moved all
.text-
utilities to the_utilities.scss
file. - Dropped
.page-header
as its styles can be applied via utilities. .dl-horizontal
has been dropped. Instead, use.row
on<dl>
and use grid column classes (or mixins) on its<dt>
and<dd>
children.- Redesigned blockquotes, moving their styles from the
<blockquote>
element to a single class,.blockquote
. Dropped the.blockquote-reverse
modifier for text utilities. .list-inline
now requires that its children list items have the new.list-inline-item
class applied to them.
Images
- Renamed
.img-responsive
to.img-fluid
. - Renamed
.img-rounded
to.rounded
- Renamed
.img-circle
to.rounded-circle
Tables
- Nearly all instances of the
>
selector have been removed, meaning nested tables will now automatically inherit styles from their parents. This greatly simplifies our selectors and potential customizations. - Renamed
.table-condensed
to.table-sm
for consistency. - Added a new
.table-inverse
option. - Added table header modifiers:
.thead-default
and.thead-inverse
. - Renamed contextual classes to have a
.table-
-prefix. Hence.active
,.success
,.warning
,.danger
and.info
to.table-active
,.table-success
,.table-warning
,.table-danger
and.table-info
.
Forms
- Moved element resets to the
_reboot.scss
file. - Renamed
.control-label
to.col-form-label
. - Renamed
.input-lg
and.input-sm
to.form-control-lg
and.form-control-sm
, respectively. - Dropped
.form-group-*
classes for simplicity’s sake. Use.form-control-*
classes instead now. - Dropped
.help-block
and replaced it with.form-text
for block-level help text. For inline help text and other flexible options, use utility classes like.text-muted
. - Dropped
.radio-inline
and.checkbox-inline
. - Consolidated
.checkbox
and.radio
into.form-check
and the various.form-check-*
classes. - Horizontal forms overhauled:
- Dropped the
.form-horizontal
class requirement. .form-group
no longer applies styles from the.row
via mixin, so.row
is now required for horizontal grid layouts (e.g.,<div class="form-group row">
).- Added new
.col-form-label
class to vertically center labels with.form-control
s. - Added new
.form-row
for compact form layouts with the grid classes (swap your.row
for a.form-row
and go).
- Dropped the
- Added custom forms support (for checkboxes, radios, selects, and file inputs).
- Replaced
.has-error
,.has-warning
, and.has-success
classes with HTML5 form validation via CSS’s:invalid
and:valid
pseudo-classes. - Renamed
.form-control-static
to.form-control-plaintext
.
Buttons
- Renamed
.btn-default
to.btn-secondary
. - Dropped the
.btn-xs
class entirely as.btn-sm
is proportionally much smaller than v3’s. - The stateful button feature of the
button.js
jQuery plugin has been dropped. This includes the$().button(string)
and$().button('reset')
methods. We advise using a tiny bit of custom JavaScript instead, which will have the benefit of behaving exactly the way you want it to.- Note that the other features of the plugin (button checkboxes, button radios, single-toggle buttons) have been retained in v4.
- Change buttons’
[disabled]
to:disabled
as IE9+ supports:disabled
. Howeverfieldset[disabled]
is still necessary because native disabled fieldsets are still buggy in IE11.
Button group
- Rewrote component with flexbox.
- Removed
.btn-group-justified
. As a replacement you can use<div class="btn-group d-flex" role="group"></div>
as a wrapper around elements with.w-100
. - Dropped the
.btn-group-xs
class entirely given removal of.btn-xs
. - Removed explicit spacing between button groups in button toolbars; use margin utilities now.
- Improved documentation for use with other components.
Dropdowns
- Switched from parent selectors to singular classes for all components, modifiers, etc.
- Simplified dropdown styles to no longer ship with upward or downward facing arrows attached to the dropdown menu.
- Dropdowns can be built with
<div>
s or<ul>
s now. - Rebuilt dropdown styles and markup to provide easy, built-in support for
<a>
and<button>
based dropdown items. - Renamed
.divider
to.dropdown-divider
. - Dropdown items now require
.dropdown-item
. - Dropdown toggles no longer require an explicit
<span class="caret"></span>
; this is now provided automatically via CSS’s::after
on.dropdown-toggle
.
Grid system
- Added a new
576px
grid breakpoint assm
, meaning there are now five total tiers (xs
,sm
,md
,lg
, andxl
). - Renamed the responsive grid modifier classes from
.col-{breakpoint}-{modifier}-{size}
to.{modifier}-{breakpoint}-{size}
for simpler grid classes. - Dropped push and pull modifier classes for the new flexbox-powered
order
classes. For example, instead of.col-8.push-4
and.col-4.pull-8
, you’d use.col-8.order-2
and.col-4.order-1
. - Added flexbox utility classes for grid system and components.
List groups
- Rewrote component with flexbox.
- Replaced
a.list-group-item
with an explicit class,.list-group-item-action
, for styling link and button versions of list group items. - Added
.list-group-flush
class for use with cards.
Modal
- Rewrote component with flexbox.
- Given move to flexbox, alignment of dismiss icons in the header is likely broken as we’re no longer using floats. Floated content comes first, but with flexbox that’s no longer the case. Update your dismiss icons to come after modal titles to fix.
- The
remote
option (which could be used to automatically load and inject external content into a modal) and the correspondingloaded.bs.modal
event were removed. We recommend instead using client-side templating or a data binding framework, or calling jQuery.load yourself.
Navs
- Rewrote component with flexbox.
- Dropped nearly all
>
selectors for simpler styling via un-nested classes. - Instead of HTML-specific selectors like
.nav > li > a
, we use separate classes for.nav
s,.nav-item
s, and.nav-link
s. This makes your HTML more flexible while bringing along increased extensibility.
Navbar
The navbar has been entirely rewritten in flexbox with improved support for alignment, responsiveness, and customization.
- Responsive navbar behaviors are now applied to the
.navbar
class via the required.navbar-expand-{breakpoint}
where you choose where to collapse the navbar. Previously this was a Less variable modification and required recompiling. .navbar-default
is now.navbar-light
, though.navbar-dark
remains the same. One of these is required on each navbar. However, these classes no longer setbackground-color
s; instead they essentially only affectcolor
.- Navbars now require a background declaration of some kind. Choose from our background utilities (
.bg-*
) or set your own with the light/inverse classes above for mad customization. - Given flexbox styles, navbars can now use flexbox utilities for easy alignment options.
.navbar-toggle
is now.navbar-toggler
and has different styles and inner markup (no more three<span>
s).- Dropped the
.navbar-form
class entirely. It’s no longer necessary; instead, just use.form-inline
and apply margin utilities as necessary. - Navbars no longer include
margin-bottom
orborder-radius
by default. Use utilities as necessary. - All examples featuring navbars have been updated to include new markup.
Pagination
- Rewrote component with flexbox.
- Explicit classes (
.page-item
,.page-link
) are now required on the descendants of.pagination
s - Dropped the
.pager
component entirely as it was little more than customized outline buttons.
Breadcrumbs
- An explicit class,
.breadcrumb-item
, is now required on the descendants of.breadcrumb
s
Labels and badges
- Consolidated
.label
and.badge
to disambiguate from the<label>
element and simplify related components. - Added
.badge-pill
as modifier for rounded “pill” look. - Badges are no longer floated automatically in list groups and other components. Utility classes are now required for that.
.badge-default
has been dropped and.badge-secondary
added to match component modifier classes used elsewhere.
Panels, thumbnails, and wells
Dropped entirely for the new card component.
Panels
.panel
to.card
, now built with flexbox..panel-default
removed and no replacement..panel-group
removed and no replacement..card-group
is not a replacement, it is different..panel-heading
to.card-header
.panel-title
to.card-title
. Depending on the desired look, you may also want to use heading elements or classes (e.g.<h3>
,.h3
) or bold elements or classes (e.g.<strong>
,<b>
,.font-weight-bold
). Note that.card-title
, while similarly named, produces a different look than.panel-title
..panel-body
to.card-body
.panel-footer
to.card-footer
.panel-primary
,.panel-success
,.panel-info
,.panel-warning
, and.panel-danger
have been dropped for.bg-
,.text-
, and.border
utilities generated from our$theme-colors
Sass map.
Progress
- Replaced contextual
.progress-bar-*
classes with.bg-*
utilities. For example,class="progress-bar progress-bar-danger"
becomesclass="progress-bar bg-danger"
. - Replaced
.active
for animated progress bars with.progress-bar-animated
.
Carousel
- Overhauled the entire component to simplify design and styling. We have fewer styles for you to override, new indicators, and new icons.
- All CSS has been un-nested and renamed, ensuring each class is prefixed with
.carousel-
.- For carousel items,
.next
,.prev
,.left
, and.right
are now.carousel-item-next
,.carousel-item-prev
,.carousel-item-left
, and.carousel-item-right
. .item
is also now.carousel-item
.- For prev/next controls,
.carousel-control.right
and.carousel-control.left
are now.carousel-control-next
and.carousel-control-prev
, meaning they no longer require a specific base class.
- For carousel items,
- Removed all responsive styling, deferring to utilities (e.g., showing captions on certain viewports) and custom styles as needed.
- Removed image overrides for images in carousel items, deferring to utilities.
- Tweaked the Carousel example to include the new markup and styles.
Tables
- Removed support for styled nested tables. All table styles are now inherited in v4 for simpler selectors.
- Added inverse table variant.
Utilities
- Display, hidden, and more:
- Made display utilities responsive (e.g.,
.d-none
andd-{sm,md,lg,xl}-none
). - Dropped the bulk of
.hidden-*
utilities for new display utilities. For example, instead of.hidden-sm-up
, use.d-sm-none
. Renamed the.hidden-print
utilities to use the display utility naming scheme. More info under the Responsive utilities section of this page. - Added
.float-{sm,md,lg,xl}-{left,right,none}
classes for responsive floats and removed.pull-left
and.pull-right
since they’re redundant to.float-left
and.float-right
.
- Made display utilities responsive (e.g.,
- Type:
- Added responsive variations to our text alignment classes
.text-{sm,md,lg,xl}-{left,center,right}
.
- Added responsive variations to our text alignment classes
- Alignment and spacing:
- Added new responsive margin and padding utilities for all sides, plus vertical and horizontal shorthands.
- Added boatload of flexbox utilities.
- Dropped
.center-block
for the new.mx-auto
class.
- Clearfix updated to drop support for older browser versions.
Vendor prefix mixins
Bootstrap 3’s vendor prefix mixins, which were deprecated in v3.2.0, have been removed in Bootstrap 4. Since we use Autoprefixer, they’re no longer necessary.
Removed the following mixins: animation
, animation-delay
, animation-direction
, animation-duration
, animation-fill-mode
, animation-iteration-count
, animation-name
, animation-timing-function
, backface-visibility
, box-sizing
, content-columns
, hyphens
, opacity
, perspective
, perspective-origin
, rotate
, rotateX
, rotateY
, scale
, scaleX
, scaleY
, skew
, transform-origin
, transition-delay
, transition-duration
, transition-property
, transition-timing-function
, transition-transform
, translate
, translate3d
, user-select
Documentation
Our documentation received an upgrade across the board as well. Here’s the low down:
- We’re still using Jekyll, but we have plugins in the mix:
bugify.rb
is used to efficiently list out the entries on our browser bugs page.example.rb
is a custom fork of the defaulthighlight.rb
plugin, allowing for easier example-code handling.callout.rb
is a similar custom fork of that, but designed for our special docs callouts.- jekyll-toc is used to generate our table of contents.
- All docs content has been rewritten in Markdown (instead of HTML) for easier editing.
- Pages have been reorganized for simpler content and a more approachable hierarchy.
- We moved from regular CSS to SCSS to take full advantage of Bootstrap’s variables, mixins, and more.
Responsive utilities
All @screen-
variables have been removed in v4.0.0. Use the media-breakpoint-up()
, media-breakpoint-down()
, or media-breakpoint-only()
Sass mixins or the $grid-breakpoints
Sass map instead.
Our responsive utility classes have largely been removed in favor of explicit display
utilities.
- The
.hidden
and.show
classes have been removed because they conflicted with jQuery’s$(...).hide()
and$(...).show()
methods. Instead, try toggling the[hidden]
attribute or use inline styles likestyle="display: none;"
andstyle="display: block;"
. - All
.hidden-
classes have been removed, save for the print utilities which have been renamed.- Removed from v3:
.hidden-xs
.hidden-sm
.hidden-md
.hidden-lg
.visible-xs-block
.visible-xs-inline
.visible-xs-inline-block
.visible-sm-block
.visible-sm-inline
.visible-sm-inline-block
.visible-md-block
.visible-md-inline
.visible-md-inline-block
.visible-lg-block
.visible-lg-inline
.visible-lg-inline-block
- Removed from v4 alphas:
.hidden-xs-up
.hidden-xs-down
.hidden-sm-up
.hidden-sm-down
.hidden-md-up
.hidden-md-down
.hidden-lg-up
.hidden-lg-down
- Removed from v3:
- Print utilities no longer start with
.hidden-
or.visible-
, but with.d-print-
.- Old names:
.visible-print-block
,.visible-print-inline
,.visible-print-inline-block
,.hidden-print
- New classes:
.d-print-block
,.d-print-inline
,.d-print-inline-block
,.d-print-none
- Old names:
Rather than using explicit .visible-*
classes, you make an element visible by simply not hiding it at that screen size. You can combine one .d-*-none
class with one .d-*-block
class to show an element only on a given interval of screen sizes (e.g. .d-none.d-md-block.d-xl-none
shows the element only on medium and large devices).
Note that the changes to the grid breakpoints in v4 means that you’ll need to go one breakpoint larger to achieve the same results. The new responsive utility classes don’t attempt to accommodate less common cases where an element’s visibility can’t be expressed as a single contiguous range of viewport sizes; you will instead need to use custom CSS in such cases.
v4.3