Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <header>
  <h1>Techniques to Break Words</h1>
  <p>
    Used in the post <cite><a href="https://adrianroselli.com/2024/02/techniques-to-break-words.html" target="_top">Text Wrap Techniques</a></cite>. Check the <a href="https://validator.w3.org/nu/?doc=https%3A%2F%2Fcdpn.io%2Fpen%2Fdebug%2FeYoOdrX" target="_top">validation results</a> from W3C's Nu HTML Checker.
  </p>
</header>
<nav>
  <fieldset id="C">
    <legend>CSS properties</legend>
    <button type="button" id="C1" onclick="wrappage(this.id);" aria-pressed="true">none</button>
    <button type="button" id="C2" onclick="wrappage(this.id);" aria-pressed="false"><code>word-break</code></button>
    <button type="button" id="C3" onclick="wrappage(this.id);" aria-pressed="false"><code>overflow-wrap</code></button>
    <button type="button" id="C4" onclick="wrappage(this.id);" aria-pressed="false"><code>hyphens</code></button>
    <!--   <button type="button" id="C5" onclick="wrappage(this.id);" aria-pressed="false"><code>hyphens:manual</code></button> -->
  </fieldset>
  <fieldset id="T">
    <legend><code>table-layout</code></legend>
    <button type="button" id="T1" onclick="tablesLayout(this.id);" aria-pressed="true">nah</button>
    <button type="button" id="T2" onclick="tablesLayout(this.id);" aria-pressed="false"><code>fixed</code></button>
  </fieldset>
  <fieldset id="H">
    <legend id="HL"><code>hyphenate-character</code></legend>
    <input type="text" id="H1" value="🤔" aria-labelledby="HL">
    <button type="button" onclick="setHyphen('H1');">Do it</button>
  </fieldset>
  <fieldset id="W">
    <legend id="WL"><code>max-width</code></legend>
    <input type="text" id="W1" value="6em" aria-labelledby="WL">
    <button type="button" onclick="setMaxWidth('W1');">Do it</button>
  </fieldset>
</nav>

<main>
  <!-- No wrap -->

  <div>
    <h2>CSS</h2>
    <div>
      <p>
        supercalifragilisticexpialidocious
      </p>
      <p lang="de">
        Donaudampfschifffahrtsgesellschaftskapitän
      </p>
      <p lang="he" dir="rtl">
        וכשלאנציקלופדיותינו
      </p>
      <p lang="hi">
        लौहपथगामिनीसूचकदर्शकहरितताम्रलौहपट्टिकाएँ
      </p>
      <p lang="ja">
        愛知県海部郡飛島村大字飛島新田字竹之郷ヨタレ南ノ割
      </p>
      <p lang="ar" dir="rtl">
        أَفَيَسْتَكْتِبونَكُمانيهِما
      </p>
      <p>
        https://en.wikipedia.org/wiki/The_King_in_Yellow
      </p>
      <p>
        JR-Bob.Dobbs@CoSG.example.com
      </p>
      <table>
        <caption>Words</caption>
        <tr>
          <th>Language</th>
          <th>Word</th>
        </tr>
        <tr>
          <th>English</th>
          <td>
            supercalifragilisticexpialidocious
          </td>
        </tr>
        <tr>
          <th>German</th>
          <td lang="de">
            Donaudampfschifffahrtsgesellschaftskapitän
          </td>
        </tr>
        <tr>
          <th>Hebrew</th>
          <td lang="he" dir="rtl">
            וכשלאנציקלופדיותינו
          </td>
        </tr>
        <tr>
          <th>Hindi</th>
          <td lang="hi">
            लौहपथगामिनीसूचकदर्शकहरितताम्रलौहपट्टिकाएँ
          </td>
        </tr>
        <tr>
          <th>Japanese</th>
          <td lang="ja">
            愛知県海部郡飛島村大字飛島新田字竹之郷ヨタレ南ノ割
          </td>
        </tr>
        <tr>
          <th>Arabic</th>
          <td lang="ar" dir="rtl">
            أَفَيَسْتَكْتِبونَكُمانيهِما
          </td>
        </tr>
        <tr>
          <th>URL</th>
          <td>
            https://en.wikipedia.org/wiki/The_King_in_Yellow
          </td>
        </tr>
        <tr>
          <th>Email</th>
          <td>
            JR-Bob.Dobbs@CoSG.example.com
          </td>
        </tr>
        <tr>
          <th>Idiom</th>
          <td>
            Chicken/egg
          </td>
        </tr>
        <tr>
          <th>Idiom 2</th>
          <td>
            Chicken / egg
          </td>
        </tr>
      </table>
    </div>
  </div>

  <!-- wbr -->

  <div>
    <h2><code>&lt;wbr&gt;</code></h2>
    <div>
      <p>
        super<wbr>cali<wbr>frag<wbr>il<wbr>is<wbr>tic<wbr>ex<wbr>pial<wbr>id<wbr>oc<wbr>ious
      </p>
      <p lang="de">
        Donau<wbr>dampf<wbr>schiff<wbr>fahrts<wbr>gesell<wbr>schafts<wbr>kapitän
      </p>
      <p lang="he" dir="rtl">
        וכשלאנ<wbr>ציקלופ<wbr>דיותינו
      </p>
      <p lang="hi">
        लौहपथगा<wbr>मिनीसू<wbr>चकदर्शक<wbr>हरितताम्रल<wbr>ौहपट्टिकाएँ
      </p>
      <p lang="ja">
        愛知県海部<wbr>郡飛島村大<wbr>字飛島新田<wbr>字竹之郷ヨタ<wbr>レ南ノ割
      </p>
      <p lang="ar" dir="rtl">
        أَفَيَسْتَكْتِبو<wbr>نَكُمانيهِما
      </p>
      <p>
        https:<wbr>//en<wbr>.wikipedia<wbr>.org<wbr>/wiki<wbr>/The<wbr>_King<wbr>_in<wbr>_Yellow
      </p>
      <p>
        JR<wbr>-Bob<wbr>.Dobbs<wbr>@CoSG<wbr>.example<wbr>.com
      </p>
      <table>
        <caption>Words</caption>
        <tr>
          <th>Language</th>
          <th>Word</th>
        </tr>
        <tr>
          <th>English</th>
          <td>
            super<wbr>cali<wbr>frag<wbr>il<wbr>is<wbr>tic<wbr>ex<wbr>pial<wbr>id<wbr>oc<wbr>ious
          </td>
        </tr>
        <tr>
          <th>German</th>
          <td lang="de">
            Donau<wbr>dampf<wbr>schiff<wbr>fahrts<wbr>gesell<wbr>schafts<wbr>kapitän
          </td>
        </tr>
        <tr>
          <th>Hebrew</th>
          <td lang="he" dir="rtl">
            וכשלאנ<wbr>ציקלופ<wbr>
          </td>
        </tr>
        <tr>
          <th>Hindi</th>
          <td lang="hi">
            लौहपथगा<wbr>मिनीसू<wbr>चकदर्शक<wbr>हरितताम्रल<wbr>ौहपट्टिकाएँ
          </td>
        </tr>
        <tr>
          <th>Japanese</th>
          <td lang="ja">
            愛知県海部<wbr>郡飛島村大<wbr>字飛島新田<wbr>字竹之郷ヨタ<wbr>レ南ノ割
          </td>
        </tr>
        <tr>
          <th>Arabic</th>
          <td lang="ar" dir="rtl">
            أَأَفَيَسْتَكْتِبو<wbr>نَكُمانيهِما
          </td>
        </tr>
        <tr>
          <th>URL</th>
          <td>
            https:<wbr>//en<wbr>.wikipedia<wbr>.org<wbr>/wiki<wbr>/The<wbr>_King<wbr>_in<wbr>_Yellow
          </td>
        </tr>
        <tr>
          <th>Email</th>
          <td>
            JR<wbr>-Bob<wbr>.Dobbs<wbr>@CoSG<wbr>.example<wbr>.com
          </td>
        </tr>
        <tr>
          <th>Idiom</th>
          <td>
            Chicken/egg
          </td>
        </tr>
        <tr>
          <th>Idiom 2</th>
          <td>
            Chicken / egg
          </td>
        </tr>
      </table>
    </div>
  </div>

  <!-- &shy; -->

  <div>
    <h2><code>&amp;shy;</code></h2>
    <div>
      <p>
        super&shy;cali&shy;frag&shy;il&shy;is&shy;tic&shy;ex&shy;pial&shy;id&shy;oc&shy;ious
      </p>
      <p lang="de">
        Donau&shy;dampf&shy;schiff&shy;fahrts&shy;gesell&shy;schafts&shy;kapitän
      </p>
      <p lang="he" dir="rtl">
        וכשלאנ&shy;ציקלופ&shy;דיותינו
      </p>
      <p lang="hi">
        लौहपथगा&shy;मिनीसू&shy;चकदर्शक&shy;हरितताम्रल&shy;ौहपट्टिकाएँ
      </p>
      <p lang="ja">
        愛知県海部&shy;郡飛島村大&shy;字飛島新田&shy;字竹之郷ヨタ&shy;レ南ノ割
      </p>
      <p lang="ar" dir="rtl">
        أَفَيَسْتَكْتِبو&shy;نَكُمانيهِما
      </p>
      <p>
        https:&shy;//en&shy;.wikipedia&shy;.org&shy;/wiki&shy;/The&shy;_King&shy;_in&shy;_Yellow
      </p>
      <p>
        JR&shy;-Bob&shy;.Dobbs&shy;@CoSG&shy;.example&shy;.com
      </p>
      <table>
        <caption>Words</caption>
        <tr>
          <th>Language</th>
          <th>Word</th>
        </tr>
        <tr>
          <th>English</th>
          <td>
            super&shy;cali&shy;frag&shy;il&shy;is&shy;tic&shy;ex&shy;pial&shy;id&shy;oc&shy;ious
          </td>
        </tr>
        <tr>
          <th>German</th>
          <td lang="de">
            Donau&shy;dampf&shy;schiff&shy;fahrts&shy;gesell&shy;schafts&shy;kapitän
          </td>
        </tr>
        <tr>
          <th>Hebrew</th>
          <td lang="he" dir="rtl">
            וכשלאנ&shy;ציקלופ&shy;דיותינו
          </td>
        </tr>
        <tr>
          <th>Hindi</th>
          <td lang="hi">
            लौहपथगा&shy;मिनीसू&shy;चकदर्शक&shy;हरितताम्रल&shy;ौहपट्टिकाएँ
          </td>
        </tr>
        <tr>
          <th>Japanese</th>
          <td lang="ja">
            愛知県海部&shy;郡飛島村大&shy;字飛島新田&shy;字竹之郷ヨタ&shy;レ南ノ割
          </td>
        </tr>
        <tr>
          <th>Arabic</th>
          <td lang="ar" dir="rtl">
            أَفَيَسْتَكْتِبو&shy;نَكُمانيهِما
          </td>
        </tr>
        <tr>
          <th>URL</th>
          <td>
            https:&shy;//en&shy;.wikipedia&shy;.org&shy;/wiki&shy;/The&shy;_King&shy;_in&shy;_Yellow
          </td>
        </tr>
        <tr>
          <th>Email</th>
          <td>
            JR&shy;-Bob&shy;.Dobbs&shy;@CoSG&shy;.example&shy;.com
          </td>
        </tr>
        <tr>
          <th>Idiom</th>
          <td>
            Chicken/egg
          </td>
        </tr>
        <tr>
          <th>Idiom 2</th>
          <td>
            Chicken / egg
          </td>
        </tr>
      </table>
    </div>
  </div>

  <!-- &shy; with hyphens manual -->

  <div>
    <h2><code>hyphens:manual</code></h2>
    <div class="hyphens manual">
      <p>
        super&shy;cali&shy;frag&shy;il&shy;is&shy;tic&shy;ex&shy;pial&shy;id&shy;oc&shy;ious
      </p>
      <p lang="de">
        Donau&shy;dampf&shy;schiff&shy;fahrts&shy;gesell&shy;schafts&shy;kapitän
      </p>
      <p lang="he" dir="rtl">
        וכשלאנציקלופדיותינו
      </p>
      <p lang="hi">
        लौहपथगामिनीसूचकदर्शकहरितताम्रलौहपट्टिकाएँ
      </p>
      <p lang="ja">
        愛知県海部郡飛島村大字飛島新田字竹之郷ヨタレ南ノ割
      </p>
      <p lang="ar" dir="rtl">
        أَفَيَسْتَكْتِبونَكُمانيهِما
      </p>
      <p>
        https:&shy;//en&shy;.wikipedia&shy;.org&shy;/wiki&shy;/The&shy;_King&shy;_in&shy;_Yellow
      </p>
      <p>
        JR&shy;-Bob&shy;.Dobbs&shy;@CoSG&shy;.example&shy;.com
      </p>
      <table>
        <caption>Words</caption>
        <tr>
          <th>Language</th>
          <th>Word</th>
        </tr>
        <tr>
          <th>English</th>
          <td>
            super&shy;cali&shy;frag&shy;il&shy;is&shy;tic&shy;ex&shy;pial&shy;id&shy;oc&shy;ious
          </td>
        </tr>
        <tr>
          <th>German</th>
          <td lang="de">
            Donau&shy;dampf&shy;schiff&shy;fahrts&shy;gesell&shy;schafts&shy;kapitän
          </td>
        </tr>
        <tr>
          <th>Hebrew</th>
          <td lang="he" dir="rtl">
            וכשלאנציקלופדיותינו
          </td>
        </tr>
        <tr>
          <th>Hindi</th>
          <td lang="hi">
            लौहपथगामिनीसूचकदर्शकहरितताम्रलौहपट्टिकाएँ
          </td>
        </tr>
        <tr>
          <th>Japanese</th>
          <td lang="ja">
            愛知県海部郡飛島村大字飛島新田字竹之郷ヨタレ南ノ割
          </td>
        </tr>
        <tr>
          <th>Arabic</th>
          <td lang="ar" dir="rtl">
            أَفَيَسْتَكْتِبونَكُمانيهِما
          </td>
        </tr>
        <tr>
          <th>URL</th>
          <td>
            https:&shy;//en&shy;.wikipedia&shy;.org&shy;/wiki&shy;/The&shy;_King&shy;_in&shy;_Yellow
          </td>
        </tr>
        <tr>
          <th>Email</th>
          <td>
            JR&shy;-Bob&shy;.Dobbs&shy;@CoSG&shy;.example&shy;.com
          </td>
        </tr>
        <tr>
          <th>Idiom</th>
          <td>
            Chicken/egg
          </td>
        </tr>
        <tr>
          <th>Idiom 2</th>
          <td>
            Chicken / egg
          </td>
        </tr>
      </table>
    </div>
  </div>
</main>
              
            
!

CSS

              
                body {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  line-height: 1.4;
  /*   line-height: 1.5; */
  /*   letter-spacing: 0.12em; */
  /*   word-spacing: 0.16em; */
  background-color: #fefefe;
  color: #333;
  /* Changing bit */
  hyphenate-character: auto;
}

h1, h2 {
  line-height: 1;
}

h2 {
  font-size: 100%;
}

main {
  display: flex;
  flex-wrap: wrap;
  gap: 6em;
}

main > div {
/*   flex: 0 0 12em; */
}

/* This kinda has to say in sixth position */
div > div {
  margin: 0;
  background-color: #f3f3f3;
  max-width: 6em;
}

table {
/*   font-size: 90%; */
  border-collapse: collapse;
  width: 100%;
}

caption {
  font-style: italic;
  text-align: left;
}

td, th {
  border: .1em solid #ccc;
  text-align: left;
  padding: 0 .25em;
}

tr:not(:first-of-type) th, tr:not(:first-of-type) td {
  vertical-align: top;
}

/* Changing bits */

table.fixed {
  table-layout: fixed;
}

.word-break {
  word-break: break-all;
}

.overflow-wrap {
/* word-wrap in IE days */
  overflow-wrap: anywhere;
}

.hyphens {
  hyphens: auto;
}

.hyphens.manual {
  hyphens: manual;
}

/* Form bits*/

nav {
  top: 0;
  position: sticky;
  display: flex;
  flex-wrap: wrap;
}

button, input {
  font: inherit;
}

fieldset, legend {
  background-color: #fff;
/*   border: .1em solid #999; */
/*   margin-bottom: .5em; */
}

legend {
/*   padding-right: .5em;
  padding-left: .5em; */
/*   margin-left: -.85em; */
/*   border-right: none; */
/*   border-bottom: none; */
/*   border-top: none; */
}

button {
  border: .1em solid #11c;
  border-radius: .25em;
  padding: .25em .5em;
  color: #fff;
  background: #11c;
  display: inline-block;
  width: auto;
  text-shadow: 1px 1px 1px #000;
  font: inherit;
  font-size: 1rem;
  margin: .2em .1em;
}

button:focus, button:hover {
  outline: .2em solid #99f;
/*   outline-offset: .1em; */
}

button[aria-pressed]::before {
  content: "⊘ ";
}

button[aria-pressed="true"]::before {
  content: "✔ ";
}

button[aria-pressed="true"], button:not([aria-pressed]):active {
  color: #11c;
  background: #eee;
  text-shadow: none;
  border-color: #000;
}

#H1 {
  width: 1.2em;
}

#W1 {
  width: 2em;
}
              
            
!

JS

              
                function tablesLayout(btnID) {
  var losTables = document.querySelectorAll("table");
  if (btnID == "T1") {
    for (var i = 0; i < losTables.length; i++) {
      losTables[i].classList.remove("fixed");
    }
  } else {
    for (var i = 0; i < losTables.length; i++) {
      losTables[i].classList.add("fixed");
    }
  }
  var deToggle = document.querySelectorAll("#T button[aria-pressed]");
  for (var i = 0; i < deToggle.length; i++) {
    deToggle[i].setAttribute("aria-pressed", "false");
  }
  var theButton = document.getElementById(btnID);
  theButton.setAttribute("aria-pressed", "true");
}

function wrappage(btnID) {
  var theButton = document.getElementById(btnID);
  var losDivs = document.querySelectorAll("div>div");
  for (var i = 0; i < losDivs.length; i++) {
    losDivs[i].classList.remove(
      "word-break",
      "overflow-wrap",
      "hyphens",
      "none"
    );
    losDivs[i].classList.add(theButton.innerText);
  }
  var deToggle = document.querySelectorAll("#C button[aria-pressed]");
  for (var i = 0; i < deToggle.length; i++) {
    deToggle[i].setAttribute("aria-pressed", "false");
  }
  theButton.setAttribute("aria-pressed", "true");
}

const JSSbody = document.styleSheets[0].cssRules[0].style;

function setHyphen(txtID) {
  var txtField = document.getElementById(txtID);
  var hyphenVal = txtField.value;
  if (hyphenVal == "") {
    JSSbody.hyphenateCharacter = "auto";
  } else {
    // alert(JSS.hyphenateCharacter);
    // JSS.setProperty("hyphenate-character","'" + hyphenVal + "'");
    JSSbody.hyphenateCharacter = "'" + hyphenVal + "'";
  }
}

const JSSdivdiv = document.styleSheets[0].cssRules[5].style;

function setMaxWidth(txtID) {
  var txtField = document.getElementById(txtID);
  var widthVal = txtField.value;
  if (widthVal == "") {
    JSSdivdiv.maxWidth = "6em";
  } else {
    // alert(JSS.hyphenateCharacter);
    // JSS.setProperty("hyphenate-character","'" + hyphenVal + "'");
    JSSdivdiv.maxWidth = widthVal;
  }
}

// alert(JSSdivdiv.maxWidth);
              
            
!
999px

Console