Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS hyphens Property

Posted in CSS Tutorial
Updated on Oct 03, 2024
By Mari Selvan
👁️ 20 - Views
⏳ 4 mins
💬 1 Comment
CSS hyphens Property

Photo Credit to CodeToFun

🙋 Introduction

The hyphens property in CSS is used to control how words should be hyphenated when text wraps across multiple lines.

It is particularly useful for improving the readability of long words in narrow columns of text, ensuring that they break correctly at appropriate hyphenation points.

💡 Syntax

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

Syntax
Copied
Copy To Clipboard
element {
  hyphens: none | manual | auto;
}

🎛️ Default Value

The default value of the hyphens property is manual, which means that hyphenation only occurs when the ­ (soft hyphen) character is used in the text.

🏠 Property Values

ValueDescription
noneNo hyphenation is applied.
manualHyphenation occurs only where the ­ character is inserted.
autoThe browser automatically inserts hyphens where appropriate, based on the language and hyphenation rules.

📄 Example

In this example, we'll enable automatic hyphenation for a paragraph.

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 hyphens Example</title>
  <style>
    p {
      hyphens: auto;
    }
  </style>
</head>
<body>
  <h1>Automatic Hyphenation Example</h1>
  <p>
    Hyphenation is the process of adding hyphens to words at appropriate points to improve the readability and layout of the text. This is particularly useful for languages with long words or for text displayed in narrow columns.
  </p>
</body>
</html>

🖥️ Browser Compatibility

The hyphens 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 hyphens property is a useful tool for enhancing the readability of text on your web pages.

By controlling how words are hyphenated, you can ensure that your text looks clean and well-organized, even in narrow or constrained layouts. Experiment with the different values of the hyphens property to see how it can improve the presentation of your 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