Cursor Pointer and Other Classes for Bootstrap

Learn via video courses
Topics Covered

Overview

The bootstrap cursor classes are used to change the appearance of the cursor when it is hovered over that item. By default, Bootstrap doesn't include the cursor pointer class or the CSS properties. But this can be done manually with the help of predefined cursor pointer bootstrap classes. We have plenty of options available to play with and let the users have a better experience. The cursor can be used to provide visual feedback on the element's behavior when it is hovered.

Cursor Pointer and other classes

Below give is a table that contains a category of the cursor's classes available. The second column is the CSS property that can be directly added to any element to change the appearance of the cursor. Bootstrap provides built-in easy to use classes which can directly be added to elements which are mentioned in the third column

CategoryCSS PropertyClass
Generalcursor: autocursor-auto
cursor: defaultcursor-default
cursor: nonecursor-none
Links & statuscursor: context-menucursor-context-menu
cursor: helpcursor-help
cursor: pointercursor-pointer
cursor: progresscursor-progress
cursor: waitcursor-wait
Selectioncursor: cellcursor-cell
cursor: crosshaircursor-crosshair
cursor: textcursor-text
cursor: vertical-textcursor-vertical-text
Drag & dropcursor: aliascursor-alias
cursor: copycursor-copy
cursor: movecursor-move
cursor: no-dropcursor-no-drop
cursor: not-allowedcursor-not-allowed
cursor: grabcursor-grab
cursor: grabbingcursor-grabbing
Resizing & scrollingcursor: all-scrollcursor-all-scroll
cursor: col-resizecursor-col-resize
cursor: row-resizecursor-row-resize
cursor: n-resizecursor-n-resize
cursor: e-resizecursor-e-resize
cursor: s-resizecursor-s-resize
cursor: w-resizecursor-w-resize
cursor: ne-resizecursor-ne-resize
cursor: nw-resizecursor-nw-resize
cursor: se-resizecursor-se-resize
cursor: sw-resizecursor-sw-resize
cursor: ew-resizecursor-ew-resize
cursor: ns-resizecursor-ns-resize
cursor: nesw-resizecursor-nesw-resize
cursor: nwse-resizecursor-nwse-resize
Zoomingcursor: zoom-incursor-zoom-in
cursor: zoom-outcursor-zoom-out

The most commonly used ones are default, zooming, drag and drop, and link and status ones. We can also manually create these classes by using the CSS cursor and respective property.

The most commonly used cursor classes are:

  • cursor-auto: This refers to the default cursor of the browser and assigns it to the current class.
  • cursor-pointer: This changes the cursor to a hand, giving an intuition that the given element is clickable.
  • cursor-not-allowed: Sets the cursor to the no-entry symbol usually used to show disabled or non-clickable elements.
  • cursor-wait: During buffering or loading cursor is changed to the hourglass so that the user gets the idea that it is processing and the user is not supposed to click randomly on the page.
  • cursor-move: For draggable elements, move cursor is used. The elements can be dragged and placed in some other place.
  • cursor-resize: Resize cursor indicates that the given element can be resized and is usually represented by an arrow.
  • cursor-text: Sets the cursor to a text cursor or "I-beam", suggesting that the element is the text that can be selected or edited.

It is essential for developers to understant that certain cursor styles may enhance visual design, it must not affect users with disabilities. Developers have to carefully consider all types of audiences to avoid unintentional accessibility barriers, ensuring a universally accessible and user-centered interface for all the users irrespective of their abilities or impairments.

Example: Add .cursor-pointer class to set a pointer cursor

Example 1 - Pointer Cursor

Output:

pointer cursor

Explanation: The class cursor-pointer changes the cursor to a pointer when it is hovered over the element.

Example 2 - Zoom IN and OUT

Output:

zoom in and out

Explanation: Similarly, for zoomable elements, we can make the cursor zoom in initially and zoom out when the element is zoomed in. This makes it easier for the user to understand what will happen when they click on elements. Alternative Way: The similar output can also be achieved if we use the css cursor property as follows:

Here, we are using inline CSS styling.

Example 3 - Copy and Move

Output:

copy and move

Explanation: Some elements facilitate drag and drop on the webpage. Copy, move, paste, etc. are part of this drag-and-drop utility.

Conclusion

  • Bootstrap cursor pointer classes can be applied in the HTML or within Bootstrap components to change the default cursor to a pointer.
  • Cursor Pointer bootstrap classes enhances user experience by providing a visual cue about an elemenet being clickable, zoomable, text only, etc.
  • Bootstrap offers classes like cursor-auto for default behaviour and other classes like cursor-wait, cursor-copy, cursor-not-allowed for special purposes.