[whatwg] Interaction of <wbr> and CSS white-space

Boris Zbarsky bzbarsky at MIT.EDU
Sat May 14 00:41:40 PDT 2011

On 5/14/11 3:29 AM, Jukka K. Korpela wrote:
>  > "The wbr element is expected to override the 'white-space' property and
>  > always provide a line-breaking opportunity."
>  >
>  > Why is this desirable?
> It reflects the original and useful idea of <wbr>, which is supposed to
> introduce a specific rule in line breaking, making an exception to
> normal line breaking rules.

Yes, by introducing a break opportunity where there was none before.

But why should this override CSS that says "do not break at any break 

> This is conceptually simple and means that such a rule is included in the data itself.

I agree that the existence of the break opportunity is part of the 
content.  But whether to take it is part of the style.

> For example, when mentioning URLs in the text of a document, you
> normally want to prevent line breaks in them by default and only allow
> line breaks at specific points, as in
> http://www.whatwg.org/<wbr>specs/<wbr>web-apps/<wbr>current-work/<wbr>multipage/
> Oops, my newsreader introduced a line break after a hyphen. And such
> behavior is common in web browsers as well. So it is natural to wrap
> urls in text in <span class="url">...</span> with CSS rule .url {
> white-space: nowrap; }.

Except that browsers don't support that, for the most part.

The problem you describe is one of breakpoint prioritization.  I have no 
problem with <wbr> getting priority over breakpoints that the browser 
determines itself.  CSS3 Text has explicit language to the effect that 
not all breakpoint opportunities are equal in section 7.1.

> Anyway, the idea is to disallow line breaks (that would otherwise be
> allowed by line breaking rules, whatever they might be in each
> situation) _except_ where explicitly allowed by <wbr>.

This can be done by simply using "white-space: normal" and having UAs 
prioritize breaks at <wbr> over other linebreaks, no?

> This is needed for example in URLs, where browsers might otherwise break after "-" or
> "%" or some other special characters.

For what it's worth, I don't see why this is a problem necessarily. 
I'll take you word that it is, but I would appreciate an explanation if 
you're willing to provide one.

> How are we expected to deal with such issues if white-space: nowrap
> kills <wbr>?

See above.

>  > It seems to contradict what CSS3 Text is trying to define
> I think HTML specs need to specify the meaning of HTML markup, and style
> sheets will take it from that. It's up to HTML specs to say whether
> <wbr> specifies a line breaking opportunity.


> CSS specs may define a setting that unconditionally prevents line breaks somewhere

Yes, that's what "text-wrap: none" means.  Right now the HTML spec 
explicitly says that this setting should be ignore for <wbr>, which is 
what make no sense.

> or a setting that prevents line breaks except those explicitly allowed in
> markup

I would be just fine with such a setting.  There isn't one in CSS right now.

> So in the current situation, authors need to be cautious and use special
> tricks to make <wbr> work

OK, we agree so far.

> but in the long term, <wbr> should be defined
> in a simple and straightforward manner, so that in the future, authors
> can use it as a simple and effective tool.

I think defining <wbr> as a high-priority line-break opportunity would 
have that effect.

> The HTML specs cannot dictate what CSS specs do

They're trying to, is my point.  As an implementor I then have to 
reconcile the conflict somehow.  My current plan if it's up to me is to 
do so by completely ignoring the part of HTML5 that's conflicting with 
CSS here.

> and the meaning of
> white-space (in detail) is unknown - is it to be understood as in the
> CSS 2 specification (which is effectively dead), or in CSS 2.1 (which is
> the de-facto standard but formally only a draft that must not be cited
> except as work in progress), or in CSS 3 (which is very much work in
> progress and may change at any moment)?

The CSS 2.1 and CSS 3 meanings of "white-space: nowrap" are identical.

> So maybe the best way to convey the message is to remove the reference
> to white-space and add a note on the _HTML_ element <nobr> (even if it
> is kept as obsolete - the spec should still specify its meaning):
> "The wbr element specifies a line breaking opportunity even when used
> inside a nobr element."

I would be fine with that, if it's useful.  Is it useful?


More information about the whatwg mailing list