writing-mode Property in CSS

The writing-mode property is used to set whether lines of text are laid out horizontally or vertically. Let us understand the property with examples. We will begin with the syntax.

Syntax

The following is the syntax of the writing-mode property −

writing-mode: value;

The values are −

  • horizontal-tb − Content flows horizontally from left to right and vertically from top to bottom

  • vertical-rl − Content flows vertically from top to bottom and horizontally from right to left

  • vertical-lr − Content flows vertically from top to bottom and vertically from left to right

Flow content vertically from top to bottom and horizontally from right to left

Let us see an example to use the vertical-rl value of the writing-mode property. This will flow the content vertically from top to bottom and horizontally from right to left −

p {
   writing-mode: vertical-rl;
}

Example

Here is the example −

<!DOCTYPE html>
<html>
<head>
   <style>
      p {
         writing-mode: vertical-rl;
      }
   </style>
</head>
<body>
   <h1>Demo Heading</h1>
   <p>This is demo text.</p>
</body>
</html>

Flow content horizontally from left to right and vertically from top to bottom

Let us see an example to use the horizontal-tb value of the writing-mode property. This will flow the content horizontally from left to right and vertically from top to bottom −

p {
   writing-mode: horizontal-tb;
}

Example

Here is the example −

<!DOCTYPE html>
<html>
<head>
   <style>
      p.demo1 {
         word-spacing: 1cm;
         color: blue;
         writing-mode: vertical-rl;
      }
      p.demo2 {
         word-spacing: 40px;
         writing-mode: horizontal-tb;
      }
   </style>
</head>
<body>
   <h1>Demo Heading</h1>
   <h2>Heading2</h2>
   <p class="demo1">This is demo text.</p>
   <h2>Heading2</h2>
   <p class="demo2">This is demo text.</p>
</body>
</html>
Updated on: 2023-12-26T15:48:24+05:30

101 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements