Open In App

CSS word-wrap Property

Last Updated : 29 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The word-wrap property in CSS is used to manage the breaking and wrapping of long words within an element, ensuring that the content fits within its container. This property is essential for maintaining readability and layout integrity when dealing with lengthy words or strings without spaces. 

Syntax

word-wrap: normal|break-word|initial|inherit;

Property Value

ValueDescription
normalDefault value; lines can only be broken at normal break points (spaces, non-alphanumeric characters).
break-wordWords that exceed the width of the container will be arbitrarily broken to fit within the bounds.
initialSets the word-wrap property to its default value.
inheritInherits the property from its parent.

Example: Using word-wrap: normal

This example demonstrates the default behavior where words only break at normal break points.

Example: In the example, word-wrap: normal; ensures text in the <div> breaks only at spaces or punctuation, not within words, causing overflow beyond the container’s 150px width.

html
<!DOCTYPE html>
<html>
  
<head>
    <title>
        word-wrap property
    </title>

    <style>
        div {
            word-wrap: normal;
            width: 150px;
            border: 1px solid black;
        }
    </style>
</head>

<body>
    <div>
        GeeksforGeeks:AComputerSciencePortalForGeeks
    </div>

</body>
  
</html>

Output: word wrapExample: Using word-wrap: break-word

This example shows how words exceeding the container’s width are broken to fit within the bounds.

Example: In this example, the word-wrap: break-word; allows the text in the <div> to break arbitrarily within words to fit within the 150px width container.

html
<!DOCTYPE html>
<html>
  
<head>
    <title>
        word-wrap property
    </title>

    <style>
        div {
            word-wrap: break-word;
            width: 150px;
            border: 1px solid black;
        }
    </style>
</head>

<body>
    <div>
        GeeksforGeeks:AComputerSciencePortalForGeeks
    </div>

</body>
  
</html>

Output:

word wrap

By using the word-wrap property, you can control how long words are handled in your layouts, ensuring that content remains within its container and maintaining a clean, readable presentation.

Supported Browsers: The browser supported by word-wrap property are listed below:


Next Article

Similar Reads