Menu

Tailwind ~CSS Styling with utility classes~
📰

Tailwind ~CSS Styling with utility classes~

DEV Community: css·Ogasawara Kakeru·3 days ago
#pFDlLZKr
#devtocss#devto#dev#styles#inline
Reading 0:00
15s threshold

"Why not just use inline styles?"

Utility classes resemble inline styles because both apply styles directly to an element rather than through a named class. Utilities still have three advantages:

Design constraints: Inline styles require "magic numbers," while utilities draw values from a predefined design system, which keeps the UI consistent.

States (hover, focus, etc.): Inline styles can't target hover or focus, but variants such as hover:bg-purple-600 can.

Media queries: Inline styles can't use media queries, but responsive variants such as sm:flex-row can.

Key points of the page

The page explains how to build components by combining many single-purpose utility classes directly in your markup.

Benefits: Faster development, safer changes (edits affect only one element), easier maintenance, portable markup, and CSS that doesn't grow in proportion to the number of features.

Thinking in utilities:

Variants apply conditional styles ( hover: , sm: , dark: , etc.) and can be stacked.

Arbitrary values…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.