Coder Perfect

With CSS cross-browser, how can I draw vertical text?


I’d like to rotate a single word of text 90 degrees across all browsers (IE6, Firefox 2, any version of Chrome, Safari, or Opera). How can this be accomplished?

Asked by usr

Solution #1

This answer has been updated with new information (from CSS Tricks). Matt and Douglas deserve credit for pointing out the filter implementation.

.rotate {
  -webkit-transform: rotate(-90deg);
  -moz-transform: rotate(-90deg);
  -ms-transform: rotate(-90deg);
  -o-transform: rotate(-90deg);
  transform: rotate(-90deg);

  /* also accepts left, right, top, bottom coordinates; not required, but a good idea for styling */
  -webkit-transform-origin: 50% 50%;
  -moz-transform-origin: 50% 50%;
  -ms-transform-origin: 50% 50%;
  -o-transform-origin: 50% 50%;
  transform-origin: 50% 50%;

  /* Should be unset in IE9+ I think. */
  filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);

Old answer:

-moz-transform -moz-transform -moz-transform -moz-transform -moz-transform -moz-transform -moz-trans (and -webkit-transform). I’m not sure how to utilize the Matrix filter in Internet Explorer (v5.5+). Opera currently lacks transformation capabilities.

.rot-neg-90 {
  /* rotate -90 deg, not sure if a negative number is supported so I used 270 */
  -moz-transform: rotate(270deg);
  -moz-transform-origin: 50% 50%;
  -webkit-transform: rotate(270deg);
  -webkit-transform-origin: 50% 50%;
  /* IE support too convoluted for the time I've got on my hands... */

Answered by Robert K

Solution #2

To write vertical text on a page, I use the following code. Firefox 3.5 and above, webkit, opera 10.5 and up, and Internet Explorer

.rot-neg-90 {
    -moz-transform-origin: bottom left;
    -webkit-transform: rotate(-270deg);
    -webkit-transform-origin: bottom left;
    -o-transform: rotate(-270deg);
    -o-transform-origin:  bottom left;
    filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);

Answered by Choesang

Solution #3

Another option is to utilize an SVG text node, which most browsers support.

<svg width="50" height="300">
    <text x="28" y="150" transform="rotate(-90, 28, 150)" style="text-anchor:middle; font-size:14px">This text is vertical</text>

Demo: for more information about SVG text.

Answered by KrisztiƔn Balla

Solution #4

Orthogonal flows with vertical text are introduced via the CSS Writing Modes module.

Simply set the desired value for the writing-mode property.

Answered by Oriol

Solution #5

This is something I adapted from and css/css-text-rotation:

        display: block;
        position: absolute;
        right: -5px;
        top: 15px;
        -webkit-transform: rotate(-90deg);
        -moz-transform: rotate(-90deg);
<!--[if IE]>
        .Rotate-90 {
            filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
            right:-15px; top:5px;

Answered by john

Post is based on