getHeadHtml() not outputting CSS included with {% includeCss %} I think there is a bug in the getHeadHtml function of craft. In the Documentation (https://craftcms.com/docs/templating/includecss) it says: 


  Your CSS snippet will be output by the getHeadHtml() function. If you aren’t calling that function anywhere, Craft will insert it right before the HTML’s &lt; /head> tag.


But in my templates it works only, if the tag getHeadHtml() is placed after the includeCss Tag.
So the following simple Example does not work as expected: 

&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;title&gt;Title&lt;/title&gt;
    &lt;!-- Here should the CSS start --&gt; 
        {{ getHeadHtml() }}
    &lt;!-- Here should the CSS end --&gt; 
  &lt;/head&gt;
  &lt;body&gt;

      {% set myCss %}
        .content {
            color:  red;
        }
      {% endset %}


      {% includeCss myCss %}

  &lt;/body&gt;
&lt;/html&gt;


It outputs the following code:

&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;title&gt;Title&lt;/title&gt;
    &lt;!-- Here should the CSS start --&gt; 

    &lt;!-- Here should the CSS end --&gt; 
  &lt;style type="text/css"&gt;
  .content {
            color:  red;
        }
  &lt;/style&gt;&lt;/head&gt;
  &lt;body&gt; 
  &lt;/body&gt;
&lt;/html&gt;


It outputs the CSS before the closing &lt; /head> Tag and not between the two comments. Is there any workaround/fix for this?
This is just an order of operations issue. The documentation is correct, but incomplete.

getHeadHtml() will only output head HTML that was queued up for it before the function was actually called. Any head HTML that is queued up after you've called getHeadHtml() will end up getting inserted in the default location - right before the &lt;/head&gt; tag.

So, if you had this in your template instead:

{% includecss %}
  .content {
      color:  red;
  }
{% endincludecss %}

&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;title&gt;Title&lt;/title&gt;
    &lt;!-- Here should the CSS start --&gt; 
        {{ getHeadHtml() }}
    &lt;!-- Here should the CSS end --&gt; 
  &lt;/head&gt;
  &lt;body&gt;

  &lt;/body&gt;
&lt;/html&gt;


Then the CSS would get included between the HTML comments as you’d expect.