Attach dynamic inline css to
After doing some more research i've found an answer to my problem. The main reason for not finding a solution was, they don't want you to do this in Drupal 8. 

From their documentation:

https://www.drupal.org/developing/api/8/assets#dynamic-css-js


  If the dynamic CSS/JS is built for each request, then you enter the truly advanced territory. This is hard, and for a good reason: per-request dynamic assets have to be built on every single request and therefore slow Drupal down. We want to make it hard to make Drupal slow down, so this is why we don't offer a nice API for this — since we don't want you to do it.


This makes sense and there is a short description how to get it to work anyway but its lacking of an example. This is what i've done to get it to work:

function my_module_page_attachments_alter(array &amp;$page) {
  $background_color = '#000';
  $page['#attached']['html_head'][] = [
    [
      '#tag' =&gt; 'style',
      '#value' =&gt; '.my-custom-class { background: ' . $background_color . '; }',
    ],
    'my-custom-module'
  ];
}