SharePoint Tip – How To Set Word Wrapping on List Column Headers

I have a list in SharePoint that has numbers of columns with very long headers and I’d like to wrap these long headers so that I can have more columns shown on the screen. By default, I couldn’t. But with a little nice trick, I can.

The reason why I couldn’t by default because the default CSS style sheet the list uses has white-space: nowrap in place that prevents anything from wrapping. If we want the header wrapped we need to find a way to overwrite the white-space style with normal instead.

So here is how I did it, inspired by Ryan here.

Go to my list, select Site Actions and choose Edit Page.

Sharepoint - edit page

Click Add a web part, then select Media and Content and Content Editor, and click Add to add the selected web part to the current page.

Sharepoint - add webpart

Select the newly added web part, and select HTML → Edit HTML Source from the ribbon.

SharePoint - edit HTML source

And paste in the following style codes.

<style type="text/css">

.ms-vh, .ms-vh2-nofilter, .ms-vh2-nograd, .ms-vh2, .ms-vb, .ms-vb2
{
    white-space: normal;
    text-align:center; 
    vertical-align:text-bottom;
    color:red;
}

</style>​

Click OK to save the change. Refresh the page and done.

It’s a very nice and useful trick in SharePoint because, with this added style web part, I can actually customize the style sheet to have the list displaying in a way I really wanted.

You can also accomplish the same with SharePoint Designer if you have one handy.

10 thoughts on “SharePoint Tip – How To Set Word Wrapping on List Column Headers

  1. This code applies to the column contents as well. I just want to wrap and center my column titles, not the data content.

  2. I used this however it causes my ribbon with “Items” & “List” to disappear. Why is that so?

    1. Yes, that’s because you added the web part for CSS style on the page. I believe you can click inside the list to have the items & lists menu to show up again.

    2. Known issue… When you add a web part to a list page SP doesn’t display those tabs anymore…
      There are permanent fixes out there e.g.: http://www.pentalogic.net/sharepoint-products/free-stuff/view-rescue
      A quick-fix way to see these ‘lost’ tabs I found is to…
      – click in the List/library search dialog (not directly on the magnifying glass though) or
      – select any of the list/library items,
      – click to the right of the list (assuming the columns don’t fill the width of the screen)
      the tabs should now appear, but this is not a permanent fix, you’ll have to do this every time the list reloads.

  3. Content Editor Web Part was added above the Allitems.aspx or SP list items for my site. I added the script above to the html source which worked beautifully but after I applied the changes. The Allitems.aspx items (list items containing 730 records) are no longer showing. Can you help please?

Leave a Reply to Caroline Cancel reply

Your email address will not be published. Required fields are marked *