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 action
  • data-bs-dismiss - Dismisses alerts, modals, toasts, offcanvas

*[bootstrap] Documentation


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 milliseconds
  • data-bs-html - Allow HTML content (true/false)
  • data-bs-title - Tooltip/popover title
  • data-bs-content - Popover content
  • data-bs-boundary - Scrollable parent
  • data-bs-container - Appends to specific element
  • data-bs-offset - [skidding, distance]
  • data-bs-reference - Reference element for positioning
  • data-bs-fallback-placement - Fallback placement
  • data-bs-custom-class - Custom CSS class
  • data-bs-popper-config - Custom Popper config

*[bootstrap] Documentation


Modals

  • data-bs-backdrop - Static, true, or false
  • data-bs-keyboard - Close on Escape key
  • data-bs-focus - Auto-focus modal on show

*[bootstrap] Documentation


Carousels

  • data-bs-ride - Auto-play (carousel, true)
  • data-bs-interval - Slide interval in milliseconds
  • data-bs-pause - Pause on hover (hover/false)
  • data-bs-wrap - Continuous cycling (true/false)
  • data-bs-touch - Keyboard support (true/false)

*[bootstrap] Documentation


Scrollspy

  • data-bs-spy - Activates scrollspy
  • data-bs-target - Nav selector #id to spy on
  • data-bs-offset - Pixels to offset anchor detection (deprecated)
  • data-bs-root-margin - top right bottom left anchor detection adjustment (replaces data-bs-offset)

*[bootstrap] Documentation


Offcanvas

  • data-bs-backdrop - Static or true
  • data-bs-keyboard - Close on Escape
  • data-bs-scroll - Allow body scroll

*[bootstrap] Documentation


General

  • data-bs-animation - Animate transitions (true/false)
  • data-bs-autohide - Auto-dismiss toasts
  • data-bs-config - Pass JSON config object

*[bootstrap] Documentation