CSS

CSS Overview Selectors Declarations Rule Sets Comments Reset/Normalize Origin Importance Order Specificity Inheritance Cascade Layers Inline Styles Internal Styles External Styles @import Absolute Units Relative Units Dynamic Viewport Angle Units Time Units Frequency Units: Resolution Units Keywords Color Formats Color Functions & Spaces Background Color Background Image Background Repeat Background Position Background Size Background Attachment Background Shorthand Multiple Backgrounds Linear Gradients Radial Gradients Conic Gradients Font Family Font Size Font Weight Font Style Line Height Text Align Text Decoration Text Transform Letter Spacing Word Spacing Text Shadow Text Wrap Variable Fonts Content Box Padding Box Border Box Margin Box Box Sizing Property Margin Padding Border Outline Box Shadow Block Display Inline Display Inline Block Display Static Position Relative Position Absolute Position Fixed Position Sticky Position Top Element Position Right Element Position Bottom Element Position Left Element Position Z Index Flexbox Box Layout Display Flex Flex Direction Flex Wrap Justify Content Align Items Align Content Gap, Row Gap & Column Gap Flex Grow Flex Shrink Flex Basis Flex Shorthand Order Property Align Self Practical Applications CSS Grid Layout Grid Display Grid Template Columns Grid Template Rows Grid Template Areas Justify Items Grid Auto Columns Justify Self Nested Grids Responsive Web Design Min Width Max Width Orientation Logical Operators Pointer Hover Prefers Color Scheme Fluid Images Flexible Typography Viewport Width Advanced CSS Features Defining variables Using variables Scope & Inheritance of CSS Variables Property Value Fallback Practical Applications :Hover :Active :Focus :Focus Visible :Visited :Link :First Child :Last Child :Nth Child :Nth of Type :Empty :Checked :Disabled :Enabled :Valid :Invalid :Required :Has :Not :Is :Where ::Before Pseudo Element ::After Pseudo Element ::First Letter ::First Line ::Selection ::Marker CSS 2D Transformations CSS 3D Transformations Transform Origin Transform Style Backface Visibility Transition Property Transition Duration Transition Timing Function Transition Delay Transition Shorthand Ease Timing Function Linear Timing Function Ease In Timing Function Ease Out Timing Function Ease In Out Timing Function Cubic Bezier Function Animations (@keyframes) Defining @keyframes Animation Name CSS Animation Duration Animation Timing Function CSS Animation Delay CSS Animation Iteration Count Animations Direction CSS Animation Fill Mode CSS Animation Play State CSS Filter Blur CSS Filter Brightness CSS Filter Contrast() CSS Drop Shadow CSS Grayscale CSS Hue Rotate CSS Invert CSS Opacity CSS Saturate CSS Sepia Mix Blend Mode Background Blend Mode Object Fit & Object Position Scroll Snap Type Scroll Snap Align Scroll Padding Scroll Margin Scroll Triggered Animations JS Variables

Pointer


Feature queries in CSS, using the @media at-rule, allow you to test for the user's input mechanism and preferences. This enables the creation of more adaptive and user-friendly web interfaces by applying styles based on the capabilities of their device.


pointer

The pointer media feature is used to test whether the user's primary input mechanism is a pointing device, and if so, how accurate it is. This is crucial for adapting interfaces for touchscreens versus traditional mice.

Example 1: Basic Pointer Detection

/* styles.css */
/* Targets devices with a fine-accuracy pointing device like a mouse */
@media (pointer: fine) {
  .button {
    /* Make buttons smaller for precise cursor interaction */
    padding: 8px 16px;
  }
}

Explanation

This code applies specific padding to elements with the class .button only when the user's device has a fine pointer, such as a mouse. This allows for smaller, more compact UI elements that are still easy to click.


Example 2: Coarse Pointer for Touchscreens

/* styles.css */
/* Targets devices with a coarse-accuracy pointing device like a finger on a touchscreen */
@media (pointer: coarse) {
  .button {
    /* Increase button size for easier touch interaction */
    padding: 15px 25px;
  }
}

Explanation

This example targets touch-enabled devices where the primary input is less precise. The CSS increases the padding of .button elements, making them larger and easier to tap accurately with a finger.


Example 3: No Pointer Device

/* styles.css */
/* Targets devices with no pointing device, like a keyboard-only user */
@media (pointer: none) {
  .nav-link {
    /* Add a visible focus outline for keyboard navigation */
    outline: 2px solid blue;
  }
}

Explanation

When a device has no pointing mechanism, navigation is often done via keyboard. This code ensures that .nav-link elements have a clear visual outline when focused, improving accessibility for keyboard users.


Example 4: Combining Pointer with Other Media Features

/* styles.css */
/* Targets devices with a fine pointer on a wide screen */
@media (pointer: fine) and (min-width: 1024px) {
  .gallery-item {
    /* Apply a special effect only for mouse users on large screens */
    transform: scale(1.05);
  }
}

Explanation

This demonstrates how to chain media features. The transform style for .gallery-item will only be applied if the device has a fine pointer AND the viewport is at least 1024 pixels wide.


Example 5: Styling for Any Pointer Presence

/* styles.css */
/* This will apply to any device that has some form of pointing device */
@media (pointer: any) {
  .interactive-element {
    /* Indicates to the user that this element is interactive */
    cursor: pointer;
  }
}

Explanation

The any-pointer value can be used to apply styles if any available pointer is present. Here, it changes the cursor to a pointer for .interactive-element, providing a visual cue of interactivity.