Skip to content

[css-ruby] glyph placement inside bopomofo ruby #13533

Open

Description

@frivoal

As detailed in https://www.w3.org/TR/clreq/#positioning_of_zhuyin, the way bopomofo characters are expected to be arranged inside ruby is different from the normal inline text layout, and there are some very specific placement rules.

CSS ruby seems to assume that this will happen, but doesn't explicitly trigger that behavior, nor references any other means by which it would be triggered. There seems to be some kind of unstated assumption that if the ruby annotation is made of bopomofo characters, and if the ruby annotation is ruby-position is inter-character, and/or maybe if the ruby container is vertical, it will somehow happen, but there's nothing explicit.

The CSS Spec is quite precise about what happens to the positioning of the ruby annotation box that contains the bopomofo annotation, but not about what happens inside that box.

(Neither https://www.w3.org/TR/clreq/ nor css-ruby is super clear as to whether that kind of layout is also expected for horizontal bopomofo ruby. Example 15 seems to suggest that it is not expected, since it talks about aligning / spacing bopomofo characters in ways that are not that, but it does so without acknowledging the departure from special bopomofo placement.)

I think we need to specificy:

  • what exactly triggers this behavior. is it always on given some circumstances? Opt it? Opt out?
  • what the behavior actually is. CLREQ gives a good starting point for the happy path where everything is set up properly, but what if there's more than the max 3 characters + 1 tone mark that it expects? What if some aren't the same font-size? what if there's some non-bopommofo in there as well? What about…

A related key is whether this is primarily something handled at the font / text-shaping level, or at the layout engine level.

My read of the current css-ruby spec is that it probably does expect fonts / text-shaping to handle the this on their own. If so, the spec should probably call it out (and we should probably work with the relevant people to make sure it happens), and even then, there may be some work left to do for the css specs and layout engine in terms of placement: if you go by CLREQ, this isn't quite centered, and how does that interact with ruby-align (when text-justify is not ruby) anyway?

But as far as I can tell, fonts don't handle this currently (neither the placing of the tone mark, nor the spacing between the letters), so it may well be fully up to the css layout engine to handle this.

Should this just always happen whenever a ruby annotation contains up to 3 bopomofo letters + 1 tone mark, possibly restricted to inter-character ruby and ruby on vertical containers? Should this tied to an additional value of ruby-align (bopomofo?), possible together with an initial auto value if we want to make it opt-out rather than opt-in and possibly depend on the writing mode?

cc: @bobbytung, @fantasai, @upsuper

Activity

  1. added
    css-ruby-1
    i18n-tracker
    i18n-clreq
    on Feb 19, 2026
  2. bobbytung commented on Feb 20, 2026

    @bobbytung

    a quick reply:

    Ideally, when base texts in horizontal writing, bopomofo ruby should be in inter-character position. That's the most frequent usage in print books and textbooks. So better opt-out.

    I've tried to find a solution to adjust tone marks' position by font feature. The feature will be turned on when glyphs set to upright (ˋˊ˙ˇ those code points are not R / Tr in UTR#50). So ideally, all glyphs inside the box should be set to upright.

    About alignment, the only reference here. It's not centered but better than justified.

  3. r12a commented on Feb 22, 2026

    @r12a
    Contributor

    We have been over this time and again, so it seems we do need to work on the spec text...

    It's already pretty clear that the inter-character value is not just some general positioning mechanism, but is specifically intended for bopomofo right-side layout, which doesn't introduce non-bopomofo text, and which has very specific placement requirements, especially for the tone marks.

    This value is provided for the special case of traditional Chinese as used especially in Taiwan: ruby (made of bopomofo glyphs) in that context appears vertically along the right side of the base glyph, even when the layout of the base characters is horizontal

    However, I think this initial sentence needs to be dropped or rewritten:

    If the writing mode of the enclosing ruby container is vertical, this value has the same effect as over.

    Sure, it puts stuff on the right side of a character in verticallly set text, but It's not the same effect as 'over' because

    1. the same special positioning needs to be applied for bopomofo characters and tone marks, the latter being in a separate column to the right of the bopomofo
    2. it is always only one annotation per character
    3. it only involves bopomofo and its tone marks (no latin or other text allowed)
    4. the side of the line doesn't change depending on the script
    5. bopomofo can (though it's unusual) be displayed like furigana (see https://r12a.github.io/scripts/bopomofo/ontheweb). For that, just use the normal ruby position values. The inter-character value is meant to indicate that an annotation is displayed differently (ie. only to the right side of an individual character and using the appropriate relative placement of elements vertically and horizontally).
    6. These annotations always appear to the right side of a character whether in vertical or horizontal writing-mode. No distinction needs to be made as to how it behaves in either direction.

    There seems to be some kind of unstated assumption that if the ruby annotation is made of bopomofo characters, and if the ruby annotation is ruby-position is inter-character, and/or maybe if the ruby container is vertical, it will somehow happen, but there's nothing explicit.

    I did push for some clarity about the expected internal positioning here in the early stages, but it was resisted. As for how to do it: Bobby has been experimenting with font-based rendering of the inter-character bopomofo elements. Lot's of people have tried to think of it as embedded writing-mode direction changes — which has been pointed out numerous times to be a non-starter, given the precise relative positioning required for the internal elements. And in the early days Dave ... proposed that Webkit could just get the browser to use script to position the internal elements — which i think would probably be the simplest solution — but nothing happened.

    what exactly triggers this behavior. is it always on given some circumstances? Opt it? Opt out?

    Use of the inter-character value, only. And the expectation should be that only bopomofo characters and associated tone marks occur as the annotation.

    what the behavior actually is. CLREQ gives a good starting point for the happy path where everything is set up properly, but what if there's more than the max 3 characters + 1 tone mark that it expects? What if some aren't the same font-size? what if there's some non-bopommofo in there as well? What about…

    This is specifically for the bopoofo right-side rendering. So there won't be more than 3 character + 1 tone mark. They will all be of the appropriate size. There will not be non-bopomofo content. There won't be any internal markup or CSS value changes — the layout is clearly specified by the document Bobby points to. Bottom line: this is not intended to be for positioning general content to the right of a character; it is expressly and specifically aimed at rendering standard bopomofo annotations in their normal right-of-base-character position.

  4. frivoal commented on Feb 23, 2026

    @frivoal
    CollaboratorAuthor

    it only involves bopomofo and its tone marks (no latin or other text allowed)

    I completely agree that that's the intent, but here's the problem: HTML allows arbitrary content in the <rt> element. There is no way to force the markup to be limited to "up to 3 bopomofo charters and one tone mark". So even if it isn't meant to be used that way, we still must answer the question of what happens the markup contains other stuff, and css tries to apply that value.

    what if there's some non-bopommofo in there as well?

    This is specifically for the bopoofo right-side rendering. So there won't be more than 3 character + 1 tone mark.

    Again, it should not be used with more than 3 characters+1 tone mark, but given how HTML works, it can. It's bad to use it this way, but we cannot prevent that, so we need to know what happens if someone does that.

    Bottom line: this is not intended to be for positioning general content to the right of a character; it is expressly and specifically aimed at rendering standard bopomofo annotations in their normal right-of-base-character position.

    No disagreement as to the intent. Just saying: css applies to arbitrary HTML, so the behavior must be defined for arbitrary content. We do not have to go out of our way to make something "useful" outside of the recognized use-case, but the user agent will need to do something, and we should be clear on what that is.

  5. r12a commented on Feb 23, 2026

    @r12a
    Contributor

    So perhaps we can add text to the spec to say that behaviour is undefined and discouraged if people use things other than bopomofo characters and the appropriate tone marks.

    But we also, i believe, need to do something about that initial paragraph that seems to equate inter-character with over in vertical.

  6. frivoal commented on Feb 23, 2026

    @frivoal
    CollaboratorAuthor

    I'd rather specify a simple-even if-not-necessarily-useful behavior than undefined behavior. Otherwise we run the risk that some popular web page(s) uses it wrong, depends on whatever currently popular browser happens to implement (which may or may not be simple, since it's undefined), forcing everyone else to reverse engineer that behavior, and us having to spec it later.

    If it's handled at the font level, that kind of falls out of how that gets implemented.

    If it's handled in CSS, maybe the simple-even-if-not-necessarily-useful behavior could simply be that if you have anything more than 3 bopomofo characters and a tone mark, the special layout mode is not invoked, and you get normal vertical layout within the ruby annotation (which is still placed inter-character in horizontal text, since you did ask for that).

    But we also, i believe, need to do something about that initial paragraph that seems to equate inter-character with over in vertical.

    +1

  7. frivoal commented on Feb 23, 2026

    @frivoal
    CollaboratorAuthor

    One extra question: is the layout logic described in CLREQ The One True layout logic used everywhere, or is that a simplified or compromise solution synthetized by the i18n group? I am asking not because I have any reason not to follow it, but because multiple sources (if they exist) could be informative about error case / corner case handling.

  8. r12a commented on Feb 23, 2026

    @r12a
    Contributor

    The information in CLReq is taken from The Reference published by the Taiwanese government that Bobby pointed to at https://language.moe.gov.tw/001/Upload/files/site_content/M0001/juyin/index.html.

  9. xfq commented on Mar 18, 2026

    @xfq
    Member

    Neither https://www.w3.org/TR/clreq/ nor css-ruby is super clear as to whether that kind of layout is also expected for horizontal bopomofo ruby.

    https://www.w3.org/TR/clreq/#positioning_of_zhuyin mentions horizontal writing mode in many places. I'm not sure which specific parts you found unclear. We can certainly make some improvements.

    what the behavior actually is. CLREQ gives a good starting point for the happy path where everything is set up properly, but what if there's more than the max 3 characters + 1 tone mark that it expects? What if some aren't the same font-size? what if there's some non-bopommofo in there as well? What about…

    I can discuss this issue with the Chinese Layout Task Force.

    But as far as I can tell, fonts don't handle this currently (neither the placing of the tone mark, nor the spacing between the letters), so it may well be fully up to the css layout engine to handle this.

    There are some discussions related to font implementation. You can check them out here: w3c/clreq#241

    One extra question: is the layout logic described in CLREQ The One True layout logic used everywhere, or is that a simplified or compromise solution synthetized by the i18n group? I am asking not because I have any reason not to follow it, but because multiple sources (if they exist) could be informative about error case / corner case handling.

    As I understand it, the content within clreq largely describes ideal typographic scenarios. In practice, you may encounter layouts that deviate from these guidelines. However, this does not necessarily imply that the behavior in clreq is incorrect. If you want further reference materials, we would be happy to look some up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    css-ruby-1css-ruby-2i18n-clreqi18n-tracker

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      Sponsor
      SponsoredKunjungi sekarang
      Promo