I'm attempting to attach several css files to a Drupal 7 module. All files have identical read/write/execute and owner permissions. I haven't had trouble with one of the three files but I can't get the other two added (checked the loaded stylesheets in developer tools). Here's what I've tried:

function usspd_search_main_form($form, $form_state) {
  $form['#attached']['css']['css1'] = '/sites/all/libraries/data_search/bootstrap_tagsinput/bootstrap_tagsinput.css'; //failed
  $form['#attached']['css']['css2'] = '/sites/all/libraries/data_search/tagme/tagme_jquery-ui.css'; //failed
  drupal_add_css('/sites/all/libraries/data_search/bootstrap_tagsinput/bootstrap_tagsinput.css'); //failed
  drupal_add_css('/sites/all/libraries/data_search/tagme/tagme_jquery-ui.css'); //failed

  $form['#attached']['css']['css3'] = drupal_get_path('module', 'usspd_search') . '/theme/usspd_search.css'; //works
  return $form;

My best guess is that there's a class conflict and instead of overriding, the attachment just fails. Is there any way to declare priority? Otherwise I'll have to add the css from both files inline.

Additionally, I'm able to call everything fine when added as raw HTML to a basic page. It shouldn't be a pathing issue.

<link rel="stylesheet" href="/sites/all/libraries/data_search/bootstrap_tagsinput/bootstrap_tagsinput.css">
<link rel="stylesheet" href="/sites/all/libraries/data_search/tagme/tagme_jquery-ui.css">
  • Look at the HTML source in the browser, and search for the filename without the path. Is the filename in the source? Then you've either linked it incorrectly, or there are file permission problems preventing it from being loaded. If the filename is not found in the source, it means you're doing it incorrectly in Drupal. What function have you added the above code into? Without context, we can't tell if you are doing it right or wrong. Also, I've never attached libraries with named indexes before - it's probably not a problem, but it's the one question that stands out for me looking at the code
    – Jaypan
    Jun 8, 2019 at 23:51
  • I've checked the HTML source in the browser to verify what is/isn't loading. Attempts to add css marked "//failed" were not found in the source. I'll update question with additional code.
    – Ghoti
    Jun 8, 2019 at 23:57
  • Just tried removing the index names (ie from $form['#attached']['css']['css1'] to $form['#attached']['css'][]). No luck. Guess that shouldn't be too surprising given drupal_add_css() also fails.
    – Ghoti
    Jun 9, 2019 at 0:13
  • Are you dschoni? I just made this comment which seems relevant to your issue, though maybe just coincidentally: drupal.org/node/2216195/discuss#comment-13138748
    – Jaypan
    Jun 9, 2019 at 0:15
  • I am not dschoni and am using Drupal 7, not Drupal 8. I'll work through the Drupal 8 documentation that you linked and see if I can find anything useful. Also reviewing your comment.
    – Ghoti
    Jun 9, 2019 at 0:20

1 Answer 1


The pathing was wrong after all. The preceding "/" was messing things up. Strangely, this was not an issue for javascript attachments. For example:

$form['#attached']['css']['css2'] = '/sites/all/libraries/data_search/tagme/tagme_jquery-ui.css'; //fails
$form['#attached']['js']['js2'] = '/sites/all/libraries/data_search/tagme/tagme_jquery-ui.min.js'; //works
$form['#attached']['css']['css2'] = 'sites/all/libraries/data_search/tagme/tagme_jquery-ui.css'; //works

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.