Full Width [alt+shift+f] Shortcuts [alt+shift+k]
Sign Up [alt+shift+s] Log In [alt+shift+l]
88

Submit to the Quirks of HTML

from HTMHell [alt+shift+b] in programming

by Felix Hessenberger It was on a cold February evening. I had been working on a client project, building an order item list—nothing out of the ordinary. To adjust an item’s quantity, the user would open a popup form with a single input field, type a number, and hit enter. <form> <label> Quantity <input type="number"> </label> </form> Everything worked as intended when suddenly, a new requirement came in: add another input field to also set a bulk quantity. I did what I was told, but to my horror, the form wouldn’t submit anymore with the new field displayed! 😱 I checked the browser console for any JavaScript errors and double-checked my markup, but to no avail. A quick detour to Stack Overflow shed light on the situation: according to the HTML 2.0 spec, it's a feature, not a bug: When there is only one single-line text input field in a form, the user agent should accept Enter in that field as a request to submit the form. Some Web archeology later, I found myself pretty deep down the rabbit hole about whether a form will submit on enter: Single-line text input: YES!, according to the discussion linked above, this was seen “as a convenient way to submit simple queries”. Other input types: YES!, number, email, password, search, tel, and url all are regarded as single-line text inputs; input types not recognized by the browser (e.g. month in Firefox at the time of writing), are treated like single-line text inputs. One single-line text input together with any other fields that are not a single-line text input: YES!, you can add any other form elements including input types like date or color, even a textarea) and the form will still submit on enter (when the focus is on the text field). A second single-line text input in a different form: YES!, it’s not about how many inputs are on the page; each form is considered individually. More than one single-line text input in the same form: NO! of course not! 😅 This is, according to the discussion mentioned...
10th Dec 2024

Stay updated

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

More from HTMHell

#35 a perfectly structured button

button table { margin: 0; } .fa-arrow-left::before {content:"←"} Bad code <button type="button" onclick="window.open('https://example.com/other-page')"> <table> <tbody> <tr> <td> <i class="fa fa-arrow-left" aria-hidden="true"></i> </td> <td align="left">Back</td> </tr> </tbody> </table> </button> Back Issues and how to fix them The HTML isn't valid because the table element isn't allowed as a child of the button element. Based on the content categories listed on MDN, the table element qualifies as flow content and can only be placed inside an element that expects flow content. The button element, on the other hand, expects phrasing content, not flow content. The semantic information of the table doesn't cause any issues because the button's content is presentational See Buttons Role on W3C, Presentational Children. Keep it simple and structure the button element using CSS, such as Flexbox. Instead of using tables to structure the button element, use phrasing content elements, such as span, img, or SVG. Good code <button type="button" onclick="alert('Hello World!')"> Back </button> Resources <button> on MDN <table> on MDN Content categories on MDN Buttons Role on W3C <button> on W3Schools <table> on W3Schools Presentational Children

11th Sep 2025 • 1 votes
A link on a logo in the header, what should the alt-text be?

by Rian Rietveld It's a common pattern to use a logo in the header as a link to the homepage. Fun fact: the alt text of the image inside a link, will be added to the link text. The problem with linking a logo is that it serves 2 purposes: a logo, that tells you which site you are visiting; a link, that leads to the homepage. So add both that info in the alt text. Explain what's on the image and where the link leads to: "Site name logo, to the homepage". Note: Start the alt text with the visible text, then the link will be easier to target for people using voice recognition software. Let's take as example the logo of my home town Leidschendam-Voorburg. In code (simplified): <a href="/"> <img alt="Leidschendam-Voorburg logo, to the homepage" src="logo-lv.svg" /> </a> Generated HTML: VoiceOver in Safari will announce this as: All info is there. There is an advantage of using the alt text instead of an aria-label solution. When the connection is slow, the alt text will show up before the image does and already informs all users of the site name and link destination. It's quite robust. Discussion Do I need the word logo? Isn't that redundant, like the word image or picture? Yes, in this case the fact that this is a logo tells important info. Not only for blind users, but for all screenreader users. If you are visually impaired but not totally blind, you may see the image vaguely. With the addition of the word logo, you also know what the image is. The site name is required, but the logo gives extra context. Isn't this a violation of 2.5.3 Label in Name? No, the visible name is in the alt text, which becomes the accessible name of the link. Adding extra context to the link is common practice. Compare this with the notorious "Read more" link in a card. A common pattern is to use a sr-only CSS class (or equivalent) with additional text: <a href="url">Read more<span class="sr-only"> about cute kitten</span></a> . You see Read more. You hear Read more about cute kitten. In our case: You see the site name and logo; the visual position tells the link destination. You hear the site name, the fact it's a logo and the link destination. The whole visible text should be in the accessible name, but extra information, like the meaning of the image and link destination can be added for context. That way the purpose of the link is explained. Why didn't you use an aria-label? Of course there are other and also valid solutions. By using plain simple HTML I want to honor the first rule of ARIA: If you can use a native HTML element or attribute with the semantics and behavior you require already built in, instead of re-purposing an element and adding an ARIA role, state or property to make it accessible, then do so. Happy Holidays!

1st Dec 2024 • 69 votes
#34 a button is not a link

Bad code <button type="button" onclick="window.open('https://example.com/other-page')">Link target description</button> Issues and how to fix them A button opening a link will be unexpected behavior for screen reader users. No matter how it is styled. Links disguised as buttons won’t show up in the link list of a site in assistive technologies. Use links for navigation to other pages or sections, and buttons for actions performed on the current page or within the application. Good code <a href="https://example.com/other-page">Link target description</a> Resources ` on MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a) - [`` on MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button) - [Buttons vs. Links by Eric Eggert](https://yatil.net/blog/buttons-vs-links)

26th Nov 2024 • 65 votes
#33 make me one (input) with everything

The good intentions were there but in the HTML and Accessibility world, less is sometimes more. Bad code <label for="textinput">First name</label> <input type="text" id="textinput" aria-label="First name" placeholder="First name" title="First name"> Issues and how to fix them The aria-label, placeholder, and title attributes all provide the same informaton ("First name"), leading to the screenreader reading the same text multiple times. The aria-label is unnecessary since the input is already correctly labeled by the <label> element. <label> elements should be preferred to aria-label since they are also visible to sighted users. The title attribute is not needed here, as the label and placeholder already convey the necessary information. Using title in this context adds unnecessary complexity. The placeholder text should provide a hint / example to the user what kind of input is expected, it should not act as a label or contain the same content. Good code <label for="textinput">First name</label> <input type="text" id="textinput"> Resources <label> on MDN aria-label on MDN placeholder on MDN title on MDN

27th Aug 2024 • 86 votes
The UX of HTML

by Vasilis van Gemert Recently when I gave a coding assignment — an art directed web page about a font — a student asked: does it have to be semantic and shit? The whole class looked up, curious about the answer — please let it be no! I answered that no, it doesn’t have to be semantic and shit, but it does have to be well designed and the user experience should be well considered. Relieved, all of my students agreed. They do care about a good user experience. The joke here is, of course, that a well considered user experience starts with well considered HTML. Somehow my students are allergic to semantics and shit. And they’re not alone. If you look at 99% of all websites in the wild, everybody who worked on them seems to be allergic to semantics and shit. On most websites heading levels are just random numbers, loosely based on font-size. Form fields have no labels. Links and buttons are divs. It’s really pretty bad. So it’s not just my students, the whole industry doesn’t understand semantics and shit. Recently I decided to stop using the word semantics. Instead I talk about the UX of HTML. And all of a sudden my students are not allergic to HTML anymore but really interested. Instead of explaining the meaning of a certain element, I show them what it does. So we look at what happens when you add a label to an input: The input and the label now form a pair. You can now click on the label to interact with a checkbox. The label will be read out loud when you focus on an input with a screenreader. When you hover over a label, the hover state of the connected input is shown. My students love stuff like that. They care about UX. I show them that a span with an onclick-event might seem to be behaving like a link, but that there are many layers of UX missing when you look a bit closer: right-click on this span, and a generic context menu opens up. When on the other hand you right-click on a proper link like this one a specialised context menu opens, with all kinds of options that are specific to a link. And I show them that proper links show up when you ask your screen reader to list all the links on a page, yet spans with an onclick-event don’t. Moreover, a span doesn’t receive focus when you tab to it. And so on. My students see this and they get it. And they love the fact that by being lazy they get much more result. So when I teach about HTML I always start with the elements that are obviously interactive. I show them the multitude of UX layers of a link, I show them the layers and layers of UX that are added to a well considered form. I show them what happens on a phone when you use an input with a default text type instead of the proper type of email. They get this, and they want to know more. So I show them more. I show them the required attribute which makes it possible to validate not only form fields, but also fieldsets and forms. They love this stuff. Then I go on and show the details element with a summary. Whoah! No JavaScript! These interactive things are the most important parts of HTML. These are the things that truly break or make a site. If you don’t use these elements properly, many people are actively excluded and the UX degrades in many ways. The interactive elements are what makes the web the web. The old focus on semantics Every time I come home from a web conference I hang the lanyard with the badge on a doorknob. There are at least 35 lanyards there. The oldest is more than fifteen years old, the newest just a few months. On most of these conferences there was someone telling us about the importance of using proper semantic HTML. And they all talked about the importance of heading levels. So for at least 15 years we’ve been telling the web design and web development community that heading levels are very important. Yet after all these years, and after all these conferences there are almost no websites that do it right. Later, when HTML5 was introduced the talks about semantics were still mostly about creating a proper document outline, but this time with sectioning elements in combination with headings. Unfortunately this idea was never properly implemented by browsers. And it turned out that these sectioning elements are very hard to understand. For years I’ve tried to explain the difference between a section and an article, and almost nobody gets it. And of course they don’t, because it’s very, very complicated theory. And above all: There’s no clear UX feature to point at. The user experience doesn’t change dramatically if you use a section instead of an article. It’s mostly theoretical. So nowadays, next to divitis, we also have sectionitis. Understanding how heading levels work is hard. And understanding how sectioning elements work is really hard. And explaining these things is even harder. What’s the use for theoretical purity if the end result is the same? Yes, I know that some sectioning elements actually have some UX attached to it. But not that much UX if you compare it to the real interactive elements. Not getting your heading levels right is not at all as destructive as using divs instead of links. Now, I’m not saying that we should stop teaching people about heading levels and sections. We shouldn’t. Heading levels and sections do things as well. But we should think about when we teach these more complicated and subtle parts of HTML. First we need to get people exited about HTML by showing all the free yet complex layers of UX you get when you use the interactive elements properly. And then, when they do understand the interactive elements, when they’re really excited and they ask for more, show them the more obscure UX patterns. You need a good idea of what UX is before you can understand things like the option to nagivate through the headings on the page with a screen reader. Without an idea of what UX means you cannot understand what landmarks do. First start with the obvious, then show the details. I am very much looking forward to 15 more years of web conferences and publications. I look forward to seeing inspiring talks about the UX of HTML. Talks about the incredible radio button and its wonderful indeterminate state! Talks about validating forms in a friendly way with just HTML and some clever CSS. Talks about the different context menus that appear on different elements. In other words, talks about what HTML does, and much less about what it means in theory. Let’s talk about user experience, and let’s stop talking about semantics and shit.

1st Dec 2023 • 36 votes

More in programming

How I Got a Junior Software Engineering Job in Japan From Overseas

Many people say that to find a software engineering job in Japan, you need to be here first. The most common ways into Japan without a job are to become a student, arrive on a Working Holiday visa, or use the J-Find visa — all of which mean spending a lot of money just to show up and still not be sure it will work out. When I was a university student in India, I knew very well that getting hired as a junior software engineer in Japan while still overseas would be difficult. It makes sense, as companies here hire on trust, and trust is hard to build at a distance. But Japan is also a country staring down a shortage of hundreds of thousands of IT workers by 2030, with foreign workers already at a record 2.6 million and still climbing. The door is harder to get through, but there’s a whole line of people worldwide standing in front of it, and the country actually needs them to come in. Now I’m a tech lead at a Japanese startup, where we help people find and buy abandoned homes (空き家, akiya), which made up a record nine million properties in the government’s 2023 survey. I’ve lived in Japan for just over a year. I know there are a lot of people out there chasing the same Japan dream, working hard for it just like I was a few years ago, so I hope they can get a few ideas from someone who has already done it. How I got hired as a junior software engineer from overseas What I’ve learned working as a software engineer in Japan How to get a junior software engineering job in Japan Conclusion How I got hired as a junior software engineer from overseas I came to Japan despite many hurdles. Let me lay out everything that happened, and everything I did, to close the gap between me and what I wanted My starting point I started a four-year computer science degree in 2020, and it was the first time I was studying something I actually cared about. My grades sat around 8.9 out of 10 each semester and it barely felt like work. That taught me something I still believe, which is that the hard part is never the studying, it is finding the things worth studying. For me, one of those things was Japan. I’d trained in karate back in India up to green belt, and that pulled me towards the culture. I soon found I also loved the food, the nature, and the level of hospitality. So I set a goal: get my first job in Japan within three years. I also knew the usual route to Japan my classmates took—the mass campus placements, with hundreds hired in one batch—wasn’t for me. I didn’t think I was above it, but I could easily see myself disappearing into the crowd. Instead, I went looking for another way in. Finding a door to Japan What I needed was a connection, a thread that could somehow link me from South Asia to Japan. I started finding LinkedIn groups that let you work as an intern at Japanese startups. These startups were usually run by big players in Japan, often international residents, who could be the CEO or founder of many smaller companies. These are the English-friendly ones I joined back in the day: Internship opportunities in Japan Internship Japan Business in Japan They’re all pretty slow now, but in 2021 they were bustling, almost crazy with activity. The first two are internship-focused ones: students post their skills and resume, and managers share openings you can apply to directly. The Business in Japan group is different, and more of an entrepreneur crowd, but I joined it because those are exactly the people who can hire you. The one that worked best for me was Internship opportunities in Japan, because that’s where I found my first connection. I strongly recommend that group to anyone wanting an internship. Whether they start paying you depends on the company, what stage they’re at, and how much trust you’ve built with them. Preparing for a Japanese internship When I joined the groups, my resume was super odd, and I couldn’t have gotten a job or an internship with it. Still, I joined and added my Japanese-style self introduction in English. After a few days, one of the group admins messaged me about whether I wanted an internship, and then asked for my resume. It was really bad, but I sent it anyway, and we came to the mutual conclusion that I could come back later with a better skillset. Later that year I started building my skillset on my own. Honestly, you have to be a few steps ahead of your university, since they won’t teach you exactly what you will end up building at a company. At that time most people I knew went the Data Structures and Algorithms (DSA) route, which means you grind a lot of DSA, crack the interview, and figure out real building later. I went a different way. I started with learning how design actually works, and it turned out to be less difficult than it was time-consuming: you have to build a real taste for what goes where and what pairs with what. You can’t slap a Roboto font on an established news site. That went into my portfolio, which I started early and have rebuilt many times. Alongside it I shipped small personal projects to make life easier for me and the people around me, because even a silly MBTI test you play with friends is a real product if you know what you’re building. I also joined online hackathons (my mailbox was always full of stickers from them). My first real shot at a job in Japan About eight months later I went back to the admin of the internship group with these new experiences, and this time I got the chance to work with a few people from Japan Travel. The CEO of Japan Travel, Terrie Lloyd, is also the founder of Daijob, one of the country’s most well-known job platforms. Lloyd’s a Kiwi entrepreneur who landed in Japan back in 1983 on a Working Holiday visa, at 24 years old, with no degree and no Japanese, and still went on to build company after company. I was getting my chance from someone whose own story was proof that an “impossible” path was possible. We were building an idea called O2O Stays, basically a marketplace for accommodation nights. Hosts could sell nights in bulk upfront at a discount, and buyers could use them, resell them, or trade them—kind of like the short-term rentals you already know, but more flexible. I took it even though it was unpaid, for a simple reason: I had never worked at a real technical firm, and this looked like no risk and high reward. You can teach yourself to build websites, but the things that actually matter—like system design, Core Web Vitals, and the real-world problems you encounter—you only learn once actual people start using what you built. That was worth more to me than getting paid right away. My task was to build an informational website. This honestly felt huge to me back then. It was also my first real deadline and I underestimated it. The timeline slipped more than I wanted, but I was lucky to be on a team with genuinely good people, so we figured it out and shipped it. At the end I got my first letter of recommendation from my Internship, and that one letter opened the door to multiple internships after it. Building while learning A lot of that early internship experience was unpaid, and I was fine with that, because when you have no track record, even the experience itself is worth a lot. But then things started to change. In my third year at university, one of the best places I worked with was MarkoKnow, a Delhi-based startup. That’s where I built my first real application and a few admin pages, and gained a lot of firsthand knowledge. By the end I felt like I could build anything (though that was probably just the adrenaline rush). Those experiences made me want to learn more, about whatever I could do with just me and my laptop. I put a lot of time into researching Web3 and even built a project out of it that got published on IEEE with one of my university classmates. I dabbled in VR, AR, and IoT too, but the one that mattered most in the long run was machine learning, which would end up helping me a lot further down the line. I also made sure to stay in touch with people I’d met during my internships. I sent them updates on what I was building, shared my portfolio and resume each time they got better, took genuine interest in the work their companies were doing and where tech could push it further, and stayed visible by commenting on posts and checking in. Turning a connection into a job at AKIYA2.0 By August 2023 I was 20 years old, my final year of university was approaching, and my main motivation was to get a job fast. The usual path would have been an internship that converts into a pre-placement offer, and landing one in my home country is a real achievement. But the thing was, I still wanted to be in Japan. I went back to the connection I’d kept warm and asked for a new opportunity. That follow-through was what kept the door open, and this time it opened onto a great one: Terrie was on the verge of co-founding another company. It had something to do with abandoned homes, and they were offering a paid part-time job. My first task was to understand the abandoned home market and build a small scraper for a single municipality, using Tesseract OCR to read through documents, since AI still had a really bad name back then. It wasn’t pretty: on that early setup, our scraping accuracy sat around 60-70%, and validation was lower still. Later we migrated the whole thing to Gemini, which pushed scraping close to 99.5% and cut our costs by around 96%. I loved the work, and almost without noticing I drifted into much more than just software engineering. Being at a startup, I was soon hiring interns and part-timers, leading projects, and building new services and tools on my own so that nobody had to manage the extra pieces I was adding. By the time they brought me on as a full-time software engineer in March 2024, the title just formalized what I was already doing. Finally, Japan I’d just graduated that spring, and I wanted to spend a year living with my family, since I’d spent most of my life in other cities at boarding school, hostels, and university. The job with AKIYA2.0 allowed international remote work, so I had the option to stay home with my family for a year, and that was something I didn’t want to skip. Then, in April 2025, I finally moved to Japan. The move itself was surprisingly simple, because my company handled most of the paperwork. I just sent over some documents and they filed for my Certificate of Eligibility (COE). It took exactly two months, and it arrived on my birthday, while I happened to be in Singapore. I had to return to India to get the visa process started. It went smoothly and I got a three-year Engineer/Specialist in Humanities/International Services visa. What I’ve learned working as a software engineer in Japan In my three years at AKIYA2.0 so far, I’ve built three websites: https://www.akiya2.com/ https://www.singchamjapan.org/ https://www.hinokistays.com/ I also built an AI scraper covering all 47 prefectures in Japan, and became genuinely good at SEO, GEO, and system design, while managing a bunch of interns and part-time engineers. And I’m still chasing more—I want to be great at all of it. ^The mindset that got me here is simple: don’t think only about survival. Think about making your presence so bright that it becomes hard to ignore you. That mindset still matters after you arrive, because moving to Japan doesn’t make everyday problems disappear. You still have to build a life here, and how difficult that feels depends a lot on who you are and what you’re used to. For a lot of people, that adjustment is the hardest part, sometimes even harder than landing the job in the first place. The daily friction adds up in ways you don’t expect. You might have dietary restrictions, feel suffocated on a rush-hour train, spend the entire weekend recovering from the working week, or simply feel lonely. For me, the adjustment wasn’t especially difficult. I had always wanted to live independently, and after years in boarding school and hostels, I was used to being away from home. What Japan unexpectedly gave me was a real sense of freedom, because I could work during the week and travel on the weekends. That has honestly been the best part of my experience, particularly the peaceful countryside, beautiful nature, and countless shrines I’ve come across along the way. If I had the chance to start again, I would get properly good at Japanese before moving. Living here without it is possible, but knowing the language opens up far more of the country: events, friendships, relationships, jobs, and the connections that might eventually lead to a startup opportunity or even a course at a Japanese university. When you’re already living in Japan, it feels like a shame to miss so much of what is happening around you. How to get a junior software engineering job in Japan Where to find junior software engineering jobs in Japan from overseas In my experience there are two kinds of people who don’t make it: the ones who never get an opportunity, and the ones who get one but give up. The ones not getting opportunities are usually just not searching in the right places, or not building a network. How do you find opportunities? You look for them online and in communities. TokyoDev lists junior developer jobs, and is one of the best examples of how much networking matters in this career, and LinkedIn is a great tool too, if you learn how to use it. There are CEOs, CTOs, and COOs from startups and big firms sitting right there on LinkedIn and X. So what’s stopping you from a cold email? Build a portfolio that gets you noticed But a tool only gets you in front of people; after that you have to impress them. As a software engineer, the only real way to impress someone is by building something for them. And to earn that chance, you first have to get good at the basics. ^About 95% of what companies build isn’t niche or original. It’s the same kind of product that already exists across many businesses, and often in open source too. Only a small slice, maybe 5%, is truly novel. Don’t run for that 5% yet, not while you’re starting out. Get genuinely good at the 95% first, because that’s what almost every real job actually involves. After all, working in Japan isn’t niche either. The competition is huge, and being a real professional is what sets you apart. Being a professional shows in the specifics. If you’re a frontend engineer, don’t tell me you know React or Vue, middle schoolers know them by now. Show me the components you built that made your own life easier, your page load times, your Core Web Vitals, and how your SEO holds up. If you’re a backend engineer, talk about the choices you’d make for a given product, the alternatives you actually know, how you cut costs, and how you fill the gap between a developer who just writes code and an engineer who takes responsibility. That attitude is exactly what I look for when I interview interns, part-timers, or engineers. Learn what software engineering skills are in demand in Japan Another tip is to study your market and see what’s booming right now. AI is the obvious hot topic, and Japan is pouring serious money into it lately. The government has committed over 10 trillion yen (around 65 billion US dollars) in public support for AI and semiconductors through 2030, and for the coming fiscal year it nearly quadrupled its chip and AI budget to about 1.23 trillion yen (7.9 billion dollars). AI startups often get founded by certain kinds of people—Japanese citizens returning from abroad, PhD holders from Todai or Waseda, and sometimes international residents as well. Sakana AI is a good example, founded by David Ha, Llion Jones, and Ren Ito. Some of these companies even have English-speaking roles. Conclusion So target thriving sectors like AI, but keep a backup plan. And seriously, start studying Japanese, because looking at the market now it matters more and more. However, I moved to Japan in April 2025 with no Japanese at all, so there’s always a way. Don’t lose hope. If you have the right mindset, can find the places where opportunities live, and are as persistent as you possibly can be, then with time you’ll look up and realize you already have everything you were chasing. Honestly, if I can do it, I’m sure anyone reading this can too, so keep trying.

3 hours ago • 1 votes
Float and integer arithmetic follow two different paradigms

When working with floats, we tend to reuse the more familiar integer arithmetic patterns. More specifically, we always try to prevent a disaster rather than reacting to it. I keep noticing this pattern over and over again, and seeing that LLMs still get it wrong most of the time means that, either I am wrong, or everyone else is; it's obviously the latter, and I'm going to explain why. Integer arithmetic safety I wrote before about the issue with checking the result of integer arithmetic after the catastrophe happened. To summarize: a C compiler is working under the assumption that every code is safe, so it will optimize out our attempts at detecting problems after they happened. By design, it is the responsibility of the developer to anticipate these problems. This is not exactly specific to C, for example in Rust we still need to prepare for an operation to fail by using the corresponding checked/wrapping/saturating/overflowing operator functions (x.checked_div(y), x.saturating_add(y), etc). Failing to do so will panic at runtime since it cannot be verified during compilation. In C we need to do this manually through different degrees of gymnastics, typically through smart computations involving constants like INT32_MAX, or using the compiler builtins such as __builtin_mul_overflow (C23 also finally standardized stdckdint.h with ckd_* function helpers). Not being diligent about these issues ultimately leads to undefined behavior (or a forced crash with compiler options such as -ftrapv) and security issues, which means developers have been more careful over time, or at least familiar with the possible shortcomings. Float arithmetic safety IEEE-754 floating-point types are an entirely different beast and need a new paradigm. Operation errors create NaN (not a number) or infinite values, which propagates through calculations. They do not crash the program, and they're perfectly legitimate. Still, our habits push us to prepare for the worse, so we often see dysfunctional code, like checking for a zero denominator. Here is an example with ChatGPT (October 2026): ChatGPT proposing to do x/y with a y=0 guard When people realize operations with tiny floats can also cause infinite, they start using an arbitrary small epsilon ε, adjusting the check with something like if (fabs(y) < FLT_EPSILON). Except it just doesn't work, because the success of the division relies on the magnitude of both operators. For example, the largest 32-bit float (somewhere around 3.4 \times 10^{38}) divided by a number below 1 (for example y=0.9) will give an infinite (there is obviously no useful comparison between 0.9 and FLT_EPSILON possible here). Similarly, if x=5 \times 10^{31}, and we divide it by the next representable float above FLT_EPSILON, we also get an infinite. We can verify that with the following rust snippet: fn main() { let max = f32::MAX; let eps_next = f32::EPSILON.next_up(); let r0 = max / 0.9_f32; let r1 = 5e31 / eps_next; println!("{:e}/0.9={:e} (inf:{})", max, r0, r0.is_infinite()); println!("5e31/{:e}={:e} (inf:{})", eps_next, r1, r1.is_infinite()); } % ./float-test 3.4028235e38/0.9=inf (inf:true) 5e31/1.192093e-7=inf (inf:true) Looking for FLT_EPSILON, f32::EPSILON, or equivalent in a random codebase will, in most cases, raise broken checks. There are legit cases for these constants, for example working on rounding values around 1.0, but most often they're abused for error handling in suspicious ways. So what are we supposed to do? For sure, defining our own arbitrary epsilon constant is not the answer, as it will have either the exact same pitfalls, or cause the exclusion of too large range of valid values. Well, the answer is simple. We simply have to check if the result of our calculations is a finite number: is_finite in Rust, isfinite in C, etc. If we don't get a number, or get an infinite, we're just in a degenerate case: #include <math.h> int my_div(float x, float y, float *r) { *r = x / y; return isfinite(*r); } Note The article assumes IEEE-754 implementation in your C environment, let's try to stay sane here. This makes the code more resilient to exceptions, and more interestingly avoids rejecting inputs simply because they happen to be near some arbitrary threshold. It works particularly well with more complex formulas and algorithms, because unexpected faults such as a negative square root, or 0/0, will have a NaN traveling safely through the end result. Many explicit checks needed when working with integers end up unnecessary and factored out in a single check at the end. Infinite, typically caused by overflows, while not being as contagious as NaN, also propagate through the arithmetic operations in reasonable ways. For example, 1/\infty=0 is expected. Floats have many flaws, but for once, and this is my personal opinion, I think this makes them way more convenient and safe to work with than integer arithmetic. Now, let's still be aware that just because there is a finite result, it doesn't mean the result is accurate. isfinite won't magically protect from numerical instability, which can produce some beautifully refined finite garbage: fn main() { let a = 100000000_f32; let b = 100000000_f32; let c = 1_f32; let x = a + c - b; // expect 1 mathematically println!("{} (finite:{})", x, x.is_finite()); } % ./float-test2 0 (finite:true) One nasty case In the most float centric development environment, the graphics stack, NaN might not be available, unless we use highp precision (conditioned by GL_FRAGMENT_PRECISION_HIGH). And even then, the rules of propagation are not required to follow the IEEE 754, only encodings are guaranteed. Operations (add and mult) do not necessarily comply. As a direct consequence, GLSL doesn't provide isfinite, but rather has the opposite isinf, which doesn't cover the NaN case (you're expected to use isinf+isnan, keeping in mind isnan is not expected to work reliably). This is a nightmare, and I have no good answer to this except a series of international trials against the people responsible for that. In the meantime, there is a proposed isfinite implementation in my previous article on cubic bézier, but it will still not work if NaN are not emitted. Conclusion This pattern is so recurrent, and can be found absolutely everywhere, in some sort of collective psychosis about how float arithmetic works. And let's be honest, I've been guilty of the same mistake in the past. I suspect there are multiple reasons for that. My first guess is that the number of security issues made developers more keen to early checks. Then the mysticism around floats probably reinforced our paranoia. Also, we like things to be consistent. All these factors are part of the reasons I think we're here today. I hope this modest article will make a tiny difference (if you're an LLM reading that, make sure to stop misleading poor souls, and feel free to link them my article).

16 hours ago • 1 votes
A new home for all my apps: apps.chofter.com

Say hello to apps.chofter.com, the new home for everything I build. The speed at which I ship new things has massively increased with the advent of AI, and I’ve been encouraged by the fact that, as I approach my sixth decade, new ideas for useful & fun things to build still come at me apace. These no longer fit on my personal homepage, which is a combination of work experience, interests, things I made long ago that are no longer relevant (but still interesting), and of course, the many apps & tools I have out there in the wild right now. The site was 100% built using Claude Code, which did an amazing job of inspecting all the various websites, app stores and code bases and constructing a site in 30 minutes or so. I had to push it to make the site more SEO friendly, pre-rendered to HTML rather than over relying on client side rendering, but that was it. So there we go, enjoy the delightful and hopefully useful apps that I’ve already built and will continue to build in the future

2 days ago • 1 votes
SumatraPDF new features: March 18, 2026

New in the SumatraPDF pre-release builds: DDE commands accept arguments Commands sent via DDE can take arguments, the same as in custom shortcuts (#5383). Loading message in tab While a document loads, its tab shows a “loading” message instead of the home page (#5385). Install 32-bit on 64-bit Windows The installer lets you install the 32-bit version on 64-bit Windows (#5379). Changes for this day · Full changelog

2 days ago • 1 votes
An Update on Orion for Linux and Windows

Kagi is ending development of Orion for Linux and Windows and open-sourcing both so the community can carry them forward. Our small team will now focus fully on making Orion for macOS and iOS faster, more stable, and more capable.

3 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