Best of CSS Tip — 2025
- 1
- 2
- 3
CSS Tip·52w
How to correctly use if() in CSS
CSS is introducing a new if() function for conditional styling, but there's a common pitfall when using calculations within conditions. The browser treats custom property values as strings unless they're registered with @property, which means calculations like calc(var(--n)/2) won't be evaluated. To fix this, you need to register the custom property with @property and specify its syntax and initial value. This registration is only required when calculations are involved - exact value matching works without registration.
- 4
- 5
- 6
CSS Tip·38w
The Fundamentals of CSS Alignment
A comprehensive guide to CSS alignment that explains the fundamental concepts behind alignment properties across different layout systems. Covers the two-level alignment theory (content and item levels), demonstrates how alignment works in Grid, Flexbox, and Block containers, and explains concepts like auto margins, safe alignment, and absolutely-positioned elements. Includes interactive demos and a quiz to test understanding.
- 7
- 8
- 9
- 10
CSS Tip·43w
Responsive infinite logo marquee
Modern CSS techniques enable creating responsive infinite logo marquees using the shape() function and new sibling-index()/sibling-count() functions. The approach works with any number of images, adapts to container width without magic numbers, and can be controlled through CSS variables. Currently limited to Chrome browser support, the technique requires equal-width items and works with any content type beyond just images.
- 11
CSS Tip·25w
The Hidden Selectors of The HTML Element
Explores alternative CSS selectors for targeting the HTML root element beyond the standard `html{}` and `:root{}`. Demonstrates lesser-known approaches including the nesting selector `&`, `:scope`, `:has(head)`, `:not(* *)`, and `:not(* > *)`. Explains how these selectors work by leveraging fallback behaviors and unique characteristics of the HTML element, such as being the only element without a parent or having head and body as children.