<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/building-a-better-button-in-css-cantina-oxq7s1nd4" -->

---
title: Building a Better Button in CSS — Cantina | daily.dev
description: A detailed case study walks through designing a scalable, maintainable button component system in CSS/Sass for a real educational app. It covers naming buttons...
canonical: https://daily.dev/posts/building-a-better-button-in-css-cantina-oxq7s1nd4
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Building a Better Button in CSS — Cantina | daily.dev
og:description: A detailed case study walks through designing a scalable, maintainable button component system in CSS/Sass for a real educational app. It covers naming buttons...
og:url: https://daily.dev/posts/building-a-better-button-in-css-cantina-oxq7s1nd4
og:image: https://api.daily.dev/og/posts/OXQ7S1ND4.png
og:image:alt: Building a Better Button in CSS — Cantina
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Building a Better Button in CSS — Cantina

**[Eric Bailey](https://daily.dev/sources/ericwbailey)** · 11 min read · 0 upvotes · 0 comments

## Summary

A detailed case study walks through designing a scalable, maintainable button component system in CSS/Sass for a real educational app. It covers naming buttons by intent rather than appearance (primary/secondary/tertiary, size, hollow vs solid), adding SVG icons with currentColor, handling background contrast via a 'context query' technique using Sass's ampersand selector, managing interactive states (:hover, :active, :focus, disabled, aria-busy), reordering elements with flexbox for accessibility-friendly tab order, and using a `:not()` selector trick to visually flag inaccessible non-semantic button markup. The piece emphasizes WCAG AA contrast compliance and semantic HTML throughout.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://cantina.co/building-a-better-button-in-css>

## Questions this post answers

### How should I name CSS classes for buttons that have multiple visual variants like size and color?

Name classes by intent rather than visual appearance, using a base class plus modifiers such as button--primary, button--large, and button--solid instead of describing colors or sizes literally. This keeps the naming meaningful even if the visual palette changes later, since a red button might later become green while its purpose as the primary action stays the same.

_daily.dev surfaces practical CSS architecture patterns for developers designing component naming systems._

### How can I style a button's background color differently depending on whether it sits on a light or dark parent background in CSS?

Use Sass's ampersand feature to write a selector that looks for a parent modifier class, such as background--dark, declared higher in the document source, then apply different background styling to the button as its child. This avoids needing JavaScript to toggle modifier classes and automatically respects nested contexts like a dark modal on a light page, though it requires careful namespacing to avoid style collisions.

_Developers wrestling with context-dependent theming in CSS can find deeper technique breakdowns on daily.dev._

### How do I visually flag buttons that were built with non-semantic markup instead of a proper button element?

Apply CSS's :not() selector to target elements that lack the semantic button styling classes but attempt to look like buttons, then style them with an obviously broken or jarring appearance so the improper implementation is immediately visible during development. This technique, sometimes called 'jerk mode', reinforces that authors use proper <button> or <input type="button"> markup for accessibility.

_daily.dev helps developers keep up with accessibility-focused CSS techniques like enforcing semantic markup._

## Similar posts on daily.dev

- [Building Better Buttons](https://daily.dev/posts/building-better-buttons-kfg2u6xfq) · Simple Thread · 68 upvotes · 5 comments
- [If you want to create a button from scratch, you must first create the universe](https://daily.dev/posts/if-you-want-to-create-a-button-from-scratch-you-must-first-create-the-universe-81uyduuo1) · Hacker News · 2 upvotes · 1 comments
- [Chris’ Corner: Click Something Do Something](https://daily.dev/posts/chris-corner-click-something-do-something-o3v7iteuf) · CodePen · 1 upvotes · 0 comments

---

Tags: [#css](https://daily.dev/tags/css), [#accessibility](https://daily.dev/tags/accessibility)

[View this post on daily.dev](https://daily.dev/posts/building-a-better-button-in-css-cantina-oxq7s1nd4)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Building a Better Button in CSS — Cantina","url":"https://daily.dev/posts/building-a-better-button-in-css-cantina-oxq7s1nd4","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/building-a-better-button-in-css-cantina-oxq7s1nd4"},"datePublished":"2026-09-20T07:43:42.161Z","dateModified":"2026-09-20T07:49:41.553Z","description":"A detailed case study walks through designing a scalable, maintainable button component system in CSS/Sass for a real educational app. It covers naming buttons...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7a2f7e5bd8b97e082dd128e22dc60f75?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7a2f7e5bd8b97e082dd128e22dc60f75?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Eric Bailey","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Eric Bailey","logo":"https://media.daily.dev/image/upload/s--r1vwe6z1--/f_auto,q_auto/v1789890198/logos/ericwbailey?_a=BAMAMicg0","url":"https://daily.dev/sources/ericwbailey"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/building-a-better-button-in-css-cantina-oxq7s1nd4","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"css,accessibility","timeRequired":"PT11M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Eric Bailey","item":"https://daily.dev/sources/ericwbailey"},{"@type":"ListItem","position":3,"name":"Building a Better Button in CSS — Cantina"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/building-a-better-button-in-css-cantina-oxq7s1nd4#faq","mainEntity":[{"@type":"Question","name":"How should I name CSS classes for buttons that have multiple visual variants like size and color?","acceptedAnswer":{"@type":"Answer","text":"Name classes by intent rather than visual appearance, using a base class plus modifiers such as button--primary, button--large, and button--solid instead of describing colors or sizes literally. This keeps the naming meaningful even if the visual palette changes later, since a red button might later become green while its purpose as the primary action stays the same. daily.dev surfaces practical CSS architecture patterns for developers designing component naming systems."}},{"@type":"Question","name":"How can I style a button's background color differently depending on whether it sits on a light or dark parent background in CSS?","acceptedAnswer":{"@type":"Answer","text":"Use Sass's ampersand feature to write a selector that looks for a parent modifier class, such as background--dark, declared higher in the document source, then apply different background styling to the button as its child. This avoids needing JavaScript to toggle modifier classes and automatically respects nested contexts like a dark modal on a light page, though it requires careful namespacing to avoid style collisions. Developers wrestling with context-dependent theming in CSS can find deeper technique breakdowns on daily.dev."}},{"@type":"Question","name":"How do I visually flag buttons that were built with non-semantic markup instead of a proper button element?","acceptedAnswer":{"@type":"Answer","text":"Apply CSS's :not() selector to target elements that lack the semantic button styling classes but attempt to look like buttons, then style them with an obviously broken or jarring appearance so the improper implementation is immediately visible during development. This technique, sometimes called 'jerk mode', reinforces that authors use proper \u003cbutton\u003e or \u003cinput type=\"button\"\u003e markup for accessibility. daily.dev helps developers keep up with accessibility-focused CSS techniques like enforcing semantic markup."}}]}
```

