The text exceeds the width of the paragraph

Something very odd is happening, a rare occurrence in my over 20 years of web development experience. The text within the paragraph seems to be overflowing its boundaries:

https://i.sstatic.net/bmB1zg7U.jpg

My client specifically requested the Duffy Script font from Adobe, which may be causing the issue. Interestingly, when I switch to sans serif, the problem disappears. But I am determined to find a solution!

I've created a simple jsfiddle to demonstrate the issue - you can resize the right-hand pane to see the same problem captured in the image: https://jsfiddle.net/GeorgeMooWoof/4x50etdy/6/

If anyone could offer some assistance, I would greatly appreciate it.

Thank you

@import url("https://use.typekit.net/twt4ckp.css");
.container {
  padding-right: 20px;
  background: yellow;
}

p {
  font-family: "duffy-script", sans-serif;
  font-weight: 400;
  font-style: normal;
  font-size: 24px;
  background: rgba(255, 0, 0, 0.2);
}
<div class="container">
  <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
    in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  </p>
</div>

Answer №1

This bug in chromium/blink browsers is due to the calt contextual alternate Opentype feature.

It seems that both chromium/blink based browsers (Chrome, Brave, Opera, Vivaldi ... and even Internet Expl... Edge) and webkit browsers (safari, web/epiphany, midori) struggle with calculating word length correctly for proper line breaks when this feature is active.
Definitely a bug (Firefox doesn't have this issue).

Check out @SyndRain's answer for additional solutions.

font-feature-settings:  'calt' 0;

This code resolves the problem while still allowing other features like ligatures to function.

Contextual alternate vs. ligature feature

On the surface, both features serve a similar purpose – replacing a specific character sequence with an alternate visual representation known as a "glyph".

  • Ligatures: replace a character sequence with a single glyph. For example, "ffi" (3 characters - 3 glyphs) is replaced by a compound glyph "ffi", consolidating three separate paths into one. Note: Browsers break ligatures into separate glyphs when custom letter spacing is applied.
  • Contextual substitutions: substitute glyphs based on character input sequences. Unlike ligatures, multiple glyphs can be substituted for a sequence of characters. For instance, replacing only the 2nd occurrence of "e" in "Queen" with an alternate glyph.

Fun facts: Yes, it's a bug!

While workarounds such as custom letter spacing may temporarily address the issue, ideally they wouldn't be necessary if opentype feature implementations were flawless.

  • Custom letter-spacing disables all ligatures, which could impact languages relying on ligatures like Arabic or Farsi combined with Latin text. However, since we're replacing individual characters with distinct glyph representations, it should not affect typographic quality.
  • The current W3C draft for higher-level opentype feature controls raises questions about contextual substitutions not being classified as a true ligature feature under
    font-variant-ligatures: contextual
    .

Further reading

Explore Microsoft's Opentype documentation:

For designers, insights from typenetwork.com:

  • OpenType at Work | Contextual Alternates

Answer №2

To get a more in-depth explanation, check out @herrstrietzel's post. Inside, it suggests using

font-variant-ligatures:no-contextual
(as per spec preference over font-feature-setting) to turn off contextual alternates.

(The inclusion of optimizeSpeed below is effective due to its impact on ligature suppression. The same goes for introducing a positive value for letter-spacing.)


text-rendering:optimizeSpeed resolved the issue for me (tested on Chrome and Edge).

@import url("https://use.typekit.net/twt4ckp.css");
.container {
  padding-right: 20px;
  background: yellow;
}

.par {
  font-family: "duffy-script", sans-serif;
  font-weight: 400;
  font-style: normal;
  font-size: 24px;
  background: rgba(255, 0, 0, 0.2);
  text-rendering: optimizeSpeed;
}
<div class="container">
  <p class="par">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
    in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  </p>
</div>

The OP also noted that including letter-spacing: 0.01px seemed to resolve the issue.

@import url("https://use.typekit.net/twt4ckp.css");
.container {
  padding-right: 20px;
  /* background: yellow; */
}

.par {
  display: inline-block;
  font-family: "duffy-script", sans-serif;
  font-weight: 400;
  font-style: normal;
  font-size: 24px;
  width: 233px;
  background: rgba(255, 0, 0, 0.2);
  letter-spacing: 0.01px;
}
<div class="container">
        <p class="par">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis tnostivasi nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderinsidaring ListTile imaging simply using no soluting oft  liquipizing neveninesestions se atsenimporquonutlpositique csspectoonaltefitiumeirain suslightitliptle imperendusoccraftuntontruicedlia secenct alaborendobovereconsectatum rekind rest amdultepius smplaborcrostistmagneticnaidoessurancefromperentemorasperemetreotenffeceallypassandsinllay rotnanular as structsaefuttow.emorcismensonspsed ortntaluxiu rorspeagusibustlibeareaelfeca receamiprovoil.euinafecatuusqamebitsolumlytorustrafesmin alre nitsetninon.m.smiasonsum.auvefrovutr.i.e su enligaloectufaitiolsse.nofther cel boctarkinnicac.minnatsoex"`ucancel modfind piglauewewse"".vit sikerwe.engdil.•" abur les res.archtrthestnifcestarnancesetrisulselinterchangeoutingrod            
        </p>

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

How can you utilize CSS to automatically generate section numbers, specifically for multiple sections?

Is it possible to automatically generate section numbering in CSS only when there are multiple sections present? I discovered that using CSS, one can create automatic numbering for sections. body { counter-reset: section } h2 { counter-reset: sub-section ...

Merging backend code (Java and Python) into HTML for seamless integration

While I have a solid background in back-end coding languages like Java and Python, the task at hand requires integrating this code into a website. The backend code comprises various methods and classes to encrypt text messages using encryption techniques ...

execute a retrieval query on an html pop-up

I have recently created an HTML web resource that I am displaying when a ribbon button is clicked. Within this popup, there is a dropdown list that I intend to fill with records obtained through a fetchXml query. The issue I'm encountering is that de ...

Need to ensure that an AJAX form doesn't resubmit without the need for a page

Encountering a peculiar mystery issue here... I have created a button on a webpage that triggers a form submission. The form is enclosed within a DIV, which dynamically updates to display the modified data. (this is embedded in a smarty template) form: ...

Creating a fully responsive HTML page with a fullscreen image background

Seeking help from someone who can assist me. I have a challenge in creating a webpage with a background image that fills its <div>. Here is the code I used: <style type="text/css> .myclassdiv { background-image:url('IMAGEURL') ...

A handy hack for eluding XSS attacks

Recently, I found out that my html/php website is susceptible to XSS attacks. Is there a method to clean my data other than having to manually include `htmlspecialchars` for every variable sent to the webpage (there's a chance of missing some and stil ...

Position three paragraphs in the center of a div container

Is there a way to center 3 paragraphs in a div? I have separate divs for each paragraph and one main div that holds all three nested divs. div.first { font-family: 'Kanit', sans-serif; color: aliceblue; width: 30%; float: left; ...

Explanation: The information box does not appear when the mouse hovers over it

Welcome to the gallery showcasing a unique calendar design with tooltip functionality. This calendar features a special hover effect for New Year's Day on January 1st, displaying a tooltip text upon interaction. Feel free to explore the code below to ...

Adjust image size based on the size of the screen

I am facing an issue with two images that are created for a 1024 x 768 resolution but I need to use them in a higher resolution. The challenge is to align these two images so that the circle from the first image falls between the second image. Although I ...

Tips for effectively redirecting multiple links on a website

Can anyone advise me on how to redirect certain HTML pages to corresponding PHP pages? For instance, if a user lands on www.example.com/sample.html from another website, I want them to automatically be redirected to www.example.com/sample.php without seei ...

How can I trigger a function or automate code execution in Angular?

I have some code within a function that is crucial for initializing other variables. The issue I am facing is that this function does not execute unless it is called through another tag in the HTML. Is there a method to automatically initialize this func ...

Unlocking JSON object with AngularJS

I have saved JSON data in a separate file named Countries.Json located in a folder called ListofCountries within the View directory. Now, I am trying to display this data on button click using AngularJS. However, I am facing difficulties in passing the J ...

Exploring the benefits of utilizing Scoped CSS for individual components within Next.js version 13

Switching from a Vue.js background to starting with Next.js, I want to scope my CSS for each component such as Navbar instead of using it inside Globas.css. Is there a way to achieve this? I am also utilizing the Tailwind CSS library. I attempted creatin ...

Embeddable javascript code can be enhanced by incorporating references into the header

I have developed a basic calculator application using HTML, JavaScript, JQuery, and CSS. My intention is to allow others to embed this calculator app on their own web pages by utilizing a file named generate.js. Within this file, there are several documen ...

Can CSS be utilized to consistently display text in a uniform manner?

Currently developing a unique Qur'an app for Muslims, standing out from the already existing ones in the market. There are two common types of Qur'an apps available: one that replicates the exact look of a physical copy, page by page, using imag ...

One effective way to redirect after a PUT request and display a one-time message

Here's what I'm aiming for in terms of desired behaviour: A user navigates to a password change web page. The user completes the form and it is sent via PUT request to our REST server. Upon successful completion, the user is redirected to their ...

How to Populate Radio Buttons in HTML with Data from a MySQL Database

I am seeking assistance with a PHP and MySQL project since I am new to these technologies. Any help would be greatly appreciated! I have created a second table that contains inventory information. This table includes two columns: Manufacturer and Item. O ...

html issue with the footer

Just starting out with HTML and encountering some difficulties with adding a footer. The main issue is that when I add the footer, the 'form' element gets stretched all the way down until it reaches the footer - you can see an example of this her ...

Is there a way to extract the text that is displayed when I hover over a specific element?

When I hover over a product on the e-commerce webpage (), the color name is displayed. I was able to determine the new line in the HTML code that appears when hovering, but I'm unsure how to extract the text ('NAVY'). <div class="ui ...

Identifying Oversized Files on Safari Mobile: A Guide to Detecting Ignored Large Files in

Mobile browsers such as Safari have a tendency to ignore large files when passed in through the <input type="file">. For example, testing with a 10mb image file results in no trigger of any events - no change, no error, nothing. The user action is si ...