bootstrap-components
Original:🇺🇸 English
Translated
This skill should be used when the user asks about Bootstrap components, "how to create a modal", "navbar not collapsing", "carousel autoplay", "responsive card grid", "toast notifications", "dropdown menu", "accordion FAQ", "offcanvas sidebar", "tab navigation", "tooltip not showing", "popover not working", Bootstrap accordion, alerts, badges, breadcrumb, buttons, button groups, cards, carousel, close button, collapse, dropdowns, list group, modal, navbar, navs and tabs, offcanvas, pagination, placeholders, popovers, progress, scrollspy, spinners, toasts, tooltips, or needs help implementing any Bootstrap UI component.
6installs
Sourcesjnims/bootstrap-expert
Added on
NPX Install
npx skill4agent add sjnims/bootstrap-expert bootstrap-componentsTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Bootstrap 5.3 Components
Bootstrap provides ready-to-use UI components for building interfaces. This skill covers all major components with usage patterns, JavaScript initialization requirements, and accessibility best practices.
JavaScript Initialization Overview: Some components work purely with data attributes, while others require JavaScript initialization. Components marked with Requires JS below won't function without explicit initialization.
| Component | Requires JS Init | Data Attributes Only |
|---|---|---|
| Tooltip | Yes | No |
| Popover | Yes | No |
| Toast | Yes (to show) | No |
| Scrollspy | Optional | Yes |
| Modal | Optional | Yes |
| Carousel | Optional | Yes |
| Collapse | Optional | Yes |
| Dropdown | Optional | Yes |
Interactive Components
These components require or benefit from JavaScript. See for detailed code examples, JavaScript APIs, and accessibility guidance.
references/interactive-components.mdAccordion
Collapsible content panels that show one section at a time. Use wrapper with children containing and . Remove to allow multiple panels open simultaneously. Use for borderless variant.
.accordion.accordion-item.accordion-header.accordion-collapsedata-bs-parent.accordion-flushCarousel
Image slideshow with optional controls and indicators. Use wrapper with containing slides. Add / for navigation. Use for autoplay. Respects automatically.
.carousel.slide.carousel-inner.carousel-item.carousel-control-prev.carousel-control-nextdata-bs-ride="carousel"prefers-reduced-motionCollapse
Toggle content visibility with smooth animations. Use on trigger with pointing to element. Use for width-based collapse. Target multiple elements with class selector ().
data-bs-toggle="collapse"data-bs-target.collapse.collapse-horizontal.multi-collapseDropdowns
Toggleable contextual menus for links and actions. Use wrapper with button and list. Direction variants: , , . Add for dark theme. Keyboard navigation is built-in.
.dropdown.dropdown-toggle.dropdown-menu.dropup.dropend.dropstart.dropdown-menu-darkModal
Dialog boxes that overlay the page and trap focus. Use with pointing to element. Sizes: , , . Modifiers: , . Use to prevent dismiss on outside click.
data-bs-toggle="modal"data-bs-target.modal.modal-sm.modal-lg.modal-xl.modal-dialog-centered.modal-dialog-scrollabledata-bs-backdrop="static"Offcanvas
Hidden sidebars that slide from viewport edge. Positions: (left), (right), , . Use to allow body scrolling. Use for persistent sidebars.
.offcanvas-start.offcanvas-end.offcanvas-top.offcanvas-bottomdata-bs-scroll="true"data-bs-backdrop="static"Popovers
Requires JS init and Popper.js. Rich overlay content triggered by click or hover. Use with and . Initialize with or batch initialize all: . Placements: top, right, bottom, left. Use (includes Popper) or include Popper separately before .
data-bs-toggle="popover"data-bs-titledata-bs-contentnew bootstrap.Popover(el)document.querySelectorAll('[data-bs-toggle="popover"]').forEach(el => new bootstrap.Popover(el))bootstrap.bundle.jsbootstrap.jsScrollspy
Auto-update navigation based on scroll position. Use on scrollable container with pointing to nav. Use to control activation threshold. Container needs so keyboard-only users can focus and scroll the container without a mouse.
data-bs-spy="scroll"data-bs-targetdata-bs-root-margintabindex="0"Toasts
Requires JS to show. Lightweight dismissible notifications. Use for positioning and stacking. Initialize with then call . Options: , . Placements via container positioning classes.
.toast-containernew bootstrap.Toast(el).show()autohide: truedelay: 5000Tooltips
Requires JS init and Popper.js. Hover hints for brief descriptions. Use with (preferred) or attribute. Initialize with or batch initialize all: . Placements: top, right, bottom, left. Tooltips on disabled buttons require a wrapper or with for keyboard accessibility. Use (includes Popper) or include Popper separately before .
data-bs-toggle="tooltip"data-bs-titletitlenew bootstrap.Tooltip(el)document.querySelectorAll('[data-bs-toggle="tooltip"]').forEach(el => new bootstrap.Tooltip(el))<span><div>tabindex="0"bootstrap.bundle.jsbootstrap.jsStatic Components
These components work primarily with CSS and HTML. See for detailed code examples and accessibility guidance.
references/static-components.mdAlerts
Contextual feedback messages. Use with . Colors: primary, secondary, success, danger, warning, info, light, dark. Use for styled links. Add with close button for dismissible alerts.
.alert.alert-{color}role="alert".alert-link.alert-dismissibleBadges
Labels, counters, and status indicators. Use on . Use for pill shape. Position with utilities for notification badges. Include text for screen reader context.
.badge.bg-{color}<span>.rounded-pill.position-absolute.visually-hiddenBreadcrumb
Navigation hierarchy indicator. Wrap in . Use on elements. Mark current page with and . Customize divider via CSS variable.
<ol class="breadcrumb"><nav aria-label="breadcrumb">.breadcrumb-item<li>.activearia-current="page"--bs-breadcrumb-dividerButtons
Interactive button elements. Base: . Outline: . Sizes: , . Full width: wrap in . States: attribute, class. Use for actions, for navigation.
.btn.btn-{color}.btn-outline-{color}.btn-lg.btn-sm.d-griddisabled.active<button><a>Button Group
Related buttons grouped together. Use with and . Vertical: . Toolbar: wrapper with . Sizes: , .
.btn-grouprole="group"aria-label.btn-group-vertical.btn-toolbarrole="toolbar".btn-group-lg.btn-group-smCards
Flexible content containers. Structure: > > , . Optional: , , /. Grid layout: use with > for equal heights.
.card.card-body.card-title.card-text.card-header.card-footer.card-img-top.card-img-bottom.row.row-cols-{n}.col.card.h-100Close Button
Generic dismiss button. Use with . White variant: . Dismiss targets via .
.btn-closearia-label="Close".btn-close-whitedata-bs-dismiss="alert|modal|offcanvas|toast"List Group
Series of content items as lists. Use > . Actionable: add . Borderless: . Horizontal: . Colors: .
.list-group.list-group-item.list-group-item-action.list-group-flush.list-group-horizontal.list-group-item-{color}Navbar
Responsive navigation header. Use . Contains , , . Placement: , , . Theme: ( deprecated in v5.3).
.navbar.navbar-expand-{breakpoint}.navbar-brand.navbar-toggler.navbar-collapse.fixed-top.fixed-bottom.sticky-topdata-bs-theme="dark".navbar-lightNavs and Tabs
Base navigation with visual styles. Styles: , , . Layout: (equal width), (full width), (vertical). For tabbed content, use with buttons and panes.
.nav-tabs.nav-pills.nav-underline.nav-fill.nav-justified.flex-columnrole="tablist"role="tab"role="tabpanel"Pagination
Navigation for paginated content. Use > > > . Sizes: , . Alignment: , . Mark current: with .
<nav aria-label="...">.pagination.page-item.page-link.pagination-lg.pagination-sm.justify-content-center.justify-content-end.activearia-current="page"Placeholders
Loading state indicators. Use spans with column widths (). Animations: wrap in or . Sizes: , , . Add to placeholder containers.
.placeholder.col-6.placeholder-glow.placeholder-wave.placeholder-lg.placeholder-sm.placeholder-xsaria-hidden="true"Progress
Progress indicators for tasks. Use wrapper with inside. Set width via . Variants: , . Colors: . Include ARIA attributes: , , , .
.progress.progress-barstyle="width: X%".progress-bar-striped.progress-bar-animated.bg-{color}role="progressbar"aria-valuenowaria-valueminaria-valuemaxSpinners
Loading indicators. Types: (spinning), (pulsing). Sizes: , . Colors: . Include and loading text.
.spinner-border.spinner-grow.spinner-border-sm.spinner-grow-sm.text-{color}role="status".visually-hiddenCommon Gotchas & Tips
Components Requiring JavaScript Initialization
Tooltips and popovers will not work without explicit JavaScript initialization. Unlike modals, dropdowns, and carousels (which work via data attributes), these components must be initialized:
javascript
// Initialize all tooltips
document.querySelectorAll('[data-bs-toggle="tooltip"]')
.forEach(el => new bootstrap.Tooltip(el));
// Initialize all popovers
document.querySelectorAll('[data-bs-toggle="popover"]')
.forEach(el => new bootstrap.Popover(el));Toasts also require JavaScript to show—they are hidden by default and must be shown programmatically with .
toast.show()Tooltip/Popover Positioning Issues
If tooltips or popovers appear in the wrong position, get clipped, or behave strangely in complex layouts (input groups, button groups, tables, modals), use :
container: 'body'javascript
// Append to body to avoid rendering issues
new bootstrap.Tooltip(el, { container: 'body' });
new bootstrap.Popover(el, { container: 'body' });For popovers inside modals, set to the modal body so focus remains trapped:
containerjavascript
new bootstrap.Popover(el, { container: '.modal-body' });Modal Best Practices
Semantic headings: Bootstrap recommends using for modal titles semantically (the modal represents its own document context). Use font size utilities like to control visual appearance while maintaining proper heading hierarchy.
<h1>.fs-5Autofocus workaround: The HTML attribute has no effect in Bootstrap modals due to HTML5 semantics. To focus an input when a modal opens:
autofocusjavascript
myModal.addEventListener('shown.bs.modal', () => {
document.getElementById('myInput').focus();
});Nested modals: Bootstrap only supports one modal at a time. Nested modals are not supported and considered poor user experience. If multiple dialogs are needed, close the current modal before opening another.
Dynamic content height: After dynamically changing modal body content that affects height, call to readjust the modal's position.
modal.handleUpdate()Cross-Component Patterns
Modals with forms: Place form validation feedback inside the modal body. On successful submission, call and optionally show a toast notification.
modal.hide()Toast stacking: Use with positioning utilities () for consistent toast placement. Multiple toasts stack automatically.
.toast-container.position-fixed.bottom-0.end-0.p-3Navbar with offcanvas: For mobile navigation, combine with offcanvas for a sliding menu. Use on the navbar toggler instead of collapse for a different UX pattern.
.navbardata-bs-toggle="offcanvas"Cards in grids: Use with > to create equal-height card grids that respond to breakpoints.
.row.row-cols-{n}.col.card.h-100Additional Resources
Reference Files
- - Quick reference tables for all component classes
references/components-reference.md - - CSS custom properties for runtime component theming
references/css-custom-properties.md - - Detailed documentation for JS-dependent components
references/interactive-components.md - - Detailed documentation for CSS/HTML components
references/static-components.md
Example Files
- - Accordion and FAQ patterns
examples/accordion-patterns.html - - Alert variants, dismissible alerts, live region patterns
examples/alert-patterns.html - - Badges, buttons, button groups, and close buttons
examples/badge-button-patterns.html - - Breadcrumb navigation with custom dividers and icons
examples/breadcrumb-patterns.html - - Responsive card grid layouts
examples/card-grid-patterns.html - - Carousel implementation patterns
examples/carousel-patterns.html - - Collapse, horizontal collapse, and multi-target patterns
examples/collapse-patterns.html - - Dropdown menus, split buttons, and form dropdowns
examples/dropdown-patterns.html - - List groups, actionable items, and tab integration
examples/list-group-patterns.html - - Modal dialog patterns
examples/modal-patterns.html - - Navigation bar layouts
examples/navbar-patterns.html - - Offcanvas sidebar patterns
examples/offcanvas-patterns.html - - Pagination variants, alignment, and responsive patterns
examples/pagination-patterns.html - - Loading skeleton patterns for cards, lists, and tables
examples/placeholder-patterns.html - - Tooltip and popover patterns (requires JS init)
examples/popovers-tooltips-patterns.html - - Progress bars and spinner loading indicators
examples/progress-spinner-patterns.html - - Scrollspy with navbar, list group, and documentation patterns
examples/scrollspy-patterns.html - - Tab navigation patterns
examples/tabs-patterns.html - - Toast notification patterns (requires JS init)
examples/toasts-patterns.html