Bootstrap 2 to Bootstrap 3 Converter
Convert Bootstrap 2 CSS classes, variables, and HTML markup to Bootstrap 3 equivalents. Handles grid, icons, buttons, forms, and more.
About
Migrating from Bootstrap 2 to Bootstrap 3 involves hundreds of breaking changes across CSS class names, LESS/Sass variables, grid systems, and HTML structure. The grid alone shifted from span* to col-md-*, row-fluid became simply row, and the responsive utilities were entirely renamed. Missing a single class rename in a large codebase causes silent layout failures that are difficult to trace. This tool performs a multi-pass conversion covering class renames, variable migration (camelCase to dashed-base), icon class translation (icon-* → glyphicon glyphicon-*), and structural HTML changes. It processes CSS, HTML, LESS, Sass, and template files. The converter handles approximately 180 class mappings and 120 variable mappings extracted from the official Bootstrap 3 migration guide. Note: dynamically constructed class strings in JavaScript or server-side templates cannot be statically analyzed. The tool flags ambiguous matches for manual review rather than silently producing incorrect output.
Formulas
The converter operates as a multi-pass text transformation pipeline. Each pass applies a category of regular expression substitutions.
Where P1 = Variable conversion pass, P2 = CSS class rename pass, P3 = HTML structural pass, P4 = Grid system pass.
Class replacement uses boundary-aware matching to avoid partial substitutions. For a class mapping old → new, the regex pattern is constructed as:
This ensures span6 inside a class attribute is matched but colspan6 is not. The diff algorithm compares input and output arrays line by line, marking lines as ADDED, REMOVED, or UNCHANGED, and produces a unified diff view with context lines.
Reference Data
| Bootstrap 2 Class | Bootstrap 3 Equivalent | Category |
|---|---|---|
| row-fluid | row | Grid |
| span1 - span12 | col-md-1 - col-md-12 | Grid |
| container-fluid | container-fluid (unchanged) | Grid |
| brand | navbar-brand | Navbar |
| nav-collapse | navbar-collapse | Navbar |
| nav-toggle | navbar-toggle | Navbar |
| btn-navbar | navbar-btn | Navbar |
| hero-unit | jumbotron | Components |
| icon-* | glyphicon glyphicon-* | Icons |
| btn (alone) | btn btn-default | Buttons |
| btn-mini | btn-xs | Buttons |
| btn-small | btn-sm | Buttons |
| btn-large | btn-lg | Buttons |
| alert-error | alert-danger | Alerts |
| control-group | form-group | Forms |
| controls | (removed, use form-group) | Forms |
| input-block-level | form-control | Forms |
| input-mini | input-xs (custom) | Forms |
| input-small | input-sm | Forms |
| input-large | input-lg | Forms |
| input-xlarge | input-lg | Forms |
| input-xxlarge | input-lg | Forms |
| input-prepend | input-group | Forms |
| input-append | input-group | Forms |
| add-on | input-group-addon | Forms |
| thumbnail | img-thumbnail | Images |
| unstyled | list-unstyled | Typography |
| inline (on ul) | list-inline | Typography |
| muted | text-muted | Typography |
| label (component) | label label-default | Labels |
| label-important | label-danger | Labels |
| bar (progress) | progress-bar | Progress |
| bar-danger | progress-bar-danger | Progress |
| bar-warning | progress-bar-warning | Progress |
| bar-success | progress-bar-success | Progress |
| bar-info | progress-bar-info | Progress |
| accordion | panel-group | Panels |
| accordion-group | panel panel-default | Panels |
| accordion-heading | panel-heading | Panels |
| accordion-body | panel-collapse | Panels |
| accordion-inner | panel-body | Panels |
| visible-phone | visible-xs | Responsive |
| visible-tablet | visible-sm | Responsive |
| visible-desktop | visible-md visible-lg | Responsive |
| hidden-phone | hidden-xs | Responsive |
| hidden-tablet | hidden-sm | Responsive |
| hidden-desktop | hidden-md hidden-lg | Responsive |
| .img-polaroid | .img-thumbnail | Images |