the Future of the Web
  • Home
  • Hire Us
  • Articles
  • About
  • Contact
  • Breaking Long URLs and Words

    Jan 25 2007

    Sometimes in your content you end up with some really long words or URLs that just won't wrap and end up screwing up the width of your content (especially in IE 6), or just running off the edge of the page.

    Some common solutions involve automatically shortening the word or URL to a character limit and putting three dots "..." after it. But what if you want the whole URL or word to be visible?

    I think the perfect solution is to have the URL wrap like words in a sentence, but how do you tell the browser to split the URL up?

    The answer is to use <wbr/>, the Word Break tag. This gives the browser a spot where it can split the line up. For example:

    http://www.thefutureoftheweb.com/<wbr/>blog/2007/1/<wbr/>breaking-long-urls

    This example gives the browser two places where it can break the URL and wrap the parts onto different lines:

    http://www.thefutureoftheweb.com/
    blog/2007/1/
    breaking-long-urls

    Unfortunately, the <wbr/> tag doesn't work in all browsers, only Firefox and Internet Explorer. Via QuirksMode, Gordon Mohr suggests another solution using CSS which makes <wbr/> work in Opera:

    wbr:after { content: "\00200B" }

    This adds &#8203; after the <wbr/>, an entity that achieves the same effect in Opera and Safari.

    Unfortunately, neither <wbr/> nor this CSS will work in Safari. You can try putting &#8203 directly into your HTML, but then you'll end up with weird squares in Internet Explorer 6. Don't you love browser compatibilities?

    For more info, check out the QuirksMode page I mentioned above.

    Tags: html wbr urls
    View 4 Comments | Add a comment
  • Comments

    1. Devon at 8:17am on January 26, 2007

    This is one of the few areas that Firefox actually annoys me, while everything else make me happy. If only Firefox would support the &shy; entity, life would be great. The soft break would be part of the content, and not the markup (which is where a soft break really belongs). It would allow for valid pages and never an excuse to leave code "broken". Even IE supports &shy;!

    But alas...I must admit....this is one of those <em>exceptionally few</em> situations where even I (a validation junkie), admit that an invalid page <em>might</em> have a right to exist.

    2. lewis at 5:02pm on February 4, 2007

    how do you come up with all these browser idiosyncrasies?!

    3. Martin Kliehm at 7:44pm on February 16, 2007

    The wbr element is not part of any standards specification. It's not even specified in working drafts of that rogue WHATWG group. It's tag soup invented by Netscape and copied by Microsoft.

    If you want some non-semantic extra markup, I found this construct works:

    exceptional<span class="break">  &nbsp;</span>longword

    .break {
    font-size: 1px;
    line-height: 1px;
    float:right !important;
    float: none;
    }

    4. Jesse Skinner at 7:48pm on February 16, 2007

    @Martin - Interesting, I had no idea it was non-standard. It explains why browser support is so scattered. Thanks for the clarification and additional suggestion.

    Add a Comment

    Note: HTML tags and entities will be converted so that they are displayed as you type them. This means if you type in <em>, people will see <em>, and if you type &lt;em&gt;, people will see &lt;em&gt;.

  • Request a Quote

  • Jesse Skinner

    Jesse Skinner
    • Hire Me
    • About Me
    • Email Me
    • RSS Feed RSS Icon
  • Recent Articles

    • Parse Accept-Language to detect a user's language
    • Twitter
    • Three years of The Future of the Web
    • Saving data to a file with PHP
    • Easy web scraping with PHP
    • See all the articles
    • IBM: Where and when to use Ajax
    • Code Igniter 1.6.0 Released
    • Update a Dev Site Automatically with Subversion
    • JavaScript Functions are Variables
    • See All...
  • Categories

    • javascript (37)
    • links (19)
    • about (18)
    • web (14)
    • server (10)
    • html (10)
    • css (8)
    • carnival (7)
    • browsers (7)
    • design (4)
    • seo (4)
    • ads (4)
    • standards (4)
    • events (4)
    • work (4)
  • Older Articles

    • May 2008
    • April 2008
    • February 2008
    • January 2008
    • December 2007
    • November 2007
    • September 2007
    • August 2007
    • July 2007
    • June 2007
    • May 2007
    • April 2007
    • March 2007
    • February 2007
    • January 2007
    • December 2006
    • November 2006
    • October 2006
    • September 2006
    • August 2006
    • July 2006
    • June 2006
    • May 2006
    • April 2006
    • March 2006
    • February 2006
    • January 2006
    • December 2005
    • November 2005
    • October 2005
    • September 2005
    • August 2005
    • April 2005
    • See All...
Copyright © 2008 Jesse Skinner | CSS | XHTML | RSS | Help | Impressum | Cutie Quilts | Internet Blog Top Sites