16 September 2017

CSS Word Wrap

CSS Word Wrap

 



CSS Word Wrap properties are used for break the long words and wrap onto the next line. The main use of this properties is to prevent overflow when a long string unable to fit into containing box.

CSS word wrap values

ValueDescription
normalThis property is used to break words only at allowed break points.
break-wordIt is used to break unbreakable words.
initialIt sets this property to its default value.
inheritIt inherits this property from its parent element.

Example without using word-break

In below example we understand what happen when we do not use word-break. Larger word will be display out side the box area

Example

<!DOCTYPE html>  
<html>  
<head>  
<style>  
p.box {  
    width: 140px;  
    background: cyan;   
    border: 1px solid #000000;  
    padding:10px;  
} 
</style>  
</head>  
<body>  
<p class="box">This is my first html with css code. Now i am happyyyyyyyyyyyyyyyyyyy. How are you friendssssssssssssssssss?</p>  
</body>  
</html>

Example using word-break

Example

<!DOCTYPE html>  
<html>  
<head>  
<style>  
p.box {  
    width: 140px;  
    background: cyan;   
    border: 1px solid #000000;  
    padding:10px;  
    word-wrap: break-word;  
} 
</style>  
</head>  
<body>  
<p class="box">This is my first html with css code. Now i am happyyyyyyyyyyyyyyyyyyy. How are you friendssssssssssssssssss?</p>  
</body>  
</html>

 

Start typing and press Enter to search