My Drupal 7 site is printing out leading and trailing whitespace and a line break within the page title <h1>. The following is an exact copy and paste of the HTML that's being delivered to the browser:

<h1 class="title" id="page-title">
                I am a Page Title               </h1>

Not too big of a deal as most browsers know to ignore whitespace... except Chrome for Windows... where it's making the last word in the page title wrap to the next line (I confirmed this by deleting the whitespace in Chrome's web inspector):

Chrome for Windows and Mac

Why is it doing that? Is there a fix? I can think of a handful of ways to trim the the whitespace using Javascript (can it be done with CSS?), but I'd rather fix it at the source.

  • 1
    Could you share what your template file looks like at that specific point too please? Jan 9, 2015 at 15:11
  • 1
    Check out your page.tpl.php and var_dump your $title variable you should be able to take care of it there.
    – sareed
    Jan 9, 2015 at 15:13
  • @sareed Duh! Of course! You're right. I took a look a the template file, removed the whitespace, and now all works well. If you want to post an answer, I'll flag it as the answer. Thanks!
    – Sam
    Jan 9, 2015 at 15:56

1 Answer 1


In the page.tpl.php file, the page title bit looks like this:

            <h1 class="title" id="page-title">
                <?php print $title; ?>

Simply removing the trailing/leading whitespace (tabs and new lines) from the code, did the trick:

            <h1 class="title" id="page-title"><?php print $title; ?></h1>


(Thanks to @sareed and @slawrence10 for the comments that jogged my memory as to how to deal with this!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.