October 26 2008 • 10:05 PM

Turning Off Hyphenation for URLs

Beth wrote:

Any clever way you can think of to make InDesign recognize URLs so that it knows to never hyphenate them when breaking lines?

Well, we can’t make InDesign recognize URLs specifically, but we can give you a way to turn off hyphenation for a given string of text. Actually, there are a couple of ways.

First, you could apply the No Break style to the text. But that’s rather extreme, as it won’t let that chunk of text break from one line to another at all. That’s not helpful for long URLs, especially.

The second, more compassionate method, is to change the language of the text to [No Language]. After all, a URL isn’t really English (or Spanish or whatever), and you don’t want to spell-check it anyway. So setting it to No Language means that it won’t cause halts when checking your spelling, and InDesign simply stops trying to hyphenate it. Instead, long URLs break at the punctuation, or in the middle of a word if it’s really long.

If you need to specify a logical place for a long URL to break, you can insert a Discretionary Line Break.

By the way, how do you find all the URLs in your document? Well, one way is with GREP (CS3 and later). Keith Gilbert wrote up a nice method for this on his blog. You could, then, use that GREP to apply the no language designation. Or, in CS4, you could use GREP Styles to apply it automatically in the paragraph style.

5 Responses discussing this post. Add yours below.

  1. Phyllis
    October 28th, 2008 • 5:56 am • Link

    Fantastic tip! I now have a “No Language” character style set up in my default basic character styles (since I’ve had this problem many times). So I’ll be using that tip a lot… :-)

    Thanks!
    Phyllis

  2. Phyllis
    October 29th, 2008 • 7:40 am • Link

    “Instead, long URLs break at the punctuation, or in the middle of a word if it’s really long.”

    As far as I can tell, it *doesn’t* break in the middle of the word, but only at the punctuation. But that’s fine as I’m planning to add discretionary line breaks to all of mine. Takes a little while but will improve the results as I’m forever having the text reflow and cause problems with the URLs. Also, the discretionary line breaks will help me follow the style-manual rules of breaking the URL *before* the dot in .com, etc.

    So I set up a keyboard shortcut for discretionary line break…. :-)

  3. David Blatner
    October 30th, 2008 • 9:49 am • Link

    @Phyllis: Try a really, really long URL. I agree that a disc-linebreak kbsc is the best idea, though.

  4. Phyllis
    October 30th, 2008 • 11:51 am • Link

    Hey, I just made up a really long one and that worked. But a short one (like http://indesignsecrets.com) will overset rather than break anywhere other than at the punctuation (at least on mine). Weird.

    It’s a great tip though, so thanks! And I enjoyed the InDesign seminar yesterday!!!!!

  5. Donna
    February 27th, 2009 • 1:03 pm • Link

    Hi

    We publish books that include at times, thousands of listings that include URLs. We’ve been looking for ways to eliminate the manual breaking of URLs.

    The discretionary line break works great, but not in all cases. We search out the @ and put the dlb after it. I’ve experimented a bit and find that if you use the Adobe Paragraph Composer in the justification, it works much better. I also created a character stylesheet for .com where I applied “no break” . I searched and replaced all .coms and it worked. You could probably just search the period if you want to get them all.

    If any of you use Indata to import databases, there is a string you can write to break them automatically at the @ if you reach a certain amount of characters in a line. Because many of our URLs are indented on the second line, with this string, you can put a return after the @ and insert a tab.

Subscribe to the Discussion

Get the ongoing discussion surrounding "Turning Off Hyphenation for URLs" delivered to you. Click here to subscribe via RSS.

Leave a Reply

You can use limited HTML tags, such as <em></em> for emphasis/italics and <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .

InDesignSecrets reserves the right to edit and/or remove posts and comments.