Javatpoint Logo
Javatpoint Logo

CSS Rotate Text

The text on a web page can be rotated with the help of CSS. Rotating the text helps style the web page and attract viewers. There are many methods to rotate the text. In this article, we are going to study the CSS rotate text.

Following are the CSS text rotate properties that are used to rotate the text on the web page:

  1. Using writing-mode
  2. Using text-orientation
  3. Using rotate property
  4. Using transform property with value rotate() function

Let us learn all properties one by one.

1. Using Writing-mode

The first property is using the "writing-mode".

Syntax:

In the above syntax, "writing-mode" is the CSS property. There are many values that this property takes, which are as follows:

  • Horizontal-tb: When this value is given to the writing-mode then it places the texts horizontally from left to right for the left-to-right scripts and it places the texts horizontally from right to left for the right-to-left scripts.
  • Vertical-lr: When this value is given to the "writing-mode" property, then it places the texts vertically from top to bottom for the left-to-right scripts and places the next vertical line to the left of the previous line. It places the texts vertically from bottom to top for the right-to-left scripts and places the next vertical line to the right of the previous line.
  • Vertical-rl: When this value is given to the "writing-mode" property, then it places the texts vertically from top to bottom for the left-to-right scripts and places the next vertical line to the right of the previous line. It places the texts vertically from bottom to top for the right-to-left scripts and places the next vertical line to the left of the previous line.
  • Sideways-lr: When this value is given to the "writing-mode" property, then it places the texts vertically from bottom to top for the left-to-right scripts, and it places the texts horizontally from top to bottom for the right-to-left scripts. It shifts the text towards the left.
  • Sideways-rl: When this value is given to the "writing-mode" property, the texts are placed vertically from top to bottom for the left-to-right scripts and horizontally from bottom to top for the right-to-left scripts. It shifts the text towards the right.
  • Inherit: It is used to inherit the CSS writing-mode property of the parent.
  • Initial: It is used to set the default value of the CSS writing-mode property.

Demonstration of "writing-mode" CSS Property

Let's examine the use of the "writing-mode" property using the following example. We will use all writing-mode property values to show the various text rotations.

Code:

Output:

Here in the output we can witness the use of writing-mode property with different values that show the different text rotation.

CSS Rotate Text

2. Using Text-orientation

The second property uses the "text orientation." This property is used when the "writing-mode" property is set, which means the "writing-mode" property is mandatory for using the "text-orientation" property.

Syntax:

text-orientation: upright| mixed| sideways| use-glyph-orientation| sideways-right| inherit| initial;

"writing-mode" and "text-orientation" are the CSS properties in the above syntax. There are various values that the "text-orientation" property takes, which are given below:

  • Upright: This value is used to set the characters to be in an upright manner and the characters are not rotated.
  • Mixed: This value is used to rotate the characters to 90 degrees in the clockwise direction.
  • Sideways: This value is supported by the Firefox browser only. It rotates the characters clockwise to 90 degrees, orienting them the same way text lines are oriented.
  • Use-glyph-orientation: This value is used to use the deprecated SVG properties glyph-orientation-horizontal and glyph-orientation-vertical in the SVG elements.
  • Sideways-right: This value's work is the same as that of the sideways value, but it is utilized for compatibility purposes.
  • Inherit: It is utilized to inherit the CSS text-orientation property of the parent.
  • Initial: It is used to set the default value of the CSS text-orientation property.

Demonstration of "text-orientation" CSS Property

Let us look at the demonstration of using the text-orientation property.

Code:

Output:

Here is the output. We can witness the text-orientation property with different values that show the various types of text rotation.

CSS Rotate Text

3. Using Rotate Property

The third property to rotate the text is the "rotate" CSS property.

Syntax:

"rotate" is the CSS property in the above syntax. The values that the "rotate" property takes are given below:

  • None: This value is the default value, i.e., automatically assigned value.
  • Axis: This tells the axis to which you want to rotate the text, such as the x-axis, y-axis, or z-axis. If the axis is not specified, then the z-axis is set by default.
  • Angle: This means the angle to which you require the text to be rotated, such as rad, turn, and degree.
  • Vector-angle: It uses three numbers to rotate the text: x-coordinate, y-coordinate, and z-coordinate. These numbers are used with angle, which defines how much angle the text is to be rotated.
  • Inherit: It is utilized to inherit the CSS rotate characteristics of the parent.
  • Initial: It is utilized to specify the default value of the CSS rotate property.

Demonstration of "rotate" CSS Property

We are going to comprehend the "rotate" property in this demonstration.

Code:

Output:

Here, in the result, the use of the "rotate" property with distinct values that display the distinct text rotation can be witnessed.

CSS Rotate Text

4. Using Transform Property with Value Rotate() Function

The "transform" is the fourth property, which accepts the value as the rotate() function.

Syntax:

"transform" is the CSS property that we can witness in the above syntax. The values that this property accepts are given below:

  • None: This value is the automatic or default value.
  • Rotate (degree) function: It is the rotate function that we use to rotate the text, and it takes the value of a degree.

Demonstration of "transform: rotate()" CSS Property

We will illustrate how to rotate the text utilizing the transform property.

Code:

Output:

We can notice the text rotation using the transform property in the result below.

CSS Rotate Text

Browser Compatibility

Given below are the browsers that support all the properties discussed in this article:

  • Google Chrome
  • Firefox
  • Opera
  • Internet Explorer
  • Safari

Conclusion

In this article, we have understood the CSS rotate text. We have seen four CSS text rotate properties that are used to rotate the text, which are as follows:

  • Using writing-mode
  • Using text-orientation
  • Using rotate property
  • Using transform property with value rotate() function

We have understood each property properly with the help of the examples.


Next TopicCSS Second Child





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA