Course contentsShow
← React
Lesson 98 of 2,3963. JSX FundamentalsFree lesson

Boolean Attributes: checked, disabled, readOnly

How boolean attributes work in JSX, when you can omit the value, and why readOnly replaces readonly.

What You'll Learn

You'll learn how JSX handles boolean attributes like checked, disabled, and readOnly — and why some HTML boolean attributes get renamed in React.

Boolean Attributes in JSX

In HTML, boolean attributes are "true" when present and "false" when absent. You write <input disabled> to disable an input — no value needed.

JSX follows the same principle, but with JavaScript rules:

// These are equivalent — both disable the button
<button disabled={true}>Click me</button>
<button disabled>Click me</button>

// To enable it, you must explicitly set false or omit the attribute
<button disabled={false}>Click me</button>
<button>Click me</button>

When to omit the value: If a boolean attribute is always true, you can write just disabled instead of disabled={true}. It's shorter and reads like HTML.

When you need the value: If the boolean comes from a variable or expression, use curly braces:

const isFormValid = false;
<button disabled={!isFormValid}>Submit</button>

The readOnly Special Case

In HTML, the attribute is readonly (lowercase). But JSX uses camelCase for multi-word attributes, so it becomes readOnly:

// Wrong - won't work correctly
<input readonly={true} />

// Correct - camelCase in JSX
<input readOnly={true} />
<input readOnly />

This mirrors the JavaScript DOM property element.readOnly, maintaining consistency with how JavaScript accesses these properties.

Common Boolean Attributes

  • checked — for checkboxes and radio buttons
  • disabled — prevents interaction
  • readOnly — allows focus but prevents editing

Key Takeaway: Boolean attributes in JSX can omit ={true} when always true, but readOnly uses camelCase (not readonly) to match JavaScript's DOM property naming convention.