<header>
  <h2 class="title">element.style.wordBreak</h2>
  <p class="description">Керує тим, як слова переносяться на новий рядок у тексті елемента.</p>
</header>
<main>
  <div class="result">
    <!-- Кнопки для зміни режиму перенесення тексту -->
    <button id="normalButton">Normal</button>
    <button id="breakAllButton">Break-All</button>
    <button id="keepAllButton">Keep-All</button>
    <button id="breakWordButton">Break-Word</button>
    <!-- Елемент для демонстрації -->
    <div id="textElement" class="text-element">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Supercalifragilisticexpialidocious non-breakingword veryveryverylongwordthatneedstobebroken.
    </div>
  </div>
</main>
body {
  font-size: 16px;
  line-height: 1.5;
  font-family: monospace;
}

header {
  background-color: #f1f1f1;
  margin-bottom: 25px;
  padding: 15px;
  -webkit-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  -moz-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}

header h2.title {
  padding-bottom: 15px;
  border-bottom: 1px solid #999;
}

header p.description {
  font-style: italic;
  color: #222;
}

.result {
  background-color: #f8f8f8;
  padding: 15px;
  -webkit-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  -moz-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}

.text-element {
  margin-top: 15px;
  padding: 10px;
  background-color: #fff;
  border: 1px solid #ddd;
  width: 100%;
  max-width: 600px;
  word-break: normal;
}
document.addEventListener('DOMContentLoaded', function() {
  const normalButton = document.getElementById('normalButton');
  const breakAllButton = document.getElementById('breakAllButton');
  const keepAllButton = document.getElementById('keepAllButton');
  const breakWordButton = document.getElementById('breakWordButton');
  const textElement = document.getElementById('textElement');

  normalButton.addEventListener('click', function() {
    textElement.style.wordBreak = 'normal';
  });

  breakAllButton.addEventListener('click', function() {
    textElement.style.wordBreak = 'break-all';
  });

  keepAllButton.addEventListener('click', function() {
    textElement.style.wordBreak = 'keep-all';
  });

  breakWordButton.addEventListener('click', function() {
    textElement.style.wordBreak = 'break-word';
  });
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.