Custom module for adding CSS file in admin section How do I include admin.css in my theme so that it's loaded in the admin section (and preferably only the admin section)?

Right now when I add admin.css via the x.libraries.yml file, it's only loaded on the front-end.

Update:

So... based on your comments/answers I've created a module admin-css. But nothing happens. The file isn't loaded. What am I doing wrong?

Inside admin_css.info.yml :

name: Admin CSS
description: Alters the Admin CSS for better usability.
package: Custom

type: module
core: 8.x


Inside admin_css.libraries.yml :

admin-css:
  version: 1.x
  css:
    theme:
      css/admin.css: {}


Inside admin_css.module :

&lt;?php

function admin_css_attachments(array &amp;$attachments) {
    $is_admin = \Drupal::service('router.admin_context')-&gt;isAdminRoute();
    if ($is_admin) {
      $attachments['#attached']['library'][] = 'admin_css/admin-css';
      return;
    }

}
Unless you use the same theme for front and backend, that's not the right approach. 

If something transcends the theme layer, e.g. you have functionality that you need to apply to two separate themes, it belongs in a module.

See Adding stylesheets (CSS) and JavaScript (JS) to a Drupal 8 module for instructions to actually accomplish that, specifically the section on Attaching a library to all (or a subset of) pages which contains a contrived code example:

function contextual_page_attachments(array &amp;$attachments) {
  if (!\Drupal::currentUser()-&gt;hasPermission('access contextual links')) {
    return;
  }

  $attachments['#attached']['library'][] = 'contextual/drupal.contextual-links';
}