CSS Properties
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.
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
Value | Description |
---|---|
none | No hyphenation is applied. |
manual | Hyphenation occurs only where the ­ character is inserted. |
auto | The 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.
<!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:
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 hyphens Property), please comment here. I will help you immediately.