Mixins and Includes
Create reusable style blocks with @mixin and include them anywhere with @include.
Mixins and Includes is a free CSS Academy lesson on CoddyKit. This is lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CSS Academy learning path, and your progress syncs across the web and the CoddyKit app. The CSS Academy course includes 4 lessons in total.
What is a Mixin?
A mixin in Sass is a reusable block of CSS declarations. Unlike a regular class, it can accept parameters, making it more flexible than copy-paste. Define with @mixin, use with @include.
Basic Mixin
A mixin without parameters is just a reusable block:
<div class="hero">Centered hero content</div>
Mixin with Arguments
Pass values to a mixin to customize its output:
<button class="btn-primary">Primary</button>
<button class="btn-danger">Danger</button>
Default Arguments
Set default values for mixin arguments so they are optional:
<div class="card">Card with default shadow</div>
<div class="modal">Modal with custom shadow</div>
Keyword Arguments
Pass mixin arguments by name for clarity:
<div class="tooltip">Tooltip</div>
@content — Mixin with Block
Mixins can accept a block of content using @content. The included block is injected where @content appears:
<a href="#" class="link">Hover or focus this link</a>
<a href="#" class="link-demo">Same link, hover state shown statically</a>
Responsive Mixin
A common mixin for media queries:
<div class="sidebar">Sidebar (280px wide on desktop ≥ 1024px)</div>
Typography Mixin
A text style mixin for consistent type scale:
<h2 class="heading">Heading text style</h2>
<p class="body">Body text style</p>
Mixin vs Function
Mixins output CSS declarations; functions return a value. Use a mixin when you want to output multiple CSS rules; use a function when you need a computed single value.
Avoiding Mixin Overuse
Too many mixins create abstract indirection that is hard to debug. Only create a mixin if a pattern is reused 3+ times. For one-off styles, just write the CSS directly.
Quick Check
What is the purpose of @content inside a Sass mixin definition?
Recap
Define mixins with @mixin and use them with @include. Mixins accept parameters with optional defaults. @content allows callers to inject CSS blocks into the mixin — enabling wrapper patterns like media query helpers. Create mixins only for patterns reused multiple times to avoid abstraction overhead.
Learn CSS with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 40
- Lessons
- 159
Frequently Asked Questions
Is the “Mixins and Includes” lesson free?
Yes — the full text of “Mixins and Includes” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CSS Academy course, upgrade to CoddyKit PRO. The CSS Academy course includes 4 lessons in total.
What will I learn in “Mixins and Includes”?
Create reusable style blocks with @mixin and include them anywhere with @include. You practise CSS Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start CSS Academy?
No prior experience is required. CSS Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.
How long does the “Mixins and Includes” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this CSS Academy lesson?
Yes. Every CSS Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Variables Nesting and Partials
- Mixins and Includes
- Extend and Placeholder Selectors
- Sass Functions and Control Flow