Javatpoint Logo
Javatpoint Logo

CSS Wrap

We will comprehend the CSS wrap in this article. The wrap properties in CSS are used to wrap the text or element within the container.

There are various CSS wrap properties, which are as follows:

Flex-wrap

It is utilized to define that the flexible items should either be wrapped or not.

Syntax:

The flex-wrap is the CSS property in the above syntax, and the value given to this property can be wrap, nowrap, wrap-reverse, initial, and inherit. The values are discussed below:

  • Wrap: It is utilized to describe the flexible items to wrap if required.
  • nowrap: It is utilized to describe the flexible items, not to wrap the elements. It is the default value.
  • Wrap-reverse: It is utilized to describe the flexible items to wrap if required but in reverse order.
  • Initial: It is utilized to define the default value.
  • Inherit: It is utilized to inherit the property of the parent element.

Note: The elements must be flexible; only then the "flex-wrap" CSS property will show its effects which means the "display" CSS property of elements must be set to flex.

Demonstration

Let us comprehend the flex-wrap property with the help of the demonstration.

We will set the flex-wrap to wrap, nowrap, wrap-reverse, initial, and inherit.

Code:

Output:

We can witness the output in which the flex-wrap property is applied.

CSS Wrap

Word-wrap:

It is utilized to break long words or to prevent the breaking of long words when the container overflows.

Syntax:

The word-wrap is the CSS property in the above syntax, and the value given to this property can be break-word, normal, initial, and inherit. The values are described below:

  • Break-word: It is utilized to break the long words when the container overflows.
  • Normal: This value is utilized to stop the breaking of the long words, and it is the default value.
  • Initial: It is utilized to set the default value.
  • Inherit: It is utilized to inherit the properties of the parent.

Demonstration:

Let us understand the word-wrap property with the help of the demonstration.

We will set the word-wrap to normal, break-word, initial, and inherit.

Code:

Output:

We can witness the output in which the word-wrap property is applied. Paragraphs 1, paragraph 3, and paragraph 4 show the words overflowing from the container when the word-wrap property is set to either normal, initial, or inherit. Paragraph 2 displays the breaking of long words when the word-wrap property is set to break-word.

CSS Wrap

Overflow-wrap

It is utilized to prevent or break the lines when the container overflows.

Syntax:

The overflow-wrap is the CSS property in the above syntax, and the value given to this property can be normal, break-word, anywhere, initial, and inherit. The values are discussed below:

  • Normal: This value is used to let the container overflow so it will not break the long words, and it is the default value.
  • Break-word: It is used to break the long words only when the container overflows.
  • Anywhere: When the container overflows, then this value breaks the long words.
  • Initial: It is used to set the default value.
  • Inherit: It is utilized to inherit the properties of the parent element.

Illustration:

Let us comprehend the overflow-wrap property with the help of the illustration.

We will set the overflow-wrap to normal and break-word.

Code:

Output:

We can witness the output in which the overflow-wrap property is applied. Paragraph 1 shows the words overflowing from the container because the overflow-wrap property is set to normal, and paragraph 2 displays the breaking of long words because the overflow-wrap property is set to break-word.

CSS Wrap

Browser Support:

Following are the browsers that support CSS wrap properties:

  • Google Chrome
  • Safari
  • Opera
  • Microsoft Edge
  • Firefox

Conclusion

We have comprehended the CSS wrap in this article. We have seen various CSS wrap properties:

  • Flex-wrap property: It is utilized to wrap the flexible elements when the container overflows.
  • Word-wrap property: It is utilized to wrap the long words when the container overflows.
  • Overflow-wrap property: It is utilized to wrap the long words and break the lines when the container overflows.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA