Disabled vs Hidden UI Elements
You'll learn when to visually disable a UI element versus hiding it completely when users lack authorization.
The Core Decision
When a user doesn't have permission to perform an action, you face a UX choice: should you disable the button/link (show it grayed out) or hide it entirely (remove it from the DOM)?
Both approaches are valid, but serve different purposes:
Disabling: Show But Don't Allow
Use disabled attributes or CSS when you want users to know the feature exists but understand they can't use it right now. This is like seeing a locked door with a sign — you know what's behind it, just not accessible yet.
<button
disabled={!hasPermission('edit_posts')}
className={!hasPermission('edit_posts') ? 'opacity-50 cursor-not-allowed' : ''}
>
Edit Post
</button>
Best for:
- Features users might gain access to (e.g., "Upgrade to Premium")
- Actions temporarily unavailable (e.g., "Save" while data loads)
- Educational UI — showing what's possible at higher permission levels
Hiding: Remove Completely
Use conditional rendering to completely hide elements when users should never see certain options. This is like a door that doesn't exist for you — cleaner, less cognitive load.
{hasPermission('delete_users') && (
<button onClick={handleDelete}>
Delete User
</button>
)}
Best for:
- Admin-only features regular users shouldn't know about
- Sensitive operations (financial, security-related)
- Cleaner UI when the feature isn't relevant to the user's role
Key Takeaway: Disable elements when discovery and awareness matter; hide them when simplicity and security take priority. Consider your users' mental model and whether knowing about restricted features helps or confuses them.