Scott Gale Scott N. Gale
Vermont
Scott Gale's RSS Feed Scott Gale's LinkedIn Page Scott Gale's Facebook Page Scott Gale's Twitter Page

CSS Vertical Text

March 1st, 2010 - by Scott Gale - 32 Comments, Add »

Many people have written about the potential for vertical text in CSS so I wanted to try it out for myself. By using the technique described below I was able to achieve this effect:

*Disclaimer: This doesn’t work in old Opera versions, but does work in Opera 10.5. This also works in IE6+, FF, and Webkit based browsers, so that is pretty encompassing.

Here is the basic markup:

<p>CSS Vertical Text</p>

I wanted to try to do my best to exclude IE browser checks and conditional checks. So this example handles all browsers mentioned previously with a single CSS block:


p.css-vertical-text {
	color:#333;
	border:0px solid red;
	writing-mode:tb-rl;
	-webkit-transform:rotate(90deg);
	-moz-transform:rotate(90deg);
	-o-transform: rotate(90deg);
	white-space:nowrap;
	display:block;
	bottom:0;
	width:20px;
	height:20px;
	font-family: ‘Trebuchet MS’, Helvetica, sans-serif;
	font-size:24px;
	font-weight:normal;
	text-shadow: 0px 0px 1px #333;
}

Also, if I can stay away from IE filters I like too, but it’s worth mentioning that if you have an specific rotation, you have to use the IE filter:

filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);

Where 0, 1, 2, 3 correlate to 0, 90, 180, and 270 respectively.

So I tried to keep this one simple, but lining everything up in different browsers can be a pain because of the way each browser interprets the spacing.

Information for this post was pulled from the following places:

http://www.thecssninja.com/css/real-text-rotation-with-css

http://snook.ca/archives/html_and_css/css-text-rotation

32 Responses to “CSS Vertical Text”

  1. Charles (over a year ago)

    Very nice. Thank you very much.

  2. PSD to WordPress (over a year ago)

    I just wanted to say THANK YOU for this! I have been looking for something like this for a very long time and other solutions I have found work but are very limited.

    This worked like a charm the first time around and with a little playing around with the CSS I got it to do just exactly what I wanted.

    Once again thank you very much.

  3. admin (over a year ago)

    My pleasure. Glad that you guys got something out of it!

  4. me (over a year ago)

    I don’t believe this works in Firefox 3.0

  5. admin (over a year ago)

    Yes that’s true, FireFox 3.0, which makes up <1% of traffic this will not work on. Sometimes you just have to move forward though :-)

  6. Bas (over a year ago)

    Cheers mate!!! U rule!

  7. Phillip Haydon (over a year ago)

    -o-transform: rotate(90deg);

    Works in Opera too :)

  8. Scott Gale (over a year ago)

    Excellent thanks Phillip I will add that to the code.

  9. Scott Gale (over a year ago)

    Updated the code to include Opera 10.5.

  10. Luke (over a year ago)

    Cheers Scotty

  11. janjula (over a year ago)

    THX mate, thats what i was looking for….

  12. martijn (over a year ago)

    Dude, you are a hero.

  13. arungandhi (over a year ago)

    very nice. Thanks. :)

  14. benjamin.ramey » Vertical text with CSS (over a year ago)

    [...] http://scottgale.com/blog/css-vertical-text/2010/03/01/ [...]

  15. Pascal (over a year ago)

    I got Firefox 3.0.19 on Mac OS X 10.5.8 and it doenst work. My Safari can show the effect but Firefox cant.

  16. Scott Gale (over a year ago)

    Pascal, there were certain older versions of FireFox where this technique does not work, but I choose to look forward as those are very small traffic segments. Thanks for mentioning the specifics.

  17. Marti (over a year ago)

    Is there some way to convince such vertical text to NOT be as wide as it is long? I’m trying to make table header cells have vertical text, and quite apart from the atrocious things it does to the borders, Firefox is totally ignoring any width settings.

  18. Dean (over a year ago)

    Wow! Works great! Thanks Scott !!!

  19. Mauro (over a year ago)

    Mitico,
    grazie mille

  20. Manfred (over a year ago)

    Great stuff – love it – still developing on a nice vertical navigation.

  21. Vertical Text in HTML – Creating dynamic vertical text images in webpages » Technology Articles - Technology And Programming Articles (over a year ago)

    [...] Gale has a post on CSS Vertical Text that does a nice job explaining how to do rotated text in CSS using IE’s writing-mode and [...]

  22. CSS Vertical Text | ScottGale.com | Pixarea (over a year ago)

    [...] viaCSS Vertical Text | ScottGale.com. This entry was posted in css. Bookmark the permalink. [...]

  23. Daniel (over a year ago)

    Wow !! Great stuff. Cant’ wait to use it. I wished to be able to get vertical text for years, and today I find your technique :)
    Thanks !

  24. chitra (over a year ago)

    can u give a work around for vertical text align that it should work in firefox version2 series. thanks.

  25. wetway (over a year ago)

    Thanks man – this is bril

  26. Dulion (over a year ago)

    Thanx so much man, I’m 2 months bothering with this problem.

    I tried to use Flash to do it (worked) only when printing the page nothing showed up.

    Now it works in IE8 and Firefox 3.6.8 and gives the prpriate results when printing the page!

    Not tested in Chrome/ safari and Opera

  27. kashif (over a year ago)

    Just beautiful :)

  28. Questions from class, Friday | Introduction to Web Design and Implementation (over a year ago)

    [...] Here is another. [...]

  29. rajesh (over a year ago)

    Thanks Bhai…..

  30. Theraisa K (over a year ago)

    Is there a way to position the rotated text? Like, lets say I wanted it to appear at a set distance from the left (say 10px) and top (say 250px) on my page?

  31. Scott Gale (over a year ago)

    You can use padding or margin, margin works better with the transform though.

  32. Michael (over a year ago)

    awesome Scott! just did a google search for “html5 vertical text” and guess who came up #2? yep, you! thanks for this.