Introduction
This proposal introduces a new media query, prefers-interaction-direction, which allows web developers to adapt their layouts and user interfaces based on the user's preferred interaction direction. The media query informs the website about the optimal placement of interactive elements, such as login forms and navigation bars, to enhance user experience and accessibility.
This could be very helpful to users for several reasons:
- accessibility, supporting less able users
- right/left handedness-based preference/ability
- general/stylistic/usability preference
Syntax
The prefers-interaction-direction media query accepts the following values:
The media query can be used as follows:
@media (prefers-interaction-direction: left) {
/* Styles for left-side interaction preference */
}
@media (prefers-interaction-direction: right) {
/* Styles for right-side interaction preference */
}
@media (prefers-interaction-direction: top) {
/* Styles for top-side interaction preference */
}
@media (prefers-interaction-direction: bottom) {
/* Styles for bottom-side interaction preference */
}
Combining Interaction Directions
The prefers-interaction-direction media query allows for combining interaction directions to target specific user preferences.
For example, these two would be equivalent:
@media (prefers-interaction-direction: top right) {
@media (prefers-interaction-direction: top) and (prefers-interaction-direction: right) {
** These queries would target users with top-side and right-side interaction preferences set (independently checked, not corner-specific)
This feature enables web developers to create more tailored user experiences based on the combination of the user's preferred interaction directions.
Overriding the User Preference
To provide flexibility and control to web developers, a new CSS property, interaction-direction, is introduced to override the user's preferred interaction direction. This property functions similarly to the color-scheme property, which overrides the prefers-color-scheme media query.
.login-form {
interaction-direction: right;
}
.login-form {
/* Prevents the user agent from overriding the interaction direction for the element. */
interaction-direction: only right;
}
The interaction-direction property accepts the same values as the prefers-interaction-direction media query, allowing web developers to explicitly set the interaction direction for specific elements.
/* Default value */
interaction-direction: normal;
/* Single-direction values */
interaction-direction: top;
interaction-direction: bottom;
interaction-direction: left;
interaction-direction: right;
/* Direction-paired values */
interaction-direction: top left;
interaction-direction: top right;
interaction-direction: bottom left;
interaction-direction: bottom right;
/* Global values */
interaction-direction: inherit;
interaction-direction: initial;
interaction-direction: revert;
interaction-direction: revert-layer;
interaction-direction: unset;
Any of the "Single-direction values" or "Direction-paired values" listed above could also be used with only to override default UA behavior.
One consideration is whether "Direction-paired values" should support only used once for both values or if it should be used per value as needed.
interaction-direction: only top left;
/* or */
interaction-direction: only top only left;
Prior Art
- Chrome (iOS only currently) allows users to choose whether to show the address/actions bar at the top or bottom. Similar to the color-scheme setting, which typically supports options: System Default/Light/Dark, apps could do the same with System Default/Top/Bottom or System Default/Left/Right, respectively. https://www.androidpolice.com/chrome-for-ios-bottom-bar-official/
- While X-axis-specific features are less common than Y-axis-specific ones, many applications and OS features also allow this as well, such as Adobe CC apps, Visual Studio, and Apple's Stage Manager and dock, allowing users to configure their preference between left/right options.
References and inspiration
Conclusion
The introduction of the prefers-interaction-direction media query and the interaction-direction property would empower developers to create more dynamically responsive and accessible user interfaces. By adapting to the user's preferred interaction direction, websites can enhance the user experience and cater to diverse user preferences and needs.
Introduction
This proposal introduces a new media query,
prefers-interaction-direction, which allows web developers to adapt their layouts and user interfaces based on the user's preferred interaction direction. The media query informs the website about the optimal placement of interactive elements, such as login forms and navigation bars, to enhance user experience and accessibility.This could be very helpful to users for several reasons:
Syntax
The
prefers-interaction-directionmedia query accepts the following values:leftrighttopbottomThe media query can be used as follows:
Combining Interaction Directions
The
prefers-interaction-directionmedia query allows for combining interaction directions to target specific user preferences.For example, these two would be equivalent:
This feature enables web developers to create more tailored user experiences based on the combination of the user's preferred interaction directions.
Overriding the User Preference
To provide flexibility and control to web developers, a new CSS property,
interaction-direction, is introduced to override the user's preferred interaction direction. This property functions similarly to thecolor-schemeproperty, which overrides theprefers-color-schememedia query.The
interaction-directionproperty accepts the same values as theprefers-interaction-directionmedia query, allowing web developers to explicitly set the interaction direction for specific elements.Any of the "Single-direction values" or "Direction-paired values" listed above could also be used with
onlyto override default UA behavior.One consideration is whether "Direction-paired values" should support
onlyused once for both values or if it should be used per value as needed.Prior Art
References and inspiration
https://www.smashingmagazine.com/2016/09/the-thumb-zone-designing-for-mobile-users/
https://www.smashingmagazine.com/2019/08/bottom-navigation-pattern-mobile-web-pages/
https://www.scotthurff.com/posts/how-to-design-for-thumbs-in-the-era-of-huge-screens/
https://www.scotthurff.com/posts/facebook-paper-gestures/
https://konsav.medium.com/-55aba8ed3859
https://www.uxmatters.com/mt/archives/2013/02/how-do-users-really-hold-mobile-devices.php
https://www.lukew.com/ff/entry.asp?1927
Conclusion
The introduction of the
prefers-interaction-directionmedia query and theinteraction-directionproperty would empower developers to create more dynamically responsive and accessible user interfaces. By adapting to the user's preferred interaction direction, websites can enhance the user experience and cater to diverse user preferences and needs.