CSS | overflow-wrap Property

The overflow-wrap property in CSS is used to specify that the browser may break lines of text inside any targeted element to prevent overflow when the original string is too long to fit. This property was earlier known as word-wrap that still supported by some browsers but it was renamed to overflow-wrap in a CSS3 draft.

Syntax:

.box{
    overflow-wrap: break-word;
}

Values:

  • normal: The lines will break according to the original line breaking rules.
  • break-word: Words that are too long to fit in a container-element break into parts.
  • inherit: It allows the element to inherit value from its parent.
  • initial: It makes the property to use its default value.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        CSS overflow-wrap property
    </title>
  
    <style>
        p {
            color: green;
        }
  
        .gfg {
            margin: auto;
            padding: 15px 15px;
            color: white;
            background-color: green;
            font-size: 20px;
            width: 60px;
            overflow-wrap: break-word;
        }
  
        div {
            text-align: justify;
        }
  
        h1,
        h2 {
            color: green;
        }
  
        h1,
        h2 {
            text-align: center;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <h2>overflow-wrap property</h2>
    <div class="gfg">
        A computer science portal for geeks.
    </div>
</body>
  
</html>

chevron_right


Output:




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.