--- title: Bulma Sass Mixins layout: docs theme: sass doc-tab: sass doc-subtab: mixins breadcrumb: - home - documentation - sass - sass-mixins ---

Throughout the codebase, Bulma uses Sass mixins to enhance and facilitate the CSS output. While these mixins are mainly used within the context of Bulma, they are of course available for you to re-use in your own projects.

{% include docs/elements/anchor.html name="Element Mixins" %}

These mixins create a visual HTML element.

{% include docs/elements/anchor-bis.html name="Arrow" %}

The arrow() mixin creates a down-facing arrow. The $color parameter defines the color of the arrow.

{% highlight sass %}.bulma-arrow-mixin { @include mixins.arrow(purple); }{% endhighlight %} {% capture arrow %} {% endcapture %} {% include docs/elements/snippet.html content=arrow %} {% include docs/elements/anchor-bis.html name="Burger" %}

The burger() mixin creates a 16x16px set of 3 horizontal bars grouped within square. The dimensions of this square are defined by the $dimensions parameter.

{% highlight sass %}.bulma-burger-mixin { @include mixins.burger(2.5rem); }{% endhighlight %} {% capture burger %} {% endcapture %} {% include docs/elements/snippet.html content=burger %} {% include docs/elements/anchor-bis.html name="Delete" %}

The delete() mixin creates a 20x20px circle containing a cross. It comes with 3 modifiers: is-small, is-medium and is-large.

{% highlight sass %}.bulma-delete-mixin { @include mixins.delete; }{% endhighlight %} {% capture delete %} {% endcapture %} {% include docs/elements/snippet.html content=delete %} {% include docs/elements/anchor-bis.html name="Loader" %}

The loader() mixin creates a 1em spinning circle.

{% highlight sass %}.bulma-loader-mixin { @include mixins.loader; }{% endhighlight %} {% capture loader %} {% endcapture %} {% include docs/elements/snippet.html content=loader %} {% include docs/elements/anchor-bis.html name="Font Awesome container" %}

The fa() mixin creates a square inline-block element, ideal for containing a Font Awesome icon, or any other type of icon font.
The first $size parameter defines the icon font size.
The second $dimensions parameter defines the dimensions of the square container.

{% highlight sass %}.bulma-fa-mixin { @include mixins.fa(1rem, 2rem); background-color: lavender; // For demo purposes }{% endhighlight %} {% capture fa %} {% endcapture %} {% include docs/elements/snippet.html content=fa %} {% include docs/elements/anchor.html name="CSS Mixins" %}

These mixins add CSS rules to the element.

{% include docs/elements/anchor-bis.html name="Block" %}

The block() mixin adds spacing below an element, but only if it's not the last child.
The $spacing parameter defines the value of the margin-bottom.

{% highlight sass %}.bulma-block-mixin { @include mixins.block(1rem); }{% endhighlight %} {% capture block %}

This element has a margin-bottom.

This element too.

Not this one because it's the last child.

{% endcapture %} {% include docs/elements/snippet.html content=block %} {% include docs/elements/anchor-bis.html name="Overlay" %}

The overlay() mixin makes the element cover its closest positioned ancestor.
The $offset parameter defines how far inside the element is positioned from each edge (top, bottom, left and right).

{% highlight sass %}.bulma-overlay-mixin { @include mixins.overlay(1.5rem); background-color: darkorange; border-radius: 0.25em; color: white; opacity: 0.9; padding: 1em; }{% endhighlight %} {% capture overlay %}
Overlay element
{% endcapture %} {% include docs/elements/snippet.html content=overlay %} {% include docs/elements/anchor-bis.html name="Center" %}

The center() mixin allows you to absolutely position an element with fixed dimensions at the center of its closest positioned ancestor.
The value of the $width parameter should be the width of the element the mixin is applied on.
Unless the element has square dimensions, the second parameter $height is required and its value should be the height of the element the mixin is applied on.

{% highlight sass %}.bulma-center-mixin { @include mixins.center; }{% endhighlight %} {% capture center %}
{% endcapture %} {% include docs/elements/snippet.html content=center %} {% include docs/elements/anchor-bis.html name="Placeholder" %}

The placeholder() mixin allows you to change the style of an input's placeholder.
The $offset parameter defines how far inside the element is positioned from each edge (top, bottom, left and right).

{% highlight sass %}.bulma-placeholder-mixin { @include mixins.placeholder { color: lightblue; } }{% endhighlight %} {% capture placeholder %} {% endcapture %} {% include docs/elements/snippet.html content=placeholder %} {% include docs/elements/anchor-bis.html name="Clearfix" %}

The clearfix() mixin adds a ::after pseudo-element with a clear: both rule.

{% highlight sass %}.bulma-clearfix-mixin { @include mixins.clearfix; }{% endhighlight %} {% capture clearfix %}

This is a short image description.

This text is following the clearfix element and is correctly placed after.

{% endcapture %} {% include docs/elements/snippet.html content=clearfix %} {% include docs/elements/anchor-bis.html name="Reset" %}

The reset() mixin applies a soft style reset. This is especially useful for <button> elements.

{% highlight sass %}.bulma-reset-mixin { @include mixins.reset; }{% endhighlight %} {% capture reset %} {% endcapture %} {% include docs/elements/snippet.html content=reset %} {% include docs/elements/anchor-bis.html name="Unselectable" %}

The unselectable() mixin makes an element not selectable. This is to prevent the text to be selected when double-clicked.

{% highlight sass %}.bulma-unselectable-mixin { @include mixins.unselectable; }{% endhighlight %} {% capture unselectable %}

This text is selectable.

This text is not selectable.

{% endcapture %} {% include docs/elements/snippet.html content=unselectable %} {% include docs/elements/anchor-bis.html name="Overflow Touch" %}

The overflow-touch() mixin add the -webkit-overflow-scrolling: touch; rule to the element.

{% include docs/elements/anchor.html name="Direction Mixins" %} {% include docs/elements/anchor-bis.html name="Left-to-right and Right-to-left Mixins" %}

Bulma has a global $rtl flag, which allows the framework to output a Right-to-left version of the CSS. By default, this flag's value is set to false. This means the framework output a Left-to-right version.

The mixins @mixin ltr and @mixin rtl are here to output CSS rules based on the value of $rtl:

This is useful for properties that are specific to the side of an element.

{% highlight sass %}.bulma-ltr-rtl-mixin { background-color: lightgreen; padding: 0.5em 1em; border: 1px solid seagreen; margin-right: -1px; &:first-child { @include mixins.ltr { border-bottom-left-radius: 0.5em; border-top-left-radius: 0.5em; } @include mixins.rtl { border-bottom-right-radius: 0.5em; border-top-right-radius: 0.5em; } } &:last-child { @include mixins.ltr { border-bottom-right-radius: 0.5em; border-top-right-radius: 0.5em; } @include mixins.rtl { border-bottom-left-radius: 0.5em; border-top-left-radius: 0.5em; } } }{% endhighlight %} {% capture ltr-rtl %}
One Two Three
{% endcapture %} {% include docs/elements/snippet.html content=ltr-rtl %} {% include docs/elements/anchor-bis.html name="LTR Position" %}

The ltr-position() mixin is a quick way to switch between left and right CSS properties when dealing with positioned elements.
The first $spacing parameter defines the value of the offset, whether it's right or left.
The second $right parameter defines if the property outputs right (default) or left.

Here is what the output looks like with a $spacing parameter set to 1rem:

Flag → $rtl: false; $rtl: true;
@include mixins.ltr-position(1rem, true) right: 1rem left: 1rem
@include mixins.ltr-position(1rem, false) left: 1rem right: 1rem

Sass source

{% highlight sass %}.bulma-ltr-position-mixin { @include mixins.ltr-position(1rem, false); border-radius: 0.25em; position: absolute; top: 1rem; }{% endhighlight %}

CSS output

{% highlight css %}.bulma-ltr-position-mixin { left: 1rem; border-radius: 0.25em; position: absolute; top: 1rem; }{% endhighlight %} {% capture ltr-position %}

Cras mattis consectetur purus sit amet fermentum. Nulla vitae elit libero, a pharetra augue. Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Curabitur blandit tempus porttitor. Maecenas faucibus mollis interdum.

{% endcapture %} {% include docs/elements/snippet.html content=ltr-position %} {% include docs/elements/anchor-bis.html name="LTR Property" %}

The ltr-property() mixin works like the ltr-position() mixin but allows you to choose which CSS property to set. The mixin will append -right or -left to that property. This is especially useful for margin and padding.
The first $property parameter which property you want to "flip" left and right.
The second $spacing parameter defines the value of the offset, whether it's right or left.
The third $right parameter defines if the property outputs right (default) or left.

Here is what the output looks like with a $spacing parameter set to 1rem:

Flag → $rtl: false; $rtl: true;
@include mixins.ltr-property("margin", 1rem, true) margin-right: 1rem margin-left: 1rem
@include mixins.ltr-property("margin", 1rem, false) margin-left: 1rem margin-right: 1rem

Sass source

{% highlight sass %}.bulma-ltr-property-mixin { @include mixins.ltr-property("margin", 1rem, false); border-radius: 0.25em; }{% endhighlight %}

CSS output

{% highlight css %}.bulma-ltr-property-mixin { margin-left: 1rem; border-radius: 0.25em; }{% endhighlight %} {% capture ltr-property %}

Cras mattis consectetur purus sit amet fermentum. Nulla vitae elit libero, a pharetra augue. Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Curabitur blandit tempus porttitor. Maecenas faucibus mollis interdum.

{% endcapture %} {% include docs/elements/snippet.html content=ltr-property %}