×

Css Text Orientation

Introduction:

The text-orientation property of CSS is used to specify the orientation of the text characters in the line of content. This property applies only with the vertical writing-mode and not with the text which is in horizontal writing-mode.

This property is used for controlling the display of languages using vertical script and to create vertical table headers.

The text-orientation property is completely dependent on the writing-mode property. So it is mandatory that the writing-mode is set to vertical-rl. If the writing-mode is set to horizontal-tb, text-orientation won't work.

It can be applied to all the element except the table rows, columns, row groups and column groups.

What is writing-mode?

The writing-mode property indicates whether the script/text is displayed vertically or horizontally.

Default value of this property is horizontal-tb

There are three values associated with writing-mode:

Value Description
horizontal-tb This allows the text to flow horizontally from left to right and vertically from top to bottom.
vertical-rl This allows the text to flow vertically from top to bottom and horizontally from right to left.
vertical-lr This allows the text to flow vertically from top to bottom and horizontally from left to right.

Text - orientation property values:

CSS text-orientation has following values:

  • mixed
  • upright
  • sideways
  • sideways-right
  • use-glyph-orientation
  • initial
  • inherit
  • mixed:
    This is the default value of text-orientation and it rotates the horizontal text 90oclockwise. Characters which are already in their vertical orientation are displayed naturally.
    Syntax:
    text-orientation: mixed;

Example:

<!DOCTYPE html>

<html>

<head>

<style>    

div{

border: 1px solid;

font-size: 20px;

width: 250px;

height: 300px;

}

div{   

writing-mode: vertical-lr;

text-orientation: mixed;      

}

h2{

        color: tomato;

}

</style>

</head>

<body>

<h2>Example of text-orientation: mixed; </h2>

<div>

This is an example of CSS text-orientation. The example display the mixed value of this property.

</div>

</body>

</html>

Output:

Css Text Orientation

In above output, the horizontal text rotates 90oclockwise using mixed keyword of text-orientation.

  • upright:
    The characters in the horizontal orientation are set upright naturally, including the glyphs for the vertical oriented scripts. This keyword treats all the characters as left to right in the writing mode, so the value for the directionproperty is forcefully set as ltr.
    Syntax:
    text-orientation: upright;

Example:

<!DOCTYPE html>

<html>

<head>

<style>

div{

border: 1px solid;

font-size: 20px;

width: 250px;

height: 300px;

}

div{   

writing-mode: vertical-rl;

text-orientation: upright;    

}

h2{

        color: tomato;

}

</style>

</head>

<body>

<h2>Example of text-orientation: upright; </h2>

<div>

This is an example of CSS text-orientation. The example display the upright value of this property.

</div>

</body>

</html>

Output:

Css Text Orientation

Here, the above text is displayed upright from left to right using text-orientation: upright value.

  • sideways:
    This keyword sets the text in vertical writing mode sideways i.e., it allows the characters to be laid out horizontally It rotates the complete line 90o clockwise.
    Syntax:
    text-orientation: sideways;

Example:

<!DOCTYPE html>

<html>

<head>

<style>

div{

border: 1px solid;

font-size: 20px;

width: 250px;

height: 300px;

writing-mode: vertical-rl;

text-orientation: sideways;   

}

h2{

color: tomato;

width: 400px;

}

</style>

</head>

<body>

<h2>Example of text-orientation: sideways; and writing-mode: vertical-rl;</h2>

<div>

This is an example of CSS text-orientation. The example display the sideways value of this property.

</div>

</body>

</html>

Output:

Css Text Orientation

Here, the text is displayed to the sideways with the writing-mode right to left.

  • sideways-right:
    This is an alias for the sideways value, and is used for compatibility purposes.
    Syntax:
    text-orientation: sideways-right;

Example:

<!DOCTYPE html>

<html>

<head>

<style>

div{

border: 1px solid;

font-size: 20px;

width: 250px;

height: 300px;

writing-mode: vertical-lr;

text-orientation: sideways-right;

}

h2{

color: tomato;

width: 400px;

}

</style>

</head>

<body>

<h2>Example of text-orientation: sideways-right; and writing-mode: vertical-lr; </h2>

<div>

This is an example of CSS text-orientation. The example display the sideways-right value of this property.

</div>

</body>

</html>

Output:

Css Text Orientation

The output displays the text in sideways-right format.

  • use-glyph-orientation:
    This property value has been removed from use since December 2015.
    It was used with SVG elements to define SVG properties glyph-orientation-vertical and glyph-orientation-horizontal.
    glyph-orientation-horizontal is used as an alias of text-orientation.
    Syntax:
    text-orientation: use-glyph-orientation;
  • initial:
    The initial keyword assigns default value to the text-overflow property.
    Default value of text-orientation is mixed.
    Syntax:
    text-orientation: initial;

Example:

<!DOCTYPE html>

<html>

<head>

<style>

.id{

        width: 300px;

        height: 300px;

        border: 1px solid black;

        font-size: 25px;

        writing-mode: vertical-lr;

        text-orientation: initial;

}

h2{

        color: skyblue;

}

</style>

</head>

<body>

<h2>text-orientation: initial; </h2>

<div class="id">

This is an example of CSS text-orientation. The example display the initial value of this property

</div>

</body>

</html>

Output:

Css Text Orientation

Here, the script takes the initial value of the property which is mixed.

  • inherit:
    This value inherits the text-overflow property of its parent element.
    Syntax:
    text-orientation: inherit;

Example:

<!DOCTYPE html>

<html>

<head>

<style>

div {

width: 400px;

height:300px;

font-size: 15px;

border: 2px solid;

writing-mode:vertical-lr;

text-orientation: upright;

}

h2{

width: 400px;

text-orientation: inherit;

color: skyblue;

}

</style>

</head>

<body>

<h2 style="color: red">text-orientation: inherit</h2>

<div>

<h2>text-orientation: inherit derives the property of its parent element </h2>

This is an example of CSS text-orientation. The example display the inherit value of this property.

</div>

</body>

</html>

Output:

Css Text Orientation

Here the <h2> element inherits the text-orientation: upright; property of the <div> element.


Related Topics

CSS Text Effects

Text Effects in CSS We can use distinct text effects used inside the HTML document. Few attributes can be applied to insert the text effects. We can also style various web documents...

5 minutes read.

CSS Clip

CSS Clip The Clip property in CSS describes the element’s visible area. It applies over the elements which are absolutely positioned (position: absolute ;). Generally, it is used when an image...

2 minutes read.

CSS Visibility

Visibility in CSS: This visibility property in CSS is employed to describe whether the components are visible or not. Note: An invisible component also grabs the space over the page. If...

2 minutes read.

CSS Checkbox style

CSS Checkbox style: It is an element of HTML, which is used to get input from various users. It is difficult to style any checkbox. However, some elements make it...

6 minutes read.

Css Text Orientation

Introduction: The text-orientation property of CSS is used to specify the orientation of the text characters in the line of content. This property applies only with the vertical writing-mode and not...

4 minutes read.

CSS Reference

The CSS Reference lists all of the basic standard CSS properties, pseudo-classes, pseudo-elements, and data types, for all intents and purposes functional notations, and at-rules alphabetically.  The site also includes...

5 minutes read.

CSS Page-break-before Attribute

Page-break-before Attribute As its name implies, the page-break-before property is applied to include page break before any element, at the time of printing any document. It adds the page break before...

5 minutes read.

Grid Vs Flexbox in CSS

Grid: - CSS Grid Layout is a 2D grid-based matrix-based layout method with columns and rows that simplifies web pages created by eliminating the need for floats and placement. A grid layout, like...

4 minutes read.

CSS Font-Size

A Cascading Style Sheet (CSS) is a simple design scripting language intended to simplify the process of making web pages more visually appealing with the kind of high-level formatting. Cascading...

3 minutes read.

What is Bootstrap CSS?

Bootstrap: - Bootstrap is a CSS framework that is free to use and is used for the front-end development of the website in a faster and easier way. Bootstrap was released as...

3 minutes read.

How to use google fonts in CSS

Fonts: - Fonts are used to make our website look more beautiful. Choosing appropriate font according to the web design or layout is also important. Many typefaces are accessible in...

4 minutes read.

CSS Inline

What is CSS? CSS is an acronym for Cascading Style Sheets. CSS is the language that we use to style an HTML document. It specifies how HTML components should appear. CSS...

4 minutes read.

CSS Pagination

CSS Pagination The pagination in CSS is an advantageous approach for indexing of a website’s distinct pages over the homepage. When our site contains multiple pages, we must insert a few...

13 minutes read.

CSS Important

CSS Important: CSS !important property is used to provide more importance, as compared to other CSS properties. The meaning of this property is “This is important.” This property enables CSS...

2 minutes read.

CSS Form

You can create attractive HTML form by using CSS. Style input Fields The Input Field width properties are used to determine the width of the input field. Let us see an example of CSS style...

2 minutes read.

CSS Overlay

CSS Overlay: It measures to cover-up something’s surface along with a coating. CSS overlay sets anything over the top area of other things. It creates a web-page more attractive. The...

8 minutes read.

CSS Letter-spacing

CSS Letter-spacing: Letter-spacing attribute is applied to manage the space among all letters within the block or element of the text. This property sets the behavior of the spacing between...

2 minutes read.

CSS Margin

CSS Margin: The CSS margin property is employed to describe the space throughout the elements. It clears the range throughout the element. These properties do not have a background color...

2 minutes read.

Cascading Style Sheet

CSS refers to the Cascading Style Sheet. CSS is a form of a programming language. In other words, CSS is a language of the style sheet that is utilised for...

7 minutes read.

CSS Line Height

CSS Line Height: This property in CSS can be used to describe the line box’s minimal height inside the element. It sets-up the distinction among two lines in our content. It...

3 minutes read.