Javascript DOM CSS Style wordWrap Property

Introduction

Allow long words to be able to break and wrap onto the next line:

document.getElementById("myDIV").style.wordWrap = "break-word";

Click the button to change the let the DIV element wrap words:

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {/*from  www  . j  a  va2 s  .  c om*/
  width: 150px;
  height: 100px;
  background-color: lightblue;
  border: 1px solid black;
}
</style>
</head>
<body>
<div id="myDIV">testtesttesttesttesttesttesttesttesttesttesttesttesttest</div>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {
  document.getElementById("myDIV").style.wordWrap = "break-word";
}
</script>

</body>
</html>

The wordWrap property allows long words to be able to be broken and wrap onto the next line.

Property Values

Value Description
normal Default. Break words only at allowed break points
break-word Allows unbreakable words to be broken
initialSets this property to its default value.
inheritInherits this property from its parent element.

The wordWrap property returns a String representing the word-wrap property of an element.




PreviousNext

Related