79

With writing-mode you can only get the text to be read from top to bottom. According to https://developer.mozilla.org/en/docs/Web/CSS/writing-mode

the only option I have is using sideways. But this attribute is experimental.

.verticalTxt_lr {
  writing-mode: vertical-lr;
}
.verticalTxt_rl {
  writing-mode: vertical-rl;
}
.rotate {
  transform: rotateZ(270deg);

}

https://jsfiddle.net/thadeuszlay/5ueopnqu/2/

I wanted to write the label on the bars to be vertical but it should start from the bottom.

http://jsfiddle.net/thadeuszlay/3HL4a/2402/

Trying with rotate gives me a weird behaviour when animating the bar chart therefore I'm looking for another method to create vertical texts that can be read with your head tilted to the left.

3
  • 1
    Occam's razor says: do you really really need to animate the bar chart? Commented Nov 1, 2016 at 16:39
  • @MrLister: 1) Who or what is Occam's razor? 2) Yes! Commented Nov 1, 2016 at 21:36
  • to answer your question: Occam's razor: ask yourself if it's neccesary to have?/if it's adding something valueable to the user's experience, if yes, go for it. if no, you're wasting your time, as well as the user's time Commented Dec 1, 2016 at 13:02

5 Answers 5

135

I combined writing-mode and rotation:

    .rotated {
        writing-mode: tb-rl;
        transform: rotate(-180deg);
    }
<div class="rotated">Text from bottom with working width/height</div>

This works for me without bad width and height settings inside table cells.


important 2020 edit:

step 1) Look at https://developer.mozilla.org/en-US/docs/Web/CSS/writing-mode , ctrl/cmd-F for "Result". This table will reflect your browser (which may have improper implementation). Look at the table immediately below it. That table is what things should look like.

Solution:

To make sure your solution is future proof:

  1. Look at the appropriate column, which will be "Horizontal Script" unless you're coding e.g. in an Asian language.
  2. Find a row that suits your needs in terms of sizing the HTML element, AND is properly implemented (appears roughly the same) in the second table below it. For example writing-mode:vertical-rl; would currently work on Chrome until others are properly implemented in the Blink engine (but if you based your answer off of sideways-lr it would break once Blink properly implements this behavior, since the two rows are not the same.).
  3. optional: set transform-origin to something, maybe use calc(...), based on percentages and/or something else
  4. perform transform:rotate(180deg) or something. This should fix issues with layout that most people would have, causing them to look up this answer. If one has animation problems, that's a separate issue.

(also tb-rl is deprecated now)

Sign up to request clarification or add additional context in comments.

5 Comments

Any reason for -180 instead of 180?
In short: writing-mode: vertical-rl; transform: rotate(-180deg); gives intended result in 2020!
The question explicitly asks for an answer without transform: rotate.
transform: rotate() also rotates borders. Any workaround?
Put the border on a wrapper element?
10

.rotated {
  writing-mode: vertical-lr;
  transform: scale(-1, -1);
}
<div class="rotated">Text from bottom with working width/height</div>

2 Comments

Welcome to Stack Overflow. Please consider adding a brief explanation of how and why this solves the problem. This will help readers to better understand your solution.
Unfortunately this reverses the order of lines in multiline text
2
.rotate {
     transform: rotate(270deg);
}

This should be enough to rotate text vertically from bottom to top, apply it on div containing the text. If you are using writing-mode: vertical-rl/lr in conjunction to this, that may be switching it to other way around.

Comments

1

this will do:

.verticalTxt_lr {
 writing-mode: vertical-rl;
 transform: rotate(-180deg);
}

Comments

1

Currently this is all you need, (according to MDN Only Samsung Internet browser does not support this):

.vertical-text {
    writing-mode: sideways-lr;
}

https://developer.mozilla.org/en-US/docs/Web/CSS/writing-mode#:~:text=10.3-,sideways%2Dlr,-132

Works nicely even when wraping vertical text.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.