1 hour ago · 10 min read2030 words · Tech · hide

I've been playing with CSS mixins recently, and I'm super excited about what this new CSS construct will bring to the way we write CSS. I think the CSS we'll write when CSS mixins are available will look very different from the CSS we write today. What's a mixin? In its simplest form, a mixin is a named piece of CSS code that you define once and can reuse elsewhere in a style sheet. In that sense, it's very similar to a custom property (also known as a CSS variable) or a CSS function. The big difference is what mixins can hold: A custom property holds a single value (or part of a value). A CSS function is similar: it can only be used as part of a CSS property value. A mixin, however, holds any number of declarations, including nested rules. So, instead of just returning the value red, a mixin can return background: red; color: white; border-radius: 2px; all at once. Why now? My team at Microsoft is implementing mixins in the Chromium open source project. They've covered a lot of…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town