Skip to content

[mediaqueries-5] prefers-interaction-side media query & interaction-side property #10244

Open
@brandonmcconnell

Description

@brandonmcconnell

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:

  • left
  • right
  • top
  • bottom

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a11y-trackerGroup bringing to attention of a11y, or tracked by the a11y Group but not needing response.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions