science and technology Bulletproof HTML5 `<details>` fallback using jQuery By mathiasbynens.be Published On :: Sun, 25 Apr 2010 15:39:49 +0200 The HTML5 element is currently not natively supported in any browser natively supported in Chrome 12 and up. This makes it a little hard to guess how exactly this new element will behave, but reading the spec gives us a pretty good idea. While we wait for browsers to implement it, how about we create a fallback/polyfill for browsers who don’t understand (yet)? Full Article
science and technology Using Showdown/PageDown with and without jQuery By mathiasbynens.be Published On :: Sun, 02 May 2010 23:03:31 +0200 Showdown (also known as PageDown) is a JavaScript parser for Markdown-formatted text. It’s used on this site to generate a formatted preview of your comment as you type it. Showdown is library-agnostic, but fortunately, using it with jQuery isn’t much of a problem. Full Article
science and technology The HTML5 `document.head` DOM tree accessor By mathiasbynens.be Published On :: Tue, 04 May 2010 21:02:07 +0200 One of the lesser known HTML5 JavaScript goodies is the document.head DOM tree accessor, which is a more efficient (and easier to type) alternative to document.getElementsByTagName('head')[0]. Native support for document.head is very easy to detect… Full Article
science and technology The three levels of HTML5 usage By mathiasbynens.be Published On :: Sun, 06 Jun 2010 11:45:27 +0200 I was asked to give an introductory talk on HTML5 for the latest Adobe User Group Belgium Web SIG Event. The presentation I ended up with is entitled “HTML5: It goes to ELEVEN” and can be viewed on Slideshare. In this article, I’ll try to write down some of the things I talked about. Full Article
science and technology How to enable Safari Reader on your site? By mathiasbynens.be Published On :: Thu, 10 Jun 2010 10:03:25 +0200 Yesterday, Mike Taylor raised a very interesting question on Twitter: “Anybody know what Safari 5 requires for a page to be Reader-ifiable?” Full Article
science and technology Thoughts on Safari Reader’s generated HTML By mathiasbynens.be Published On :: Sun, 13 Jun 2010 17:30:50 +0200 Every time you click that shiny little Reader button, Safari generates an HTML document and displays it as an overlay to the original document. Let’s have a look at the HTML and CSS used in this process, and find out how we can mess with it. Full Article
science and technology The XML serialization of HTML5, aka ‘XHTML5’ By mathiasbynens.be Published On :: Thu, 17 Jun 2010 10:24:25 +0200 A while ago, I was wondering how exactly one triggers HTML5’s XML mode — let’s call it XHTML5 from now on. You know, just out of curiosity. I’ll always prefer HTML over XHTML because it’s much less verbose and I like to keep things simple. Full Article
science and technology The `id` attribute got more `class`y in HTML5 By mathiasbynens.be Published On :: Sun, 11 Jul 2010 17:38:38 +0200 One of the more subtle yet awesome changes that HTML5 brings, applies to the id attribute. I already tweeted about this a few months ago, but I think this is interesting enough to write about in more than 140 characters. Full Article
science and technology CSS character escape sequences By mathiasbynens.be Published On :: Mon, 12 Jul 2010 11:57:08 +0200 When writing CSS for markup with weird class or id attribute values, you need to consider some rules. For example, you can’t just use ## { color: #f00; } to target the element with id="#". Instead, you’ll have to escape the weird characters (in this case, the second #). Doing so will cancel the meaning of special CSS characters and allows you to refer to characters you cannot easily type out, like crazy Unicode symbols. Full Article
science and technology Using `setTimeout` to speed up `window.onload` By mathiasbynens.be Published On :: Tue, 14 Sep 2010 12:08:56 +0200 A few days ago, Martín Borthiry contacted me with a question. He had been using the optimized asynchronous Google Analytics snippet for a while, and noticed an additional speed gain when wrapping it inside a setTimeout() with a delay of 0 milliseconds. His tests made it pretty clear that this technique was indeed slightly faster, but Martín had no clue why. Full Article
science and technology How to create simple Mac apps from shell scripts By mathiasbynens.be Published On :: Fri, 12 Nov 2010 12:51:46 +0100 Thomas Aylott has come up with a clever script that allows you to easily create Mac apps from shell scripts. Here’s how it works. Full Article
science and technology Using CSS without HTML By mathiasbynens.be Published On :: Tue, 14 Dec 2010 15:13:38 +0100 The following article was published on CSS-Tricks as a guest post. Full Article
science and technology Bulletproof JavaScript benchmarks By mathiasbynens.be Published On :: Thu, 23 Dec 2010 11:15:24 +0100 The following article, written by John-David Dalton and yours truly, was published as part of the Performance Calendar series in 2010. Full Article
science and technology Completing Dropbox’s Dropquest 2011 in 60 seconds By mathiasbynens.be Published On :: Sun, 16 Jan 2011 17:13:31 +0100 Dropbox organized a scavenger hunt named Dropquest the other day. The first 81 people to complete all steps won some nice prizes, but everyone participating in the quest can get 1 GB of extra Dropbox storage space. Full Article
science and technology AirPlay video support in iOS Safari — a bookmarklet By mathiasbynens.be Published On :: Thu, 03 Feb 2011 11:23:40 +0100 As you may have heard, the upcoming iOS 4.3 will support AirPlay streaming in Mobile Safari. Previously video streaming was only available in Apple-controlled iOS applications like the YouTube and iPod/Video apps, but the new iOS 4.3 beta opens up AirPlay support to both third party App Store applications, as well as embedded web videos using either the Quicktime plugin () or the element. Full Article
science and technology Everything you always wanted to know about touch icons By mathiasbynens.be Published On :: Wed, 02 Mar 2011 08:09:06 +0100 “Touch icons” are the favicons of mobile devices and tablets. Adding them to your web page is relatively easy, but it gets more complicated as you target different devices and firmware versions. Let’s dive in! Full Article
science and technology Using the `oninput` event handler with `onkeyup`/`onkeydown` as its fallback By mathiasbynens.be Published On :: Wed, 11 May 2011 09:31:52 +0200 HTML5 standardizes the oninput event handler, which should be used to detect user input in JavaScript. Sure, you could use onkeydown or onkeyup instead, but those were never really designed for this particular use case, and it shows. Full Article
science and technology In defense of CSS hacks — introducing “safe CSS hacks” By mathiasbynens.be Published On :: Thu, 19 May 2011 13:54:00 +0200 I am writing this article because I noticed there’s a lot of misunderstanding on the subject of CSS hacks. How do you target Internet Explorer in your CSS? Do you use CSS hacks, conditional stylesheets or something else? Full Article
science and technology Unquoted attribute values in HTML and CSS/JS selectors By mathiasbynens.be Published On :: Mon, 13 Jun 2011 10:22:53 +0200 This is one of those posts I wrote just to be able to link back to it later. I see a lot of questions on the subject, and even though I don’t mind explaining the same thing over and over again, it’s probably easier to just write it down once. Full Article
science and technology The end-tag open (ETAGO) delimiter By mathiasbynens.be Published On :: Mon, 27 Jun 2011 10:45:14 +0200 According to HTML4, the first occurrence of the character sequence (ETAGO or end-tag open delimiter) is treated as terminating the end of the containing element’s content. This has since been changed in the HTML5 spec. What do browsers implement? How can we make sure the code we write doesn’t break because of this? Full Article
science and technology How I detect and use `localStorage`: a simple JavaScript pattern By mathiasbynens.be Published On :: Fri, 29 Jul 2011 15:09:40 +0200 By now, everyone knows how to detect and use localStorage. However, I’ve been using a seemingly unconventional (but slightly more efficient) technique to do so. Since I haven’t seen it documented anywhere else, here goes! Full Article
science and technology HTML element + attribute notation By mathiasbynens.be Published On :: Thu, 04 Aug 2011 15:09:09 +0200 Recently, a popular new addition was made to the HTML spec: anchors may now have a download attribute. That’s not what this post is about though — instead, I’d like to go over some of the different notations people used to refer to this new element + attribute combo in tweets and blog posts. Full Article
science and technology JavaScript `foo.prototype.bar` notation By mathiasbynens.be Published On :: Fri, 12 Aug 2011 10:56:54 +0200 As a follow-up to the post documenting a few popular HTML element + attribute notations, here’s a similar one about JavaScript. Full Article
science and technology Ambiguous ampersands By mathiasbynens.be Published On :: Wed, 23 Nov 2011 12:22:30 +0100 In this post, we’ll take a closer look at what happens if there’s an unencoded ampersand that’s not part of a character reference in your HTML code. Is it valid? Is it invalid? And what do “ambiguous ampersands” have to do with all this? Full Article
science and technology The smallest possible valid (X)HTML documents By mathiasbynens.be Published On :: Thu, 15 Dec 2011 13:35:06 +0100 I thought it would be fun to document the smallest possible valid HTML documents for each version, so here goes :) Full Article
science and technology JavaScript character escape sequences By mathiasbynens.be Published On :: Wed, 21 Dec 2011 15:24:30 +0100 Having recently written about character references in HTML, I figured it would be interesting to look into JavaScript character escapes as well. Full Article
science and technology JavaScript’s internal character encoding: UCS-2 or UTF-16? By mathiasbynens.be Published On :: Fri, 20 Jan 2012 22:18:54 +0100 Does JavaScript use UCS-2 or UTF-16 encoding? Since I couldn’t find a definitive answer to this question anywhere, I decided to look into it. The answer depends on what you’re referring to: the JavaScript engine, or JavaScript at the language level. Full Article
science and technology Valid JavaScript variable names in ES5 By mathiasbynens.be Published On :: Tue, 21 Feb 2012 15:19:15 +0100 Did you know var π = Math.PI; is syntactically valid JavaScript? I thought this was pretty cool, so I decided to look into which Unicode glyphs are allowed in JavaScript variable names, or identifiers as the ECMAScript specification calls them. Full Article
science and technology Unquoted property names / object keys in JavaScript By mathiasbynens.be Published On :: Mon, 05 Mar 2012 21:17:54 +0100 Fun fact: var foo = { H̹̙̦̮͉̩̗̗ͧ̇̏̊̾Eͨ͆͒̆ͮ̃͏̷̮̣̫̤̣Cͯ̂͐͏̨̛͔̦̟͈̻O̜͎͍͙͚̬̝̣̽ͮ͐͗̀ͤ̍̀͢M̴̡̲̭͍͇̼̟̯̦̉̒͠Ḛ̛̙̞̪̗ͥͤͩ̾͑̔͐ͅṮ̴̷̷̗̼͍̿̿̓̽͐H̙̙̔̄͜: 42 }; is valid JavaScript. It may not be immediately obvious, but the real surprise here is that the Cthulhu-esque property name is not surrounded by quotes. Intrigued by this, and having written about the similar topic of JavaScript identifiers before, I decided to look into valid property names in JavaScript. When do they need to be quoted? When can the quotes be omitted? And in which cases can dot notation be used instead of bracket notation to get or set a property based on its name? Full Article
science and technology Unquoted font family names in CSS By mathiasbynens.be Published On :: Tue, 03 Apr 2012 17:38:34 +0200 Are the quotes in font-family: 'Comic Sans MS' required, or not? If you thought the answer was yes, you may want to read on. Full Article
science and technology How to speedrun Dropbox’s Dropquest 2012 By mathiasbynens.be Published On :: Mon, 14 May 2012 16:21:29 +0200 Are you a Dropbox user? By completing this year’s Dropquest, you can get 1 GB of extra Dropbox storage space, for free. Here’s how to do that as fast as possible. Full Article
science and technology How to support full Unicode in MySQL databases By mathiasbynens.be Published On :: Mon, 30 Jul 2012 15:16:16 +0200 Are you using MySQL’s utf8 charset in your databases? In this write-up I’ll explain why you should switch to utf8mb4 instead, and how to do it. Full Article
science and technology Reserved keywords in JavaScript By mathiasbynens.be Published On :: Wed, 12 Jun 2013 19:46:35 +0200 Looking for a list of all reserved words in JavaScript? You’ve come to the right place. I recently needed such a list myself, but ended up comparing the reserved keywords in all ECMAScript versions as well. The result is listed below, for future reference. Full Article
science and technology Loading JSON-formatted data with Ajax and `xhr.responseType='json'` By mathiasbynens.be Published On :: Wed, 24 Jul 2013 23:14:15 +0200 This post explains a hidden gem in the XMLHttpRequest standard that simplifies fetching and parsing JSON data through Ajax. Full Article
science and technology Hiding JSON-formatted data in the DOM with CSP enabled By mathiasbynens.be Published On :: Tue, 27 Aug 2013 16:32:01 +0200 If Content Security Policy is enabled for protection against cross-site scripting attacks (i.e. the unsafe-inline option is not set), the use of inline