w3c / w3c/csswg-drafts

[css-values-4] Add new relative length units that are relative to the size of the system cursor

Open
#8,315 11 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

css-ui-4 css-values-5
Dominant language
Bikeshed
Stars
4.9k
Forks
816
Avg merge
2d 18h
Merged PRs (30d)
24

Description

[Related bug in Firefox]

There are currently two ways for web developers to get tooltip behavior for a website, as listed in this example StackOverflow thread:

  • use a title attribute, which yields a standardized text tooltip managed by the browser;

  • create a CSS-customizable tooltip, listen to mouse move events with JavaScript to dynamically change the position of the tooltip, reveal it when some other element is hovered.

When computing the new position for a customizable tooltip with JavaScript, web developers will typically add an offset to account for the system cursor. However, because the system cursor size is not exposed, the offset they add is arbitrary and cannot account for varying cursor sizes. This causes problems for accessibility, as visually impaired users may set their cursors to a bigger size than the average and have their cursor cover the contents of the tooltip -- thus part of the information is not shown for them.

This can be seen in the StackOverflow thread listed above, where two different web developers answering the same question answered with a different arbitrary offset:

    // Offset of 20px
    tooltipSpan.style.top = (y + 20) + 'px';
    tooltipSpan.style.left = (x + 20) + 'px';
  // Offset of 10px
  tooltip.style.left =
      (e.pageX + tooltip.clientWidth + 10 < document.body.clientWidth)
          ? (e.pageX + 10 + "px")
          : (document.body.clientWidth + 5 - tooltip.clientWidth + "px");
  tooltip.style.top =
      (e.pageY + tooltip.clientHeight + 10 < document.body.clientHeight)
          ? (e.pageY + 10 + "px")
          : (document.body.clientHeight + 5 - tooltip.clientHeight + "px");

This issue proposes to add two new relative length units.

unit relative to
'scw' width of the system cursor
'sch' height of the system cursor

Browsers may let the option to users to use up-rounded or predefined system cursor sizes to limit fingerprinting.

The first example from above may then be changed to the following:

    tooltipSpan.style.top = 'calc(1sch + ' + y + 'px)';
    tooltipSpan.style.left = 'calc(1scw + ' + x + 'px)';

The second example could be partially adapted ...

  tooltip.style.left =
      (e.pageX + tooltip.clientWidth + 10 /* still arbitrary */ < document.body.clientWidth)
          ? ("calc(1scw + " + e.pageX + "px)")
          : ("calc(0.5scw + " + (document.body.clientWidth - tooltip.clientWidth) + "px)");
  tooltip.style.top =
      (e.pageY + tooltip.clientHeight + 10 /* still arbitrary */ < document.body.clientHeight)
          ? ("calc(1sch + " + e.pageY + "px)")
          : ("calc(0.5sch + " (document.body.clientHeight - tooltip.clientHeight) + "px)");

... but, as you can see, the proposed change would not be enough on its own to completely adapt the second example. This code is trying to assess from JavaScript whether the tooltip would be partially positioned outside the limits of the rendered page and not get rendered completely -- and adjust its position accordingly. For this example to not use any arbitrary offset, I believe we would have to expose the system cursor size directly to JavaScript -- so I'd like to hear your opinions regarding this possibility as well.

Thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the CSS Values 4 relative-length section and the linked Firefox bug, then read the discussion about cursor-size exposure and fingerprinting. This needs a resolved CSSWG design for scw and sch, including whether JavaScript access is needed, before a specification change can be considered done.

Written by the indexing model from the issue text.

Assessment

Tech stack
css
Domain
accessibility, frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.