Breaking text to new line with csss

There are several ways to break text to a new line using CSS:

  1. Using the br element: You can use the <br> element to insert a line break in your HTML code. However, this method is not recommended as it's not semantic and can cause issues with screen readers.

Example:

<p>This is a paragraph of text.<br>This is a new line.</p>
  1. Using the white-space property: You can use the white-space property to specify how whitespace characters (such as spaces, tabs, and line breaks) should be treated.

Example:

p {
  white-space: pre-line;
}

This will preserve the line breaks in the HTML code and render them as new lines in the browser.

  1. Using the word-wrap property: You can use the word-wrap property to specify whether the text should wrap to a new line or not.

Example:

p {
  word-wrap: break-word;
}

This will wrap the text to a new line if it exceeds the width of the container.

  1. Using the overflow-wrap property: You can use the overflow-wrap property to specify whether the text should wrap to a new line or not.

Example:

p {
  overflow-wrap: break-word;
}

This will wrap the text to a new line if it exceeds the width of the container.

  1. Using the display property: You can use the display property to specify the display type of the element.

Example:

p {
  display: block;
}

This will render the paragraph as a block-level element, which means it will take up the full width of its parent element and will automatically wrap to a new line.

  1. Using the flex-wrap property: You can use the flex-wrap property to specify whether the flex items should wrap to a new line or not.

Example:

p {
  display: flex;
  flex-wrap: wrap;
}

This will wrap the flex items to a new line if they exceed the width of the container.

  1. Using the text-wrap property: You can use the text-wrap property to specify whether the text should wrap to a new line or not.

Example:

p {
  text-wrap: wrap;
}

This will wrap the text to a new line if it exceeds the width of the container.

Note that some of these methods may have different effects depending on the browser and device being used. It's always a good idea to test your code in different browsers and devices to ensure that it works as expected.