- From: Remco Haszing <notifications@github.com>
- Date: Fri, 19 Jun 2026 06:53:13 -0700
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/dom/issues/1472@github.com>
remcohaszing created an issue (whatwg/dom#1472)
### What problem are you trying to solve?
Usually, when text overflows in an HTML element, the text is wrapped. I need to calculate the positions where this happens.
For example, let’s say I have the following HTML:
```html
<!doctype html>
<html>
<body style="font-size: 4em;">
<p>This is a line with <span style="font-size: 2em;">some bigger text</span> and <span style="font-size: 0.5em;">some smaller text</span>.</p>
</body>
</html>
```
It might look like this:
<img width="500" height="804" alt="A browser window showing the text “This is a line with some bigger text and some smaller text.” wrapped over 5 lines." src="https://github.com/user-attachments/assets/309dc5e5-b429-4120-9f1a-94b4f5bafe13" />
In this case I’m interested in the numbers `[21, 26, 33, 47]`.
But it might also look like this:
<img width="811" height="720" alt="A browser window showing the text “This is a line with some bigger text and some smaller text.” wrapped over 3 lines." src="https://github.com/user-attachments/assets/4b91d16c-0906-479b-b0dd-b0bad92a873d" />
In this case I’m interested in the numbers `[26, 47]`.
### What solutions exist today?
For more details, you can see my question on StackOverflow: https://stackoverflow.com/questions/79939908/trouble-calculating-html-line-wrapping-positions-at-different-zoom-levels
The problem is that solutions today aren’t accurate. The precision of DOM rects depends on factors such as zoom level and font size. So instead of precise calculations, you need to rely on tresholds that might need to vary depending on certain hard to know conditions.
### How would you solve it?
I’m not sure. I imagine something like this?
```js
const element = document.getElementsByTagName('p')[0]
element.getWrappingColumns()
```
### Anything else?
Not sure. I’ll gladly give any more information if requested :)
--
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/1472
You are receiving this because you are subscribed to this thread.
Message ID: <whatwg/dom/issues/1472@github.com>
Received on Friday, 19 June 2026 13:53:17 UTC