Skip to content
Tutorials Center
My learning

Topics

Lesson 96 of 139 ยท UI Components

User Interface Properties

Control how people interact with your page using cursor, resize, user-select, pointer-events, caret-color, accent-color, scrollbar styling and touch-action.

Most CSS decides how things look. A small family of properties decides how things behave when people interact with them: which cursor appears, whether a box can be resized, whether text can be selected, whether clicks pass through an element, how scrollbars are drawn and how touch gestures are handled.

These properties are small, but they shape how an interface feels. Used well, they make a page feel polished and native. Used carelessly, they break copying, hide clickable things or trap people on touch screens. This lesson closes the UI Components chapter with a tour of each one, along with the mistakes to avoid.

cursor

The cursor property sets the mouse pointer shown over an element. Browsers already pick sensible cursors: an I-beam over text, a hand over links. You only need cursor when you build something the browser can't know about.

Value Meaning Typical use
default The normal arrow Resetting an inherited cursor
pointer A hand Buttons and custom clickable elements
text An I-beam Editable or selectable text
not-allowed A circle with a line Disabled controls
wait / progress Busy (progress means you can still click) Long operations
help Arrow with a question mark Elements with extra explanations
grab / grabbing Open and closed hand Draggable items, while idle and while dragging
move Four arrows Moving an element
zoom-in / zoom-out Magnifying glass Image viewers
col-resize, ns-resize, ew-resizeโ€ฆ Resize arrows Split panes, resize handles
crosshair Thin cross Picking a point, drawing
none No cursor Games, full-screen media
A cursor gallery

The last box uses a custom cursor image: url(...), then the hotspot coordinates (the exact pixel that "points", here the center at 16 16), then a required fallback keyword. Keep custom cursors to 32 by 32 pixels or smaller; browsers ignore large ones.

Cursors are hints, not features. A cursor change only helps mouse users. Anything clickable must also be a real <button> or link so keyboard and touch users can reach it. And don't change cursors just for decoration: a pointer cursor on something that isn't clickable makes people click and wonder why nothing happens.

resize

resize lets users drag the bottom-right corner of an element to change its size. Text areas have it on by default; you can turn it off, restrict it, or add it to other elements:

  • none, both, horizontal, vertical
  • block and inline: the logical versions, which follow the writing mode.

There's one condition that surprises everyone: resize only works when overflow is something other than visible. A plain <div> needs overflow: auto (or hidden) before the handle appears.

CSS
textarea { resize: vertical; }           /* height only: never breaks the layout */
.panel   { resize: both; overflow: auto; }

Restricting a <textarea> to vertical is a good default: people can make it taller for long messages without pushing it wider than its column. Add min-height and max-width to keep resizing within reason.

user-select

user-select controls whether text can be selected:

Value Effect
auto The default behavior
none The text can't be selected
text Selectable, even inside an element that disables selection
all One click selects the whole element

none is useful for interface chrome that gets selected by accident during fast clicking: button labels, tab names, drag handles. all is lovely for things people copy as a whole, like a code snippet, an API key display or a coupon code.

Don't disable selection on content. Blocking selection of articles, prices or addresses doesn't stop copying (anyone can open the page source), but it does annoy everyone who wants to quote, translate or look up a word, and it can interfere with assistive tools. Use user-select: none only on controls.

Safari still needs the prefixed -webkit-user-select for some values, so write both when it matters.

caret-color and accent-color

Two properties tint parts of form controls without rebuilding them:

  • caret-color sets the color of the blinking text cursor in inputs, text areas and contenteditable elements. The default, auto, uses the text color.
  • accent-color tints the checked parts of checkboxes, radio buttons, range sliders and progress bars. It's covered with examples in Styling Forms.
resize, user-select and caret-color

pointer-events

pointer-events: none makes an element invisible to the mouse and to touch. Clicks, taps and hovers pass straight through to whatever is underneath, as if the element weren't there. (SVG supports several more values, such as visiblePainted and stroke, for fine control over which parts react.)

Common uses:

  • Decorative overlays. A gradient fade on top of a scrolling list, a watermark or a glow effect shouldn't block clicks on the content below.
  • Hidden tooltips and menus that fade out with opacity: 0 but would otherwise still catch hovers. The Tooltips lesson uses this.
  • Labels inside custom controls, where the click should reach the input underneath.
Clicking through an overlay

pointer-events: none is not a way to disable things. It blocks the mouse only. A button with pointer-events: none can still be focused with Tab and activated with Enter, and screen readers still announce it as usable. To disable a control, use the disabled attribute; to disable a whole region, use the HTML inert attribute, which blocks the mouse, the keyboard and assistive technology at once.

appearance

appearance controls whether form controls are drawn with the operating system's native look. appearance: none removes it, leaving a plain box you style yourself, which is how custom checkboxes, selects and progress bars start. appearance: auto restores the native look. Styling Forms walks through it; remember that after appearance: none, you're responsible for every state the browser used to draw for you.

Scrollbar styling

Three standard properties shape scrollbars, and they're covered in depth in Overflow:

  • scrollbar-width: auto, thin, or none (hidden, but the area still scrolls).
  • scrollbar-color: two colors, the thumb and then the track: scrollbar-color: #0d9488 #ccfbf1;.
  • scrollbar-gutter: stable: reserves the scrollbar's space even when there's nothing to scroll, so content doesn't jump sideways when a scrollbar appears.
CSS
.sidebar {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #94a3b8 transparent;
  scrollbar-gutter: stable;
}

These work in all current browsers. Older Chromium and Safari versions only supported the non-standard ::-webkit-scrollbar pseudo-elements, which you'll still see in older code. Modern Chromium ignores those when the standard properties are set.

Be careful with scrollbar-width: none. Hiding the scrollbar hides the only visible sign that an area scrolls, and some mouse users depend on dragging it. Use it for things like a horizontal row of chips that also has arrow buttons, not for main content.

touch-action

On touch screens, the browser handles gestures itself: one finger scrolls (pans), two fingers zoom, and a double-tap may zoom too. touch-action tells the browser which of those gestures it may handle on an element, leaving the rest to your JavaScript:

Value The browser handles
auto Everything (default)
manipulation Panning and pinch-zoom, but not double-tap zoom
pan-x / pan-y Only horizontal / vertical scrolling
pinch-zoom Only pinch-zoom (combine with pan-x or pan-y)
none Nothing; your script gets every touch
CSS
/* A drawing canvas: every finger movement draws, nothing scrolls */
canvas.sketchpad { touch-action: none; }

/* A horizontal carousel that should still let the page scroll vertically */
.carousel { touch-action: pan-y; }

/* Buttons in a game or calculator: no double-tap zoom delay */
.keypad button { touch-action: manipulation; }

The carousel example reads backward at first: pan-y lets the browser scroll the page vertically, while your swipe code handles horizontal movement.

touch-action: none on large areas is risky: if a whole page section ignores gestures, people on phones can get stuck unable to scroll past it. Apply it only to the exact element that needs custom gestures. (touch-action can't be shown in a desktop preview, so this section uses read-only code.)

Mobile browsers flash a gray or blue box when you tap a link or button. -webkit-tap-highlight-color: transparent removes it. If you remove it, make sure your own :active style gives tap feedback instead, as in Styling Buttons and Links.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. You add resize set to both on a <div>, but no resize handle appears. What is missing?

    resize only applies to elements whose overflow isn't visible. Add overflow: auto or hidden.
  2. 2. Which is a good use of user-select set to all?

    all selects the entire element with one click, which is handy for codes and snippets. Content should stay normally selectable.
  3. 3. A button has pointer-events set to none. What still works?

    pointer-events only affects pointer input. Use the disabled attribute or inert to block keyboard and assistive technology too.
  4. 4. What does scrollbar-gutter set to stable do?

    The gutter is kept even when nothing overflows, so layouts don't jump sideways.
  5. 5. Which touch-action value suits a drawing canvas where every finger movement should draw?

    none stops the browser from scrolling or zooming on that element, so your script receives every touch.

Summary

  • cursor gives mouse users a hint about what an element does; custom cursors need a hotspot and a fallback keyword, and never replace real buttons and links.
  • resize works only when overflow isn't visible; resize: vertical is a safe default for text areas.
  • user-select: none belongs on controls, never on content; user-select: all selects a whole snippet in one click.
  • caret-color tints the text cursor and accent-color tints native checkboxes, radios, sliders and progress bars; appearance: none removes native styling entirely.
  • pointer-events: none lets clicks pass through overlays but doesn't disable keyboard access; use disabled or inert for that.
  • scrollbar-width, scrollbar-color and scrollbar-gutter style scrollbars in all current browsers; don't hide scrollbars on main content.
  • touch-action decides which touch gestures the browser handles; keep none limited to elements with custom gestures.

Next: Transitions, where the Transforms and Animation chapter begins with smooth changes between states.