CSS - hyphens



CSS hyphens property controls how words are broken into lines when text is too long to fit on a single line. This property can be used to improve the readability of text that wraps across multiple lines.

The property only applies to block-level elements.

Following are all possible values that can be used for property hypens:

  • none − No hyphenation is allowed.

  • manual − It specifoes manual hyphenation behavior for text in WebKit-based browsers.

  • auto − Hyphenation is allowed at appropriate hyphenation points, as determined by the browser.

  • initial − The initial value, which is manual.

  • inherit − The value inherited from the parent element.

CSS hyphens - none Value

The hyphens: none property value prevents hyphenation of words. It will not be broken into lines, even if they are too long to fit on a single line.

<html>
<head>
<style>
   .container {
      border: 2px solid #12782f;
      background-color: #2fe262;
      width: 60px;
   }
   .hyphenated-none {
      hyphens: none;
   }
</style>
</head>
<body>
   <div class="container">
      <p class="hyphenated-none">It is a long established Contrary to popularised.</p>
   </div >
</body>
</html>

CSS hyphens - manual Value

When you use the CSS hyphens: manual property, hyphenation is only allowed at points where the user has explicitly inserted hyphens. This is a default value.

<html>
<head>
<style>
   .container {
      border: 2px solid #12782f;
      background-color: #2fe262;
      width: 60px;
   }
   .hyphenated-manual {
      hyphens: manual;
   }
</style>
</head>
<body>
   <div class="container">
      <p class="hyphenated-manual">It is a long establ-ished Contrary to popula-rised.</p>
   </div >
</body>
</html>

CSS hyphens - auto Value

You can use the CSS hyphens: auto property to let the browser automatically hyphenate words at points that are considered to be appropriate, according to the language's hyphenation rules.

<html>
<head>
<style>
   .container {
      border: 2px solid #12782f;
      background-color: #2fe262;
      width: 60px;
   }
   .hyphenated-auto {
      hyphens: auto;
   }
</style>
</head>
<body>
   <div class="container">
      <p class="hyphenated-auto">It is a long established Contrary to popularised.</p>
   </div>
</body>
</html>

CSS hyphens - initial Value

CSS hyphens: initial property sets the hyphens property to its initial value. The initial value for the hyphens property is manual, which means that hyphenation is only allowed at points where the user has explicitly inserted hyphens.

<html>
<head>
<style>
   .container {
      border: 2px solid #12782f;
      background-color: #2fe262;
      width: 60px;
   }
   .hyphenated-initial {
      hyphens: initial;
   }
</style>
</head>
<body>
   <div class="container">
      <p class="hyphenated-initial">It is a long establ-ished Contrary to popu-larised.</p>
   </div >
</body>
</html>

CSS hyphens - inherit Value

When you use the hyphens: inherit property, the value of the hyphens property is inherited from the parent element. The hyphenation of the element will be the same as the hyphenation of its parent element.

<html lang="en">
<head>
<style>
   .container {
      border: 2px solid #12782f;
      background-color: #2fe262;
      width: 60px;
      padding: 2px;
      hyphens: auto;
   }
   .hyphenated-inherit {
      border: 2px solid #ac3f08;
      background-color: #f05e40;
      hyphens: inherit;
   }
</style>
</head>
<body>
   <div class="container">
      There are many variations of embarrassing of Lorem Ipsum.
      <p class="hyphenated-inherit">It is a long establ-ished Contrary to popu-larised.</p>
   </div >
</body>
</html>
Advertisements