CSS Cursor
In this page:
selector {
cursor: pointer | default | text | move | not-allowed;
}
Standard Cursor Values
CSS pointer और default से आगे कई built-in cursor keywords define करता है, जिनमें text, move, grab, help, wait, crosshair, और ns-resize जैसे directional resize cursors शामिल हैं। सही cursor keyword चुनना users को यह बताने का एक छोटा लेकिन meaningful signal है कि कोई element click करने से पहले क्या करता है।
- किसी tooltip वाले elements पर cursor: help इस्तेमाल करें ताकि users जान सकें कि hover करने से ज़्यादा जानकारी मिलेगी।
- Accepted values:
- auto — browser context से चुनता है (initial)
- pointer | default — links के लिए hand | normal arrow
- text — text के लिए एक I-beam
- move — चार-दिशा arrows
- not-allowed — एक forbidden sign
- grab | grabbing — draggable
- wait | progress — busy states
- crosshair | help | zoom-in | zoom-out — precision, help और zoom
- ns-resize | ew-resize | nwse-resize — directional resize cursors
- inherit | initial | unset | revert — हर property द्वारा accepted CSS-wide keywords
उदाहरण: Standard Cursor Values
<style>
.help { cursor: help; background: #eef; padding: 6px 12px; display: inline-block; }
.move { cursor: move; background: #efe; padding: 6px 12px; display: inline-block; }
.grab { cursor: grab; background: #fee; padding: 6px 12px; display: inline-block; }
</style>
<span class="help">Help</span>
<span class="move">Move</span>
<span class="grab">Grab</span>
Custom Cursor Images
cursor एक या ज़्यादा image URLs accept करता है जिनके बाद एक ज़रूरी fallback keyword आता है, आपको एक branded custom cursor इस्तेमाल करने देते हुए फिर भी gracefully degrade करते हुए। अगर कोई भी image URL सफलतापूर्वक load नहीं होता, तो browser चुपचाप list के आख़िर में ज़रूरी keyword पर fall back हो जाता है।
- custom cursor images को छोटा रखें, लगभग 32 by 32 pixels, ताकि वे crisply render हों और जल्दी load हों।
- Accepted values:
- cursor: url(<image>), <fallback> — custom image
- cursor: url(<image>) x y, <fallback> — hotspot set करता है
- fallback keyword — हमेशा आख़िर में ज़रूरी
- image formats — .cur, .png, .svg common हैं
उदाहरण: Custom Cursor Images
<style>
.box {
cursor: url('custom-cursor.png'), pointer;
background: lightblue;
padding: 20px;
}
</style>
<div class="box">Falls back to pointer if the image fails</div>
Buttons पर cursor: pointer
pointer सबसे common cursor value है, किसी भी clickable चीज़ के ऊपर एक hand icon दिखाते हुए, और यह styled divs और spans जैसे non-native interactive elements पर खासतौर पर ज़रूरी है जो buttons की तरह act करते हैं।
- Native button और a elements ज़्यादातर browsers में पहले से default रूप से pointer दिखाते हैं, लेकिन इसे explicitly जोड़ना आपकी stylesheet में intent को साफ़ तरीके से document करता है।
- Accepted values:
- cursor: pointer — एक hand, clickable signal देता है
- cursor: auto — default, browser तय करता है
- cursor: default — arrow
- नोट: इसे सिर्फ genuinely interactive elements पर set करें
- inherit | initial | unset | revert — हर property द्वारा accepted CSS-wide keywords
उदाहरण: cursor: pointer on Buttons
<style>
.fake-button {
cursor: pointer;
background: royalblue;
color: white;
display: inline-block;
padding: 10px 20px;
}
</style>
<div class="fake-button">Styled div acting as a button</div>
Disabled Elements के लिए cursor: not-allowed
not-allowed एक circle के साथ एक line दिखाता है, साफ़ तरीके से यह बताते हुए कि कोई element मौजूद है लेकिन इस समय उसके साथ interact नहीं किया जा सकता, आमतौर पर disabled form controls के साथ जोड़ा जाता है।
- disabled buttons पर cursor: not-allowed को reduced opacity के साथ combine करें ताकि disabled state visually और cursor दोनों से साफ़ हो।
- Accepted values:
- cursor: not-allowed — forbidden sign
- cursor: default — plain arrow
- pointer-events: none — सभी clicks नज़रअंदाज़ करता है (सावधानी से इस्तेमाल करें)
- :disabled — जोड़ने के लिए selector
उदाहरण: cursor: not-allowed for Disabled Elements
<style>
button:disabled {
cursor: not-allowed;
opacity: 0.5;
}
</style>
<button disabled>Can't click me</button>
Interactive States और Overlays पर Cursor
आप :hover जैसे pseudo-classes से cursor को dynamically बदल सकते हैं, या इसे loading screens या modal backdrops जैसे full-page overlays पर globally लागू कर सकते हैं। hover पर एक cursor change अक्सर इकलौता visual cue होता है कि एक otherwise plain-looking element असल में clickable है।
- किसी full-page loading overlay पर cursor: wait set करें ताकि users समझें कि interface कुछ process कर रहा है।
- Accepted values:
- cursor: grab — draggable के ऊपर hover करना
- cursor: grabbing — drag करते समय
- cursor: zoom-in | zoom-out — image overlays के लिए
- cursor: pointer — clickable overlays के लिए
- inherit | initial | unset | revert — हर property द्वारा accepted CSS-wide keywords
उदाहरण: Cursor on Interactive States and Overlays
<style>
.card {
background: lightblue;
padding: 10px;
margin-bottom: 8px;
}
.card:hover {
cursor: pointer;
}
.overlay {
background: #333;
color: white;
padding: 10px;
cursor: wait;
}
</style>
<div class="card">Hover to see the pointer cursor</div>
<div class="overlay">Full-page loading overlay</div>
- custom-styled clickable divs पर default cursor छोड़ देना, visitors को pointer cursor के बिना यह realize न होना कि एक styled div interactive है।
- उन elements पर cursor: pointer इस्तेमाल करना जो असल में clickable नहीं हैं, जो users को किसी action की उम्मीद में गुमराह करता है।
- किसी custom cursor image के बाद एक fallback keyword भूल जाना, अगर image load न हो तो browser के पास fall back करने के लिए कुछ नहीं होता।
- cursor mouse pointer की shape बदलता है यह बताने के लिए कि किसी element के साथ interact करने पर क्या होगा।
- Custom cursor images एक URL के बाद pointer या auto जैसे fallback keyword से set की जा सकती हैं।
- cursor: pointer clickable elements को signal करता है, जबकि cursor: not-allowed एक disabled या blocked action को signal करता है।
cursor property और उसकी standard keyword values हर modern और legacy browsers द्वारा supported हैं; custom image cursors बहुत पुराने browser versions को छोड़कर हर जगह supported हैं।
Chapter Quiz — Complete all 25 topics to unlock
0/25 topics done
Complete these topics first:
- CSS Container Queries
- CSS Subgrid
- CSS Logical Properties
- CSS Logical Sizing
- CSS Writing Modes
- CSS Aspect Ratio
- CSS Object Fit
- CSS object-position
- CSS Masking
- CSS Math Functions
- CSS Motion Path
- CSS @supports
- CSS @property
- CSS At-Rules
- CSS Cursor
- CSS Will Change
- CSS User Interface
- CSS Print Styles
- CSS Pagination (Print)
- CSS Dark Mode
- CSS Accessibility
- CSS Performance
- CSS Preprocessors
- CSS Frameworks Overview
- CSS Interview Prep