Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS overflow-wrap Property

Posted in CSS Tutorial
Updated on Jul 25, 2024
By Mari Selvan
👁️ 11 - Views
⏳ 4 mins
💬 1 Comment
CSS overflow-wrap Property

Photo Credit to CodeToFun

🙋 Introduction

The overflow-wrap property in CSS is used to specify how the browser should handle long words or unbreakable text that overflows the boundaries of its container.

This property helps improve the readability and layout of text content, especially in responsive design scenarios. It ensures that text does not break the layout or cause horizontal scrolling issues.

💡 Syntax

The overflow-wrap property can be applied to any block-level or inline-level element. It has the following syntax:

Syntax
Copied
Copy To Clipboard
element {
  overflow-wrap: value;
}

Here, value can be one of the predefined keywords described below.

🎛️ Default Value

The default value of the overflow-wrap property is normal. This means that the browser will use its default line-breaking rules, which may not always prevent long words from overflowing their container.

🏠 Property Values

ValueDescription
normalAllows words to overflow their container if they do not fit. This is the default behavior.
break-wordBreaks long words and wraps them onto the next line to prevent overflow. This value ensures that even if a word is too long to fit, it will break to avoid horizontal scrolling.

📄 Example

In this example, we’ll apply the overflow-wrap property to a paragraph element to handle long words gracefully.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS overflow-wrap Example</title>
  <style>
    .text-container {
      width: 200px;
      border: 1px solid #ccc;
      padding: 10px;
      overflow-wrap: break-word;
    }
  </style>
</head>
<body>
  <h1>Text Container with Overflow Wrap</h1>
  <div class="text-container">
    This is an example of a verylongwordthatwillbreakandwrapcorrectlyinsideitscontainerwithoutcausinganyoverflowissues.
  </div>
</body>
</html>

🖥️ Browser Compatibility

The overflow-wrap property is widely supported across modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. It is a reliable solution for managing text overflow issues in most web environments.

🎉 Conclusion

The overflow-wrap property is a valuable tool for controlling how text content behaves when it exceeds its container.

By using this property, you can improve the readability and user experience of your website by ensuring that text wraps correctly and avoids causing layout problems. Experiment with different values to see how they affect your text content and find the best fit for your design needs.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy