Search code examples
htmlcsscss-transforms

Inline text rotation


I want to have italic text, however I want to be able to play with the rotation. I know for plain italic text, I can do <i></i> or font-style: italic, but what if I want to rotate the text by a custom amount of degrees. Is there a way to do that?

Simple transform: rotate(5deg) won't work because that will not rotate the text inline, like italic does. Is there a way to do this, and if so, how do you recommend I go about it?


Solution

  • There are multiple ways to do this, but I think CSS skew() transform property would be the best approach to get what you want.

    The skew() will accept two properties (skew(ax, ay)) for distorting the element in x and y axes, but in your current particular case passing the first parameter would be enough.

    So your final code would be something like this:

    .skew {
      transform: skew(15deg);
    }
    <div class="skew">hi there</div>