Full Width [alt+shift+f] Shortcuts [alt+shift+k]
Sign Up [alt+shift+s] Log In [alt+shift+l]
SplitDuck.com Use A/B testing to increase revenue
1

Hidden until found

from HTMHell Advent Calendar 2025 [alt+shift+b] in programming

by Roy Keur The hidden attribute has always been an odd way of hiding elements. It allows a developer to hide elements with HTML and this by itself has been a source of debate since it was introduced. A couple of years ago, this attribute was already discussed over here, but what has been predicted as the future has turned into a reality today. hidden is no longer truly hidden since the introduction of until-found as a new value for this attribute. From the beginning, we were promised in the specs that when you add hidden to an element, you make it hidden from all presentations. Since until-found has been implemented, I feel a bit lied to, as this new value seems to break that promise. I would say it is a good idea to revisit this nefarious attribute to see what has actually changed and what we can learn from it. Hiding important content with display:none (and hidden) has shortcomings Let's start with a brief reminder of why hidden="until-found" was introduced in the first place. The very basics are that hidden applies display: none to an element, as defined in the user agent stylesheet, but using display: none can lead to some shortcomings. Some years ago, various news media found it a good idea to cut stories on their websites in two parts by inserting a 'Continue reading' button at some point in their articles, especially on mobile devices. Below is a simplified snippet of how this concept is applied today: <p> You could either take a boat or fly to Lorem Ipsum Island, but the flights are all cancelled due to a lack of available aircraft, so you will have to take a boat. </p> <button type="button" aria-expanded="false"> Continue reading this article </button> <p data-readmore-hidden="1" style="display: none;"> You can either use a catamaran, which takes one hour and fifteen minutes with departure time at 11:30, or take the slower cruise ship which takes two hours and 30 minutes, with departure time at 9:30. </p> Note: the original code in this snippet...
3 hours ago

Stay updated

Get a weekly newsletter with the top 5 articles worth reading every week.

More from HTMHell Advent Calendar 2025

HTML esoterica - en-GB vs en_GB

by Terence Eden Here's a fun little historic mystery for HTML nerds. Most websites report the language they're written in using the lang attribute. <html lang="en-GB"> But on the <meta> element, it's common to see: <meta content="en_GB" property="og:locale"> Why does that use an underscore rather than a hyphen? What is a language anyway? Here's how the lang attribute works: 3.2.6.2 The lang and xml:lang attributes OK, so what is a valid BCP 47 language tag? Language tags permit only the characters A-Z, a-z, 0-9, and HYPHEN-MINUS (%x2D). 6. Character Set Consideration For example, en is English. en-GB is British English and en-CA is Canadian English. The two parts are separated by a hyphen. Where else is language specificity useful? That's not the only way language tags can appear in HTML. If you want your web page to show a little preview when you share it - perhaps on social media or a messaging app - you can use Open Graph Protocol. og:locale - The locale these tags are marked up in. Of the format language_TERRITORY. Default is en_US. Optional Metadata - Open Graph Protocol (Hurrah for American hegemony!) Here's the example it gives: <meta property="og:description" content="Sean Connery found fame and fortune as the suave, sophisticated British agent, James Bond." /> <meta property="og:locale" content="en_GB" /> That says the locale of the tags, not the page, is British English. So you could have a page in the Japanese language but OGP tags written in Cherokee. Now I have two questions. Why doesn't this use the lang attribute? Why does this use an underscore rather than a hyphen? For example, this is valid HTML: <meta property="og:site_name" content="Les Misérables" lang="fr"> <meta property="og:description" content="A book by Victor Hugo." lang="en-GB"> That says the site's name is in French but the description is in English. That will parse perfectly. What's going on with OGP? As I've ranted before, development of Open Graph Protocol is dead. Facebook, who run it, recently reopened their GitHub repo - but only to add a proposed tag. Their discussion forum is full of spam. There's no history of the development, no rationale for why things were chosen, just Facebook's edict. The nearest I can find to an explanation is this Pull Request which references an obsolete page of Facebook's locales. Despite Facebook removing the page, it lives on! Take a look at the documentation for embedded posts. It says: When you load the SDK, change the value of js.src to use your locale. Replace en_US with your locale, e.g., fr_FR for French (France): 'https://connect.facebook.net/fr_FR/sdk.js Which, I think, leads us to the answer. An answer which was hidden in the question the whole time. A language is not the same as a locale. A language only tells you about the language. A locale, by contrast, tells you about the user's preferences. A locale comprises the language, territory, and code set combination used to identify a set of language conventions. These conventions include information on collation, case conversion, and character classification, the language of message catalogs, date-and-time representation, the monetary symbol, and numeric representation. Understanding locale - IBM Do you know if 10/08/12 is the 10th of August or the 8th of October? Is 5.99 describing the cost in a mark, a yen, a buck, or a pound? If you know the locale, you do. So a locale can be more useful than just a plain language. OK, but why does it use an underscore? As far as I can tell, POSIX standardised it in ISO/IEC 15897. It built on a number of older standards. And, for whatever reason, they used the underscore. My final question before I let you get on with your lives - is a locale useful? OGP defines several data types. The date is always in ISO8601 format, so no need for a locale there. Bools, strings, and enums don't benefit from a locale in any way that I can see. What about the new payment property? A locale might be useful there to show currency. Except the specification has: payment:currency - string - The currency code ISO 4217 of the payment. The only thing I can see a locale being useful for is numbers. The thousand separator and decimal mark are different depending on the locale. So it might be useful to display "5,99" or "10.000,32" depending on the page's intended audience. If Facebook were still interested in maintaining OGP, I think that asking them to deprecate og:locale and replace it with lang on specific meta elements would be sensible. So there you have it. A language is not the same as a locale, and an underscore is not the same as a hyphen, and a Facebook recommendation is not the same as a living standard. Right, that's enough yak shaving. I'm sure I was meant to be doing something important… Oh! Yes! Welcome to HTMHell 🎅

3 days ago • 1 votes
Top layer troubles: popover vs. dialog

by Stephanie Eckles Have you ever tried to set z-index: 9999 to solve element layering issues? If so, you’ve been fighting a fundamental CSS concept of stacking contexts. The stacking context defines the order things are placed in the third dimension, or the “z” axis. Think of the z-axis as layers of DOM elements between the root of the stacking context within the viewport, and you, the user, looking through the browser viewport. An element can only be re-layered within the same stacking context. While z-index is the tool to do it, the failure happens due to a change in stacking contexts. This can happen in a few ways, such as a fixed or sticky positioned element, or combining position absolute or relative along with a z-index, among others as listed on MDN. A modern web feature is the “top layer,” which is guaranteed to be the top-most layer above any other stacking context. It spans the entire viewport, although elements existing in the top layer may have smaller visible dimensions. Promoting an element to the top layer breaks it free of any stacking context it may otherwise exist within. Although the top layer directly addresses a CSS-related issue, there is currently no property available to promote an element to the top layer. Instead, certain elements and conditions gain access to the top layer, including native dialogs via showModal() and elements designated as popovers. The Popover API is a newly available HTML feature that enables you to create declarative non-modal overlay elements. The ability to escape any stacking context by gaining top layer access is usually a desirable feature of choosing the Popover API. However, there’s a sneaky potential conflict to be aware of before hastily opting for this native upgrade. Setting the scene Picture this, the web, 2025: your web app includes a notification service that displays via “toast” messages. You know, those pop-up messages that usually appear in a corner or other location with a lower likelihood of obstructing any other UI. Usually these toast notifications are for real-time alerts of things like a successful save, or errors such as a failed form submit. They are sometimes time limited, or include a dismissal mechanism like a close button. Sometimes they include an additional action, such as to “Retry” for re-submitting a failed workflow. Since your app is hip to the times, you’ve recently decided to upgrade the toasts to use the Popover API. This enables you to place the toast component anywhere in the app structure, and not have to hack around stacking context issues. After all, toasts absolutely must appear over everything else, so the top layer access afforded via popovers makes sense! You ship the enhancement, proud of your work. Later that week, you get an urgent bug report. Not just any bug report, but an accessibility violation. Dialog vs. popover Because your app is hip, you also had previously upgraded to native HTML dialogs. That was an incredible upgrade because you got to reduce a JavaScript dependency in favor of a native web feature. That’s another reason you were excited to enhance your toasts to use popover as well. So, what was the bug? A keyboard user was in a workflow that involved a dialog. While the dialog was open, a background process caused a toast notification to trigger. The notification was for an error, and required user interaction. The bug occurred when the keyboard user tried to tab into the toast, which they were able to visually see above the dialog backdrop. Unfortunately, their focus never successfully entered the toast, and instead seemed to skip over it, jumping unexpectedly to the browser UI instead. You can experience this error yourself in this CodePen, where by using the tab key, you too will never be able to access the toast. You can also try it out using a screen reader, and notice that the virtual cursor is also unable to get into the toast. See the Pen conflicting by Stephanie Eckles (@5t3ph) on CodePen. If you are able to click on the popover, you may think it’s at least working with that method. But shortly we’ll learn that thing aren’t always as they seem. Why the toast popover is unreachable While top layer allows beating out standard stacking contexts, items that exist within the top layer are still affected by layering order. The most recently added top layer item appears over previous top layer items. This is why the toast was visually appearing over the dialog’s backdrop. So if the popover is visually available, why is it unreachable via keyboard or a screen reader’s virtual cursor? The reason has to do with the popover competing with a modal dialog. When the native HTML dialog is launched via showModal(), the page outside of the dialog becomes inert. The state of inert is a necessary accessibility behavior, which results in isolating the dialog contents, and prevents both tab and virtual cursor access to the background page. The bug is due to the toast popover being part of the background page’s DOM. This means it has been made inert due to being outside of the DOM boundary of the dialog. But, due to top layer order, since it was created after the dialog was opened, it is confusingly sitting visually over the dialog. If you thought clicking the popover was working, it’s in fact not, even though the popover does dismiss. What is really happening is that you are triggering the light dismiss behavior of the popover. This means it is closing because you are technically clicking outside of it’s boundaries, since the dialog is capturing the click instead. So, while the popover was dismissed, the “Retry” button was not actually clicked, meaning any associated event listener was not triggered. Even if you created an automated test to check your alert functionality specifically when a dialog was open, the automated test may have had a false positive because it triggered a programmatic click on the toast button. That pseudo click was falsely getting around the issue created from the dialog causing the page to be inert. Regaining popover access The solve is two-fold: move the popover physically inside the DOM of the dialog ensure use of popover="manual" to prevent clicks inside the dialog from prematurely triggering light dismiss on the popover Once we’ve done both of those things, the popover is now both visually available and fully interactive via any method. See the Pen conflicting by Stephanie Eckles (@5t3ph) on CodePen. Learnings and additional considerations What we’ve learned is that you will need to work out a mechanism to launch popovers from within dialogs if your website or app has the possibility of both displaying at once, and they have independent timelines. Alternatively, you could opt to suppress background page popovers until the dialog closes. This may not be ideal if notifications require timely interaction, or if the dialog contents have the potential to trigger a toast. Another issue you may need to handle for, besides visibility and interactivity, is if the popover needs to outlive the dialog. As in, it needs to remain open - perhaps to keep waiting for the user to take action - once the dialog is closed. While I am a huge proponent of using native platform features, and I think popover in particular is an incredible feature, sometimes conflict points can’t be entirely avoided. In fact, you may have already had to contend with a similar conflict against the inert behavior of a modal dialog. So, this article may mostly be a warning to not entirely rip out your previous custom popover architecture if you have this potential issue of displaying background popovers and modal dialogs simultaneously. If this is an issue that currently, or may in the future affect your work, keep an eye on this HTML issue where solutions are being discussed.

1st Dec 2025 • 1 votes

More in programming

Jenni joins Digital Science: a four-year retrospective

In October 2026 Jenni was acquired by Digital Science. A personal reflection on four years as founding designer, from $4k to $730k in monthly revenue.

yesterday • 1 votes
counting large numbers of events in small floating point registers

In 1978, the ACM published an algorithm by Robert Morris for counting large numbers of events in small registers. It uses one byte to keep track of the approximate logarithm of the count, and randomly increments the logarithm with a probability that scales with the value of the count. You can tune the range and precision of the counter by adjusting the base of the logarithm. Morris suggests pre-calculating a table of probabilities so that no difficult calculations are needed at runtime. Recently I learned from emsenn about a 2009 paper by Miklós Csűrös titled approximate counting with a floating-point counter. It changes Morris’s algorithm to use a binary log-linear counter instead of a pure logarithm. It reminded me of my hg64 log-linear histograms, so I thought it would be fun to implement, especially since the algorithm can be made shorter and faster. representing a counter We need to choose the number of bits to use for the exponent and mantissa of each approximate floating point counter. Typically the exponent will be 5 or 6 bits, corresponding to an unpacked exact counter of 32 or 64 bits. The mantissa will typically be the rest of an 8 or 16 bit integer (though languages such as Zig and C23 allow more adventurous integer sizes). I’ll call the approximate counter type usmol and the unpacked counter type ubig. #define EXPBITS 5 #define SIGBITS 3 typedef unsigned _BitInt(EXPBITS+SIGBITS) usmol; typedef uint32_t ubig; static_assert(sizeof(ubig) * 8 == 1 << EXPBITS, "ubig must match EXPBITS"); It’s straightforward to extract the exponent and mantissa from a usmol counter. Unpacking a usmol into a ubig is slightly tricky. Like hg64 and IEEE754, normal numbers (with a nonzero exponent) have an implicit leading bit, and denormal numbers (exponent is zero) do not. The effect is that small counts are represented exactly in a usmol (up to 2*MANTISSA, covering denormal numbers and exponent == 1), and larger counts are shifted by the exponent. (I don’t need the inverse conversion here, but it is used by hg64 to map a sample to a histogram bucket, truncating the value by shifting right.) #define MANTISSA (1 << SIGBITS) static inline ubig exponent(usmol approx) { return(ubig)(approx / MANTISSA); } static inline ubig mantissa(usmol approx) { return(ubig)(approx % MANTISSA); } static inline ubig unpack(usmol approx) { ubig e = exponent(approx) - 1; ubig m = mantissa(approx) | MANTISSA; return(approx < MANTISSA ? approx : m << e); } bumping a counter Because binary floating point uses logarithms in base 2, we need the probability of incrementing the counter to scale with 2^-e. Specifically, we want the probability of increasing the counter to be 100% when its exponent is 0 or 1, 50% when the exponent is 2, 25% when it is 3, etc. Csűrös does this by getting a random bit e times in a loop and incrementing the counter if they are all zero. A more efficient way to do this on a computer is to get a ubig word full of random bits and count the leading or trailing zeroes. There are a variety of bit scan functions that differ in how they number bits and what they do when the word is entirely zero. The POSIX ffs() family has the advantage of no undefined behaviour, but it weirdly counts from one. However this oddity turns out to match the way denormal numbers give our exponent an off-by-one bias. So for instance, when our exponent is 2 and we want a 50% probability, we want ffs() to return 2 or more. OK, that determines when to increment the mantissa given a particular exponent. But how does the exponent get incremented? Like Csűrös, we put the exponent immediately to the left of the mantissa; when the mantissa overflows, it rolls over to zero and the exponent ticks up. No special cases are needed. The resulting code is short: usmol bump(rng_t *rng, usmol approx) { ubig r = ubig_random(rng); ubig z = (ubig)ffsll((long long)r); ubig e = exponent(approx); return(approx + (z >= e)); } considerations Morris allows you to smoothly tune the allowable range and precision of a counter by adjusting the base of the logarithm. By contrast, Csűrös has very lumpy 2^2^n choice of ranges; that isn’t necessarily bad because it’s normal for programmers to have to choose between uint32_t and uint64_t. Morris uses a lookup table to determine the probability of incrementing, which is tolerable for an 8 bit counter, but it can get large for wider counters. Csűrös just uses a few instructions and bigger counters don’t need much more. So I don’t think either algorithm is clearly better than the other, except that Csűrös has the winning fun factor of bithacking a bespoke floating point format.

2 days ago • 1 votes
How to tokenmaxx correctly

Parallelize discovery and execution, but serialize judgement.

2 days ago • 1 votes
You really shouldn't vibe code a newsletter app

Sending email is easy. Making sure good emails land where they should is not.

2 days ago • 2 votes
📚 BoredReading

You seem to be enjoying this.

Join free to unlock everything.

Create free account

Already have an account? Sign in