Skip to main content

Sometimes when it’s false, it’s true

Posted in Development and HTML

A short posts on boolean attributes in HTML. What’s a boolean attribute? Something that can only be true or false false; things like:

They either are reversed, checked or disabled, or they’re not.

The funny thing about booleans in HTML is that they’re true if they exist. So even if the value is false (like required="false") it’s still true!

In fact, it doesn’t matter what value a boolean attribute is given: required="true", required="false", and required="banana" do the same thing.

You can go one step further an remove the value altogether, leaving just required, and that’s what I do. It differentiates a boolean nicely from other attributes like class and src.

Subscribe

I send a newsletter on the last day of every month, containing:

  • A roundup of the articles I’ve posted
  • A hot pick from my archives
  • Some interesting posts from around the web

I don’t collect any data on when, where or if people open the emails I send them. Your email will only be used to send you newsletters and will never be passed on. You can unsubscribe at any time.

More posts

Here are a couple more posts for you to enjoy. If that’s not enough, have a look at the full list.

  1. Booleans in ARIA

    HTML booleans are bit quirky but, as if just to complicate things, booleans in ARIA work slightly differently. It’s worth knowing how and why.

  2. XHTML syntax is still worth using

    A few weeks ago I read an article on CSS-Tricks about writing HTML the HTML way, not the XHTML way, and it has been bothering me a bit.