How to Wrap Text in HTML
We’ll learn how to wrap text in HTML in today’s post.
Text Wrap in HTML
Text editors and word processors have features known as text wrap
or a text flow
. When the side of the page is reached, it enables the user’s text to be carried over to the following line.
Long words can be split up and wrapped into the following line thanks to the word-wrap
attribute.
Syntax:
word-wrap: value
The four values that word-wrap
supports are listed as follows:
- The
word-wrap
property’s default value isnormal
, which only breaks words at permitted places. - Unbreakable words can be broken thanks to the
break-word
value. - The value
initial
sets this property to its default setting. - The value
inherit
inherits this attribute from its parent element.
To further understand the previous concept, consider the following example.
<div>
Helloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo World!
</div>
div {
width: 350px;
word-wrap: break-word;
}
The above example prints the phrase hello world
within a div
with 285 characters. The word-wrap: break-word;
attribute is used to automatically break the word on the following line when the width on the screen surpasses 350px
.
Shraddha is a JavaScript nerd that utilises it for everything from experimenting to assisting individuals and businesses with day-to-day operations and business growth. She is a writer, chef, and computer programmer. As a senior MEAN/MERN stack developer and project manager with more than 4 years of experience in this sector, she now handles multiple projects. She has been producing technical writing for at least a year and a half. She enjoys coming up with fresh, innovative ideas.
LinkedIn