How can you achieve device-specific functionality using HTML and JavaScript?
Instruction: Discuss methods to tailor web content or functionality based on the user's device.
Context: This question assesses the candidate's ability to implement responsive design and functionality, using HTML and JavaScript to detect and adapt to different devices.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
Adapt to the capability or preference needed for the task instead of inferring a device category from a user-agent string or viewport width. A laptop can have touch, a phone can have a keyboard, and input devices can change.
Use CSS media queries for layout and preferences such as reduced motion, and JavaScript feature detection for an optional API...