Class Wbr


public class Wbr extends StyledElement<Wbr>
Represents an HTML <wbr> (Word Break Opportunity) element for suggesting line break points.

This class provides functionality to create word break opportunity markers within text. The <wbr> element represents a position within text where the browser may optionally break a line, though it will not force a break. This is particularly useful for long words, URLs, email addresses, or compound terms that might overflow their container if not broken. Unlike the <br> element which forces a line break, <wbr> only suggests a break point that the browser can use if needed for proper text wrapping.

Features:

  • Suggests optional line break positions without forcing breaks
  • Helps manage long unbreakable strings (URLs, email addresses, etc.)
  • Prevents text overflow in constrained layouts
  • Improves responsive design and text wrapping
  • Has no visual representation when line breaks are not needed
  • Extends StyledElement as a void element with no content

Usage:


 // Long URL with break opportunities
 P paragraph = new P();
 paragraph.addElement(new Text("Visit http://"));
 paragraph.addElement(new Wbr());
 paragraph.addElement(new Text("www."));
 paragraph.addElement(new Wbr());
 paragraph.addElement(new Text("example."));
 paragraph.addElement(new Wbr());
 paragraph.addElement(new Text("com/"));
 paragraph.addElement(new Wbr());
 paragraph.addElement(new Text("very/"));
 paragraph.addElement(new Wbr());
 paragraph.addElement(new Text("long/"));
 paragraph.addElement(new Wbr());
 paragraph.addElement(new Text("path"));

 // Long compound word
 Span term = new Span();
 term.addElement(new Text("pneumono"));
 term.addElement(new Wbr());
 term.addElement(new Text("ultra"));
 term.addElement(new Wbr());
 term.addElement(new Text("microscopic"));
 term.addElement(new Wbr());
 term.addElement(new Text("silico"));
 term.addElement(new Wbr());
 term.addElement(new Text("volcano"));
 term.addElement(new Wbr());
 term.addElement(new Text("coniosis"));

 // Simple break opportunity
 Wbr breakPoint = new Wbr();
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Wbr

      public Wbr()
      Constructs a Wbr element.

      Creates a new <wbr> element that represents an optional line break opportunity. The browser may choose to break the line at this point if needed for proper text wrapping, but will not force a break.