CSS hyphens Property
CSS hyphens Property
CSS hyphens
property specifies how words should be hyphenated when text wraps across multiple lines.
Example
<!DOCTYPE html>
<html lang="en-US">
<head>
<style>
div{
width: 80px;
padding: 10px;
line-height: 1.8;
border: 1px solid #8c8c8c;
}
#point{
hyphens: none;
-webkit-hyphens: none;
-ms-hyphens: none;
}
#point1{
hyphens: manual;
-webkit-hyphens: manual;
-ms-hyphens: manual;
}
#point2{
hyphens: auto;
-webkit-hyphens: auto;
-ms-hyphens: auto;
}
</style>
</head>
<body>
<h1>CSS hyphens property</h1>
<h2>hyphens: none;</h2>
<div id="point">
An extra•ordinary piece of work!
</div>
<h2>hyphens: manual;</h2>
<div id="point1">
An extra•ordinary piece of work!
</div>
<h2>hyphens: auto;</h2>
<div id="point2">
An extra•ordinary piece of work!
</div>
<p><strong>Note</strong>: Red colored dots are '‐' (hyphens).</p>
</body>
</html>
Syntax
Using CSS
element{
hyphens: none;
}
Using Javascript
object.style.hyphens="none";
Animatable
No, hyphens property is not animatable. CSS Animatable Properties Reference.
Default Value
Default value for CSS hyphens property is manual.
Property Value
The following table provides a list of values for CSS hyphens
property.
Value | Explanation |
---|
none | Words are not broken at line breaks, even if characters inside the words suggest line break points. |
manual | Words are broken for line-wrapping only where characters inside the word suggest line break opportunities. |
auto | The browser is free to automatically break words at appropriate hyphenation points. |
Using JavaScript
In the following example, we will demonstrate how to change the CSS hyphens
property of an element using JavaScript.
Example
<!DOCTYPE html>
<html lang="en-US">
<head>
<style>
div{
width: 80px;
padding: 10px;
margin-bottom: 25px;
line-height: 1.8;
border: 1px solid #8c8c8c;
hyphens: none;
-webkit-hyphens: none;
-ms-hyphens: none;
}
</style>
</head>
<body>
<h1>CSS hyphens property</h1>
<div>
An extra•ordinary piece of work!
</div>
<button onclick="myFunction()">Click Me</button>
<script>
var x = document.getElementsByTagName("div")[0];
function myFunction(){
x.style.hyphens = "manual";
x.style.Webkithyphens = "manual";
x.style.mshyphens = "manual";
}
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 98.7% of CSS Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in CSS.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.
Share this Page
Meet the Author