Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Topics

CSS direction Property

Posted in CSS Tutorial
Updated on Oct 02, 2024
By Mari Selvan
👁️ 28 - Views
⏳ 4 mins
💬 1 Comment
CSS direction Property

Photo Credit to CodeToFun

🙋 Introduction

The direction property in CSS is used to set the text direction of an element.

This property is particularly useful for creating web pages that support languages written from right to left (RTL), such as Arabic and Hebrew. By controlling the direction of text, you can ensure that your website provides a proper and intuitive reading experience for users of different languages.

💡 Syntax

The syntax for the direction property is straightforward. It can be applied to any block-level element.

Syntax
Copied
Copy To Clipboard
element {
  direction: ltr | rtl | initial | inherit;
}

🎛️ Default Value

The default value of the direction property is ltr (left-to-right).

🏠 Property Values

ValueDescription
ltrText direction goes from left to right. This is the default value.
rtlText direction goes from right to left.
initialSets the property to its default value (ltr).
inheritInherits the direction property from its parent element.

📄 Example

In this example, we'll change the text direction of a paragraph to right-to-left.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS direction Property Example</title>
  <style>
    p.rtl {
      direction: rtl;
    }
  </style>
</head>
<body>
  <h1>Paragraph with Custom Text Direction</h1>
  <p>This paragraph is left-to-right by default.</p>
  <p class="rtl">This paragraph is right-to-left.</p>
</body>
</html>

🖥️ Browser Compatibility

The direction property is supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. It is also supported in older browsers, ensuring broad compatibility across different user environments.

🎉 Conclusion

The direction property is an essential tool for web developers who need to support multiple languages, especially those written in right-to-left scripts.

By controlling the direction of text, you can create a more inclusive and user-friendly web experience. Experiment with this property to see how it can enhance the readability and accessibility of your web content.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

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

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy