CSS Properties
CSS writing-mode Property
Photo Credit to CodeToFun
🙋 Introduction
The writing-mode
property in CSS is used to define the direction and orientation of text. This property is particularly useful for languages that are written vertically, such as Japanese and Chinese, as well as for creating unique layouts where text direction plays a key role.
By using the writing-mode
property, you can control whether text is laid out horizontally or vertically and the direction in which lines are stacked.
💡 Syntax
The syntax for the writing-mode
property is simple and consists of specifying one of the predefined values.
element {
writing-mode: value;
}
🎛️ Default Value
The default value of the writing-mode
property is horizontal-tb, which means text is written horizontally and lines are stacked from top to bottom.
🏠 Property Values
Value | Description |
---|---|
horizontal-tb | Text is written horizontally, and lines are stacked from top to bottom (default). |
vertical-rl | Text is written vertically, and lines are stacked from right to left. |
vertical-lr | Text is written vertically, and lines are stacked from left to right. |
sideways-rl | Text is written horizontally but rotated 90 degrees counterclockwise, with lines stacked from right to left. |
sideways-lr | Text is written horizontally but rotated 90 degrees clockwise, with lines stacked from left to right. |
📄 Example
In this example, we'll change the writing mode of a paragraph to vertical, with lines stacked from right to left.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS writing-mode Example</title>
<style>
p {
writing-mode: vertical-rl;
border: 1px solid #000;
width: 200px;
height: 100px;
padding: 10px;
}
</style>
</head>
<body>
<h1>Paragraph with Vertical Writing Mode</h1>
<p>
This is a paragraph with the writing mode set to vertical-rl. The text is written vertically, and lines are stacked from right to left.
</p>
</body>
</html>
🖥️ Browser Compatibility
The writing-mode
property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it is always a good practice to test your website across different browsers to ensure compatibility.
🎉 Conclusion
The writing-mode
property is a versatile tool for web developers looking to create unique text layouts and support various writing systems.
By controlling the direction and orientation of text, you can enhance the readability and aesthetic appeal of your website. Experiment with different values and see how this property can transform the way your content is displayed.
👨💻 Join our Community:
Author
For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee
If you have any doubts regarding this article (CSS writing-mode Property), please comment here. I will help you immediately.