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

HTML esoterica - en-GB vs en_GB

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

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...
20 hours ago

Stay updated

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

More from HTMHell Advent Calendar 2026

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

NSRS georeferencing

The US is updating its primary spatial reference system, replacing NAD 83 with NATRF 2022 and other systems.

5 hours ago • 1 votes
Finish line

Max Verstappen wins the 2026 Mexico City Grand Prix.

20 hours ago • 1 votes
My Favourite Black Friday Deals

For many course creators, the Black Friday holiday period is when we offer the biggest discounts of the year, which means it’s a great time to pick up some of the web development courses you’ve had your eye on! This post is a quick round-up of my top 10 picks.

2 days ago • 1 votes
A Better UTF-8 Automaton

Without wasting your time, here it is: Any edge not shown goes to an error state. If you can start in ACC, follow the edges for each byte in your input and end up back in ACC, your string is valid UTF-8. Some C code implementing the above DFA is as follows. It highlights some of the neat features that our new automaton supports, namely quick branchless transitions as a shift-DFA, trivial parallel evaluation, and instant error recovery. #include <stddef.h> #include <stdint.h> enum { DFA_ACCEPT = 2, DFA_SYNC = 16 }; static const uint32_t DFA[256] = { [0x00 ... 0x7f] = 0xcae2bb8a, [0x80 ... 0x8f] = 0xaef05f22, [0x90 ... 0x9f] = 0xbff05f22, [0xa0 ... 0xbf] = 0xbf905f22, [0xc0 ... 0xc1] = 0xc6318cbb, [0xc2 ... 0xdf] = 0xcb8dc637, [0xe0] = 0xc6565dd9, [0xe1 ... 0xec] = 0xc8c7771d, [0xed] = 0xc63318cc, [0xee ... 0xef] = 0xc8c7771d, [0xf0] = 0xcbbaeeeb, [0xf1 ... 0xf3] = 0xc8c97725, [0xf4] = 0xc6546551, [0xf5 ... 0xff] = 0xc6318cbb, }; uint32_t step(uint32_t s, uint8_t b) { return DFA[b] >> (s & 31); } int is_error(uint32_t s) { return !((0x4459a285 >> (s & 31)) & 1); } int partial(uint32_t s) { return (0x92283845 >> ((s + 12) & 31)) & 3; } size_t utf8_valid_up_to(const uint8_t *buf, size_t len) { uint32_t s = DFA_ACCEPT, t; size_t i = 0; for (; i + 32 <= len; i += 32) { uint32_t s1 = s, s2 = DFA_SYNC; for (int j = 0; j < 18; j++) { s1 = step(s1, buf[i + j]); s2 = step(s2, buf[i + j + 14]); } if (is_error(s1) | is_error(s2)) break; s = s2; } for (; i < len && !is_error(t = step(s, buf[i])); i++) s = t; return i - partial(s); } Note that a proper UTF-8 validation routine should at the very least have hot paths for ASCII, this is just an example. And while the above definitely doesn’t beat simdutf, it runs only ~2.5x slower on my Apple M5 laptop when validating Chinese, which isn’t bad for ~30 lines of scalar code. Compared to Björn Höhrmann’s minimal C UTF-8 validator, the above runs 9 times faster in the same benchmark. State machine Our state machine isn’t minimal, but that’s on purpose. It has three nice properties: Like Per Vognsen’s shift-DFA, this state machine can be encoded so each transition is a byte lookup into an array of magic constants followed by a bit shift. Their original implementation packed the constants as uint64_ts, this one fits them in uint32_ts through the use of a SAT solver and overlapping the constants, reducing the lookup table from 2 → 1 KiB. Because we do not merge states which have consumed a different number of bytes of a partial codepoint, error recovery is trivial. In case of an error we can directly read off from the state machine how many bytes we consumed, go back that much, and insert a replacement character if desired. An extra SYNC state is added to the state machine, which absorbs continuation bytes. This makes it super easy to do parallel validation, allowing the shift-DFA to run almost twice as fast as previous shift-DFA UTF-8 validators due to instruction-level parallelism. The trick is to overlap the end of one chunk of bytes with the start of the next chunk by 4 bytes (since no valid codepoint can be > 4 bytes). The first parallel run will validate the overlap, and the second can synchronize on it. If there was an error in these four bytes the second DFA’s state will be nonsense, but the first will catch the error safely. Shift-DFA I would highly recommend reading Per Vognsen’s original shift-DFA exposition, but in short, if you have a finite automaton with a limited number of states and symbols, you can store a transition table. It seems natural to store per state what transition to take for each symbol: $$(\mathrm{State} \times \mathrm{Symbol}) \to \mathrm{State},$$ but if you have a very small number of states it is actually more efficient to store for each symbol how each state transitions: $$\mathrm{Symbol} \to (\mathrm{State} \to \mathrm{State}).$$ This is for two reasons: The memory lookups can all be done in parallel, off the critical dependency chain, as each lookup only depends on its symbol, not the previous state. All the information needed for a $\mathrm{State} \to \mathrm{State}$ function can be stored in one register (naive encoding is $n \cdot \lceil \log_2 n \rceil$ bits for $n$ states). If you choose your state indices cleverly, doing a state transition can even be a single operation after the lookup, e.g. for at most 32 states: state = table[symbol] >> (state % 32) On most hardware shift counts automatically wrap around, making the mod free, as long as it’s 32 or 64. I’m not clever enough, so a SAT solver was used to pack the shift-DFA transition table into uint32_t magic constants. It is somewhat surprising this fit at all, since we have thirteen states, meaning we need 4 bits to encode a transition target, and ${13 \times 4 = 52}$ bits to store it naively. Worse still, since we want to target uint32_t magic constants, our natural modulo is 32, meaning five bits define a state. Luckily we can overlap the bits of neighboring states, if the start of one matches the end of another. To make it fit I still had to be a bit creative: there isn’t a single error state. Instead, we have 32 possible states, of which 12 are valid and 20 are invalid. The only requirement on the invalid states is that they remain invalid on every transition. Luckily checking if a state is valid can still be done with just one shift into a bit vector. What follows is the Z3 code to find our magic DFA constants, it runs in ~15 minutes on my machine. from z3 import * STATES = 'ACC SYNC 1/2 1/3 2/3 1/4 2/4 3/4 E0 ED F0 F4'.split() CONT = {'SYNC': 'SYNC', '1/2': 'ACC', '1/3': '2/3', '2/3': 'ACC', '1/4': '2/4', '2/4': '3/4', '3/4': 'ACC'} CLASSES = { '00-7f': {'ACC': 'ACC', 'SYNC': 'ACC'}, '80-8f': {**CONT, 'ED': '2/3', 'F4': '2/4'}, '90-9f': {**CONT, 'ED': '2/3', 'F0': '2/4'}, 'a0-bf': {**CONT, 'E0': '2/3', 'F0': '2/4'}, 'c0-c1 f5-ff': {}, 'c2-df': {'ACC': '1/2', 'SYNC': '1/2'}, 'e0': {'ACC': 'E0', 'SYNC': 'E0'}, 'e1-ec ee-ef': {'ACC': '1/3', 'SYNC': '1/3'}, 'ed': {'ACC': 'ED', 'SYNC': 'ED'}, 'f0': {'ACC': 'F0', 'SYNC': 'F0'}, 'f1-f3': {'ACC': '1/4', 'SYNC': '1/4'}, 'f4': {'ACC': 'F4', 'SYNC': 'F4'}, } # The offset of valid state s, and the word of class c. off = {s: BitVec(s, 32) for s in STATES} word = {c: BitVec(c, 32) for c in CLASSES} valid = lambda x: Or([x == o for o in off.values()]) # Each state has a unique offset below 32. solver = Solver() solver.add(*[ULT(o, 32) for o in off.values()]) solver.add(Distinct(*off.values())) for c, trans in CLASSES.items(): step = lambda o: LShR(word[c], o) & 31 # State s should go to its target state or error. for s in STATES: if s in trans: solver.add(step(off[s]) == off[trans[s]]) else: solver.add(Not(valid(step(off[s])))) # Error states only transition to error states. for e in range(32): e = BitVecVal(e, 32) solver.add(Or(valid(e), Not(valid(step(e))))) solver.check() model = solver.model() for s in STATES: print(s, model[off[s]]) for c in CLASSES: print(c, f'{model[word[c]].as_long():08x}') Acknowledgements I’d like to thank Thom Chiovoloni for their discussions and their earlier work on packing the lookup tables using Z3, and Max Hollmann for bringing shift-DFA UTF-8 validation to my attention at RustWeek 2026 and exchanging further thoughts.

2 days ago • 1 votes
📚 BoredReading

You seem to be enjoying this.

Join free to unlock everything.

Create free account

Already have an account? Sign in