- Home
- /
- Tutorials
- /
- CSS Tutorial
- /
- CSS User Interface
CSS Accessibility
CSS User Interface
Control selection, pointer hit testing, resizing, caret appearance, cursors, and other interaction-facing CSS without hiding usable states. It covers pointer hit testing, selection, resizing, carets, cursors, control feedback, and accessibility boundaries.
A few CSS properties change how things feel to use: whether text can be selected, which cursor appears, whether a textbox can be resized. They are small, and easy to misuse in ways that frustrate people.
The rule of thumb: use them to make something clearer, never to take away something people rely on, like selecting text or seeing where the keyboard focus is. This lesson connects with Accessible CSS and Modern Form Styling.
Selecting and clicking
Example
css
.drag-handle {
user-select: none;
cursor: grab;
}
.decoration {
pointer-events: none;
}user-select: none stops text from being highlighted when someone drags the handle, which is the right place for it. Do not put it on articles or prices; people copy text all the time. cursor: grab shows a hand, so it looks draggable.
pointer-events: none makes an element ignore the mouse, so clicks go through to whatever is underneath. That is useful for decorative overlays. It does not disable a button: the keyboard can still reach and press it. Use the disabled attribute for that.
Text boxes
Example
css
textarea {
resize: block;
min-block-size: 8rem;
caret-color: currentColor;
}resize: block lets people make the textarea taller but not wider, so it never breaks the layout. Avoid resize: none unless the box grows on its own; otherwise long messages get hidden. caret-color sets the color of the blinking cursor.
Touch gestures
Example
css
.horizontal-slider {
touch-action: pan-y pinch-zoom;
}touch-action tells the browser which gestures to keep. This slider keeps vertical scrolling and pinch zoom, while sideways swipes go to the slider. Never block all gestures on a large area, or people will not be able to scroll the page.
User Interface Properties
| Property | Purpose | Example |
|---|---|---|
| user-select | Controls text selection. | user-select: none |
| pointer-events | Controls pointer hit testing. | pointer-events: none |
| resize | Controls author-provided resizing. | resize: block |
| caret-color | Sets the insertion caret color. | caret-color: currentColor |
| touch-action | Declares which direct-manipulation gestures remain available. | touch-action: pan-y pinch-zoom |
Complete Example
Complete runnable example
html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CSS User Interface example</title>
<style>
* { box-sizing: border-box; }
body {
margin: 0;
padding: 2rem;
font-family: system-ui, sans-serif;
line-height: 1.5;
}
main { max-width: 70rem; margin-inline: auto; }
article, section, aside, form, .card, .panel {
padding: 1rem;
border: 1px solid #cbd5e1;
border-radius: 0.6rem;
}
.drag-handle {
user-select: none;
cursor: grab;
}
.decoration {
pointer-events: none;
}
textarea {
resize: block;
min-block-size: 8rem;
caret-color: currentColor;
}
.horizontal-slider {
touch-action: pan-y pinch-zoom;
}
</style>
</head>
<body>
<main><p class="drag-handle">Drag handle text</p><span class="decoration">Decorative overlay</span><label for="notes">Resizable notes</label><textarea id="notes">Edit this text and resize the field.</textarea></main>
</body>
</html>Browser Support
Feature | Chrome | Edge | Firefox | Safari |
|---|---|---|---|---|
| pointer-events | 1 | 12 | 1.5 | 4 |
| user-select | 54 | 79 | 69 | 3 |
| resize | 1 | 79 | 4 | 3 |
| touch-action | 36 | 12 | 52 | 13 |
Versions show the first stable desktop release with unprefixed support. Data source: MDN Browser Compatibility Data 8.0.8. A partial-support note is included where it changes how the example behaves.
Remember
A custom cursor is a hint, not a signal anyone can depend on. Hover, focus, active and disabled states still need to be visible, and HTML attributes, not CSS, are what make a control disabled or read-only.
CSS User Interface exercises
A hand
Show a hand cursor over the button.
The HTML your code works on
<button class="btn">Go</button>
<button class="off" disabled>No</button>
<textarea class="note"></textarea>
<p class="code">npm install</p>
<div class="panel">Panel</div>Result
