w3resource

HTML5: How to defines a possible line-break?

Go to Exercise page

Solution :

HTML Code:

<!DOCTYPE html><!-- Define document type as HTML -->
<html><!-- Begin HTML document -->
<head><!-- Start of document header -->
<meta charset="utf-8"><!-- Define character encoding -->
<title>How to defines a possible line-break</title><!-- Title of the HTML page -->
</head><!-- End of document header -->
<body><!-- Start of document body -->
<p>wbr element is a veryveryveryveryveryveryveryveryveryveryvery<wbr>longwordthatwillbreakatspecific<wbr>placeswhenthebrowserwindowisresized.</p>
<!-- Paragraph containing text with wbr elements -->
</body><!-- End of document body -->
</html><!-- End of HTML document -->
   

Explanation:

  • The HTML code includes a paragraph (<p>) element.
  • Inside the paragraph, the wbr element is used to define possible line breaks within a long word.
  • When the browser window is resized, the browser will break the long word at the specified <wbr> elements, allowing for better readability without affecting the overall layout of the page.

Live Demo:

See the Pen wbr-answer by w3resource (@w3resource) on CodePen.


See the solution in the browser

Supported browser

Firefox logo Chrome logo Opera logo Safari logo Internet Explorer logo
Yes Yes Yes Yes Yes

Go to Exercise page

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.