- Services
- Case Studies
- Technologies
- NextJs development
- Flutter development
- NodeJs development
- ReactJs development
- About
- Contact
- Tools
- Blogs
- FAQ
CSS Hyphens Enhance Text Readability with Easy Hyphenation
Choose from 'none', 'manual', or 'auto' options to manage hyphenation effectively.
Introduction
In web development, managing text flow is crucial for readable and visually appealing layouts. The CSS hyphens
property helps control how words break and hyphenate across lines. Introduced in September 2023, this feature works well on the latest devices and browsers. It lets you prevent hyphenation, manually specify break points, or let the browser handle it automatically.
Using the hyphens
property improves readability, especially on text-heavy sites. By configuring it properly, you ensure words break nicely, maintaining flow and coherence. Whether you’re a seasoned developer or a beginner, mastering hyphens
can greatly enhance your site’s aesthetics and user experience. Let’s explore how to use it effectively.
Specification
The hyphens
property is defined in the CSS Text Module Level 3 specification. This module covers text rendering rules, including hyphenation. You can find detailed guidelines here:
- CSS Text Module Level 3: hyphens property
Description
The hyphens
property controls word breaks and hyphenation at line ends, ensuring smooth text flow. It has three main values:
- none: Prevents word breaks at line ends.
- manual (default): Allows breaks at manually specified points, like soft hyphens (
­
). - auto: Lets the browser decide where to break words based on language rules.
Additionally, it supports global values like inherit
, initial
, revert
, and unset
, which manage how the property is inherited or reset.
Syntax
The syntax for the hyphens
property is straightforward:
- Keyword values: Control hyphenation behavior.
none
: No word breaks.manual
: Breaks at specified points.auto
: Browser decides breaks.
- Global values: Manage inheritance and default behavior.
inherit
: Inherits from parent.initial
: Sets to default (manual
).revert
andrevert-layer
: Revert to user agent or outer scope default.unset
: Resets to natural value.
Values
The hyphens
property accepts several values:
- none: Prevents word breaks.
- manual (default): Breaks at specified points.
- auto: Browser decides breaks.
Global values include:
- initial: Resets to default (
manual
). - inherit: Inherits from parent.
- revert: Reverts to user agent default.
- revert-layer: Reverts considering cascade layers.
- unset: Resets to natural value.
Suggesting Line Break Opportunities
You can manually specify break points using Unicode characters:
- U+2010 (HYPHEN): Always shows a hyphen.
- U+00AD (SHY): Invisible soft hyphen (
­
).
Example:
This suggests a break point without visibly altering the text.
Formal Definition
The hyphens
property has specific attributes:
Attribute | Value |
---|---|
Initial Value | manual |
Applies To | All elements |
Inherited | Yes |
Computed Value | As specified |
Animation Type | Discrete |
Formal Syntax
The formal syntax for the hyphens
property is:
It also supports global values:
Examples
Example 1: Basic Usage
HTML:
This example demonstrates how to use the hyphens
property with different values to control text hyphenation effectively.
CSS hyphens Property Examples
Here are some examples to show how the hyphens
property works in CSS.
Example 1: Basic Usage
Explanation:
- hyphens: none: The text will not be hyphenated, and the word may overflow the container.
- hyphens: manual: The word will be hyphenated at the specified soft hyphen (
­
). - hyphens: auto: The browser will automatically determine where to hyphenate the word.
Example 2: More Detailed Usage
Explanation:
- hyphens: none: The text will not be hyphenated, and long words may cause overflow.
- hyphens: manual: The word “Post-Impressionist” will be hyphenated at the specified soft hyphen (
­
). - hyphens: auto: The browser will automatically determine the best points for hyphenation, ensuring the text flows smoothly.
Example 3: Language-Specific Hyphenation
Explanation:
- English Text: The browser will automatically hyphenate the English text based on its rules.
- French Text: The browser will automatically hyphenate the French text based on its rules.
- German Text: The browser will automatically hyphenate the German text based on its rules.
Specifying Text Hyphenation
Specifying text hyphenation with the hyphens
property allows you to control how words break at the end of lines, enhancing the readability and visual appeal of your content. Here’s how you can specify text hyphenation using the hyphens
property:
HTML
CSS
Explanation
none
:- Description: Prevents words from being broken at line breaks. The text will only wrap at whitespace.
- Usage: Use this value when you want to prevent any hyphenation, ensuring that words remain intact even if it results in overflow.
manual
:- Description: Allows words to be broken at manually specified points within the text, such as where a soft hyphen (
­
) is inserted. - Usage: Use this value when you need precise control over where hyphens appear, typically in cases where you manually insert soft hyphens in the text.
- Description: Allows words to be broken at manually specified points within the text, such as where a soft hyphen (
auto
:- Description: The browser is free to automatically break words at appropriate hyphenation points, following whatever rules it chooses. However, suggested line break opportunities (such as soft hyphens) will override automatic break point selection when present.
- Usage: Use this value to let the browser handle hyphenation automatically, which is useful for text-heavy layouts where manual control is impractical.
Browser Compatibility
The hyphens
property in CSS is widely supported across modern browsers, ensuring that developers can rely on it to manage text hyphenation effectively. However, it’s essential to be aware of the specific versions and any limitations that might exist. Below is an overview of the browser compatibility for the hyphens
property:
- Google Chrome: Supported from version 55.0 onwards (released in December 2016).
- Mozilla Firefox: Supported from version 43.0 onwards (released in December 2015).
- Internet Explorer: Supported from version 10.0 onwards (released in September 2012).
- Microsoft Edge: Supported from version 79 onwards.
- Opera: Supported from version 44.0 onwards (released in March 2017).
- Safari: Supported from version 5.1 onwards (released in October 2011).
Note: Older versions of these browsers may not support the hyphens
property, so it’s crucial to test your implementation across different browser versions to ensure compatibility.
Supported Browsers
The hyphens
property in CSS is supported by a wide range of modern browsers, ensuring that developers can rely on it to manage text hyphenation effectively. Below is a list of browsers that support the hyphens
property, along with the versions where support was introduced:
- Google Chrome: Supported from version 55.0 onwards (released in December 2016).
- Mozilla Firefox: Supported from version 43.0 onwards (released in December 2015).
- Internet Explorer: Supported from version 10.0 onwards (released in September 2012).
- Microsoft Edge: Supported from version 79 onwards.
- Opera: Supported from version 44.0 onwards (released in March 2017).
- Safari: Supported from version 5.1 onwards (released in October 2011).
Note: Older versions of these browsers may not support the hyphens
property, so it’s crucial to test your implementation across different browser versions to ensure compatibility.
By understanding the supported browsers for the hyphens
property, you can ensure that your web projects maintain consistent and effective text hyphenation across various devices and platforms. This knowledge allows you to create more robust and user-friendly web designs, enhancing the overall user experience.
Talk with CEO
We'll be right here with you every step of the way.
We'll be here, prepared to commence this promising collaboration.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.