Using the CSS property hyphens: auto does not function properly for certain words

Could someone shed light on why the word "Sustainability" is not being correctly hyphenated in the following code snippet? I have tested it in multiple browsers like Google Chrome, FireFox, and Safari, and none of them seem to hyphenate the word, even though they do so for words like "hyphenated".

Here are my findings so far:

  1. Hyphenation works if the word is not capitalized.
  2. Changing the lang attribute from en to de (German) also enables hyphenation, even though the word is in English.

:root {
  font-size: 20px;
  font-family: system-ui;
  padding: 2rem;
}
body {
  margin: 0;
}
p {
  border: 1px solid;
  width: 100px;
  hyphens: auto;
}
<html lang="en">
  <body>
    <p>The word Sustainability can't be hyphenated, apparently</p>
    <p>Only if written without a capital "S", it starts working: sustainability 🤔</p>
  </body>
</html>

Answer â„–1

The guidelines state clearly: https://www.w3.org/TR/css-text-3/#hyphenation

"In order to enhance user experience, browsers may choose to exclude certain words from automatic hyphenation using language-specific rules. For instance, a browser may opt to avoid hyphenating proper nouns by detecting words with specific capitalization and punctuation patterns. These rules are not covered in this particular document. (Please note that these rules are language-specific and may differ based on the capitalization norms of different languages such as English and German.)"

Answer â„–2

The behavior seems to be a deliberate choice in accordance with language rules. Currently, there are limited hyphenation control tools available, leaving browsers to determine the hyphenation process when using the hyphens: auto property.

One possible workaround is to utilize a soft wrap character such as U+005F or the &shy; HTML entity.

Answer â„–3

To prevent this issue with words that are in capital letters or uppercase, one simple trick is to write the word in lowercase:

<strong>Lorem <span>averyreallylongword</span> ipsum</strong>

Then, you can use CSS to achieve the desired result:

strong {hyphens: auto;}
span {text-transform: capitalize;} // similar to 'Titlecase'

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Display HTML using JavaScript/jQuery

I am trying to figure out how to print a document by passing custom HTML code. Below is the code I have tried, but unfortunately it's not working: function Clickheretoprint() { var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes, ...

Showcasing top performers via JavaScript tabs

I have two tabs on my webpage: "Overall Leaderboard" and "Weekly Leaderboard". Each tab displays a leaderboard with different scores. When I click on the "Overall Leaderboard" tab, it shows a leaderboard with specific scores. Now, my question is how can ...

What is the process for setting the active state for HtmlBodyElement?

I attempted to use the following method: document.querySelector('body').setActive(); However, I encountered an error: TS2339: Property 'setActive' does not exist on type 'HTMLBodyElement'. Any suggestions on how to resolve t ...

Steps for Disabling col-sm and col-xs in Bootstrap 3

Hey there! I'm currently working on a template using Bootstrap 3. Initially, I planned to make it responsive for all devices, but I have since changed my mind and decided that the template is already complete. I've utilized col-md in each row, h ...

There seems to be an issue with Bootstrap: the property this._config is

Here is the button I have: <button class="kv_styleclass_0 btn btn-outline-success btn-lg" data-bs-toggle="modal" data-bs-target="formModal" type="button"> Become a participant </button ...

Locking the second column of a data table with CSS to prevent scrolling

We need to freeze two columns in our data table - "PPD Delivery Schedule" and "Check Opex". The first column is working fine, but we're having issues freezing the second column. We've tried various approaches but haven't been successful so ...

how to enable drag and drop functionality based on names in angularjs

In my project using angular js, I have implemented a drag and drop feature that allows items to be dragged between cells in two directions. I now want to enhance this functionality by allowing members with 'a's (e.g. 1a, 2a, etc.) to be dragged ...

Opacity transition in CSS does not function properly on a sibling selector when hovering over an element

I have created a responsive menu where the list items after the 4th element are set to display:none; opacity:0 on mobile devices. The 4th element is an icon and when you hover over it, the hidden menu items appear as a block list below using li:nth-child( ...

Manipulate DIV elements with jQuery by selecting them based on their class names and then

Is there a way to use jQuery to eliminate all DIVs on a webpage while preserving their content that have the following specific pattern? <div class="ExternalClass85AC900AB26A481DBDC8ADAE7A02F039">....</div> Please note that these DIVs adhere ...

Adjusting the width of a DIV element within a table cell

In my ASP.NET application, I am facing an issue with table column widths not rendering as expected in the browser. Despite setting the column width to 100px, it appears as either 96px or 108px. The problem seems to be related to having a div inside the th ...

Cannot see the toggler button in Bootstrap 4 Navbar

I recently implemented the toggler button (hamburger icon) code in my HTML, but I'm facing an issue where the hamburger icon doesn't appear and looks blank when I resize my screen or view it on a smaller viewport. Here's the snippet of my H ...

Go through each row in a table and retrieve the value of a column only if the checkbox

Is there a way to extract only the values in the serial column if the checkbox is checked for that row using jquery? I am currently able to retrieve the serial value, but unsure how to incorporate the checkbox condition. HTML: <table id="usersTable"&g ...

The <footer> element refuses to be placed at the bottom of the page

Struggling to keep my <footer> tag at the bottom of my page despite trying various techniques. Check out my website below to see the issue in action: ...

Unable to apply margin right to React Material-UI table

I am struggling to add margin to the right of a mui table with no success. Below is the code I have used: <TableContainer> <Table sx={{ mr: 100 }} aria-label="customized table"> <TableHead> <Tabl ...

When I open my website in the browser, the bootstrap card-deck design is not being displayed correctly

I encountered a strange issue while designing my website. The code I wrote for the Bootstrap card-deck class in codeply.com was working perfectly fine. However, when I copied the same code into my PyCharm code editor and then pasted the file link into my b ...

Tips for adjusting a web address provided by a user

I have a JavaScript code that prompts the user to input a URL and then appends it to a div. The code is working fine, but now I am trying to add functionality to edit the entered URL by changing the width and height of any iframes before appending them. ...

Responsive Bootstrap 4 navigation bar featuring collapsible menu and various elements displayed on the right side

I have been struggling for quite some time to create a mobile menu using Bootstrap 4. My goal is to display the 3 brand names and the toggle button on the same row in the mobile menu. However, when I click the toggle button, the 3 brands end up below the c ...

Using the columns property in CSS3 along with background-color

My ul-element has multiple lis with a background color assigned to it. I am using the CSS3 columns property and everything is working well, but the background color of my ul is only visible in the first column. What could be causing this issue? Thank you ...

Is there a way to determine if two distinct selectors are targeting the same element on a webpage?

Consider the webpage shown below <div id="something"> <div id="selected"> </div> </div> Within playwright, I am using two selectors as follows.. selectorA = "#something >> div >> nth=1&q ...

Using PHP/MySQL to enable users to make changes to their account details

I've successfully set up 2 pages update.php edit.php We begin on edit.php, so here is the script for edit.php <?php session_start(); $id = $_SESSION["id"]; $username = $_POST["username"]; $fname = $_POST["fname"]; $password = $_POST["password"]; ...