How can I print the admin toolbar icon for my module?

I created a module and it has a menu in the admin toolbar. I want to show an icon (module/costum_module/image/00/icon.svg) in this path for my admin toolbar tab.

I created a CSS style for that, but it doesn't work.

Module path :

/module/my module/css/styles.css =>

.toolbar-icon-mymodule-list:before {
    background-image: url(../icons/787878/icon.svg);
.toolbar-icon-mymodule-list.active:before {
    background-image: url(../icons/000000/icon.svg);

/module/my module/mymodule.libraries.yml =>

      css/styles.css: {}
  • 3
    You did not tell what you've tried and why it is not working. You can use the css from the toolbar module as example: cgit.drupalcode.org/drupal/tree/core/modules/toolbar/css/…
    – 4uk4
    Feb 4, 2017 at 16:33
  • 1
    I take that @4k4 also means you aren't showing the CSS styles you added, and you aren't telling us how you added them.
    – apaderno
    Feb 4, 2017 at 16:59
  • I edit my question .
    – user60258
    Feb 5, 2017 at 5:11
  • Can you be more specific about what is not working?
    – 4uk4
    Feb 5, 2017 at 10:56

1 Answer 1


If you want to add svg icon for your menu link item in admin toolbar, you have to alter toolbart.

In your mymodule.libraries.yml file

toolbar: version: VERSION css: theme: css/styles.css: {}

And you need to implement hook_toolbar_alter() in your mymodul.module

function mymodule_toolbar_alter(&$items) {
  $items['administration']['#attached']['library'][] = 'mymodule/toolbar';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.