When Visual Design Conflicts with Semantics
What you'll learn: How to handle situations where your visual design requirements don't match the semantic HTML structure you should use.
The Core Challenge
Sometimes designers create layouts where elements look like one thing but need to function as something else. For example, a navigation menu might be visually styled to look like tabs, or a button might need to appear as a link. When this happens, you face a dilemma: do you use the HTML element that matches the visuals or the one that matches the functionality?
Always choose semantic HTML first, then style it to match the design.
The Solution Pattern
Think of it like a costume: an actor might dress as a king, but they're still fundamentally an actor underneath. Similarly, a <button> can look like anything with CSS, but it remains functionally a button—which is what assistive technologies need to understand.
When styling alone isn't enough, ARIA fills the gap. For instance:
- A set of
<button>elements styled as tabs can userole="tab"andaria-selectedto communicate their tab-like behavior - A visually hidden heading (for design reasons) should stay in the DOM with semantic heading tags, not replaced with styled
<div>elements - A decorative icon that looks important might need
aria-hidden="true"so it doesn't confuse screen reader users
When to Use ARIA
Use ARIA properties to bridge the gap between what users see and what assistive technologies understand. This ensures both visual users and screen reader users get the complete, accurate picture of your interface—even when those two pictures need different technical approaches.
Key Takeaway: When design and semantics conflict, keep the semantic HTML structure and use CSS for styling plus ARIA attributes to clarify the enhanced behavior or state—never sacrifice semantic correctness for visual appearance.