DEV Community

Cover image for How to correctly position rotated text using CSS
Temani Afif
Temani Afif

Posted on β€’ Edited on

30 6

How to correctly position rotated text using CSS

Find out more CSS tricks at css-tip.com

It's always a hassle to correctly position a rotated text. Especially to position such text in the corner or the sides of another element.

No need to bother yourself with such a task. Find below all the common cases. It's responsive and no hardcoded width or height is needed (hover to change the text direction)

The corners

The sides

Here are a few notes to easily remember the different cases:

  • There is always a relation between transform-origin and top/left/bottom/right. If you will use top and left then you will need transform-origin:top left and so on.
  • We always rotate then translate (never the opposite)
  • The rotation is 90deg for a text orientation to the bottom and -90deg to the top.
  • The translation is +/-100% for the corners and +/-50% for the sides. No need to remember them all, a quick trial & error can give you the correct value.

The above is the most supported way to achieve what we want but we can do easier using writing-mode

The corners

The sides

Nothing to remember here πŸ˜‰


More common positions (that we can easily find from the above)


buy me a coffee

OR

Become a patron

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly β€” using the tools and languages you already love!

Learn More

Top comments (2)

Collapse
 
mahfujseopage1 profile image
mahfujseopage1 β€’

You saved my day :)

Collapse
 
imiahazel profile image
Imia Hazel β€’

Thanks for wonderful tips. You saved my day :)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

πŸ‘‹ Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay