Data Attributes
Bootstrap supports various data attributes to declaratively configure components within HTML.
Data attributes are Bootstrap's declarative way of configuring components within HTML
- In the background the respective Bootstrap's JavaScript libraries are accessing those attributes during page rendering to setup the various components
- There are always JS versions of those data attributes to be used in case you want to them programmatically change them or achieve special effects, which can not be achieved otherwise
- So it is a fair advice to check-out the data attributes first and then use the JS version in case it is required
Toggle & Dropdown
data-bs-toggle- Activates components (button, modal, dropdown, tab, collapse, etc.)data-bs-target- Specifies the target element #id for the toggle actiondata-bs-dismiss- Dismisses alerts, modals, toasts, offcanvas
Popovers & Tooltips
data-bs-placement- Position (top, right, bottom, left, auto)data-bs-trigger- How to trigger (click, hover, focus, manual)data-bs-delay- Delay in millisecondsdata-bs-html- Allow HTML content (true/false)data-bs-title- Tooltip/popover titledata-bs-content- Popover contentdata-bs-boundary- Scrollable parentdata-bs-container- Appends to specific elementdata-bs-offset- [skidding, distance]data-bs-reference- Reference element for positioningdata-bs-fallback-placement- Fallback placementdata-bs-custom-class- Custom CSS classdata-bs-popper-config- Custom Popper config
Modals
data-bs-backdrop- Static, true, or falsedata-bs-keyboard- Close on Escape keydata-bs-focus- Auto-focus modal on show
Carousels
data-bs-ride- Auto-play (carousel, true)data-bs-interval- Slide interval in millisecondsdata-bs-pause- Pause on hover (hover/false)data-bs-wrap- Continuous cycling (true/false)data-bs-touch- Keyboard support (true/false)
Scrollspy
data-bs-spy- Activates scrollspydata-bs-target- Nav selector #id to spy ondata-bs-offset- Pixels to offset anchor detection (deprecated)data-bs-root-margin- top right bottom left anchor detection adjustment (replaces data-bs-offset)
Offcanvas
data-bs-backdrop- Static or truedata-bs-keyboard- Close on Escapedata-bs-scroll- Allow body scroll
General
data-bs-animation- Animate transitions (true/false)data-bs-autohide- Auto-dismiss toastsdata-bs-config- Pass JSON config object