Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How Sass treats colors varies depending on what version you're using. But there are a few common behaviors:</p> <ul> <li>Sass will <em>always</em> maximize backwards compatibility whenever possible. Since <strong>keyword</strong>, <strong>hex</strong>, and <strong>rgba</strong> have the broadest browser support, all colors will be converted to one of those 3 formats, prioritizing towards either the keyword or hex. The rgba format will only be used if the color has alpha transparency (if you specify <code>rgba(0, 0, 0, 100)</code>, Sass will convert it to either <code>black</code> or <code>#000</code>)</li> <li>If Sass has to choose between using the keyword or hex formats, the one it will use will depend on the output settings. The <em>compact</em> or <em>compressed</em> modes will always convert to hex, the other formats will use the keyword.</li> <li>Sass will convert hex colors to their 3-digit format in <em>compressed</em> mode (eg. <code>#000000</code> will be output as <code>#000</code>).</li> </ul> <h1>Sass 3.3 and older</h1> <p>Sass <em>only</em> converts colors when they are used as variables or if they are not in one of the 3 formats as described above:</p> <pre><code>$color-hex: #000000; $color-keyword: black; $color-rgb: rgb(0, 0, 0); $color-hsl: hsl(0, 0, 0); .box-hex { color: $color-hex; background: #000000; } .box-keyword { color: $color-keyword; background: black; } .box-rgb { color: $color-rgb; background: rgb(0, 0, 0); } .box-hsl { color: $color-hsl; background: hsl(0, 0, 0); } </code></pre> <p>Output:</p> <pre><code>.box-hex { color: black; background: #000000; } .box-keyword { color: black; background: black; } .box-rgb { color: black; background: black; } .box-hsl { color: black; background: black; } </code></pre> <h1>Sass 3.4 and later</h1> <p>The only change from 3.3 to 3.4 is that when using variables, Sass will preserve the format of your color... unless it is in something other than the keyword, hex, or rgba formats.</p> <pre><code>.box-hex { color: #000000; background: #000000; } </code></pre> <h1>But what if I <em>really</em> need a specific format?</h1> <p>If you absolutely must have a specific format, you can turn it into a string:</p> <pre><code>$color: #{'#F00'}; // or `unquote('#F00')` .foo { color: $color; } </code></pre> <p>Output:</p> <pre><code>.foo { color: #F00; } </code></pre> <p>Just keep in mind that when you do this, your "color" will not work with color manipulation functions like <code>lighten()</code> or <code>darken()</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload