The Wayback Machine - https://web.archive.org/web/20250119182008/https://www.geeksforgeeks.org/css-word-wrap-property/
Open In App

CSS word-wrap Property

Last Updated : 29 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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:

CSS word-wrap Property – FAQs

What is the function of the word-wrap property in CSS?

The word-wrap property specifies whether long words should be broken and wrapped onto the next line.

What is the difference between word-wrap and overflow-wrap?

word-wrap is the legacy name for overflow-wrap; they both perform the same function of breaking and wrapping long words.

How can I ensure that words break only when necessary?

Use word-wrap: normal; to ensure words break only at normal break points, not within words.

Can word-wrap handle unbreakable content like URLs?

Yes, word-wrap: break-word; will break long words or unbreakable content like URLs onto the next line.

Does word-wrap apply to all block-level elements?

Yes, word-wrap can be applied to any block-level element containing text content.


Next Article

Similar Reads

three90RightbarBannerImg