Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Tim Bozeman on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Description:
In Drupal 7, drupal_add_css()
, drupal_add_js()
and drupal_add_library()
could be used to add JS and CSS to a page. In Drupal 8, these functions have been removed. Instead, you must use #attached
in a render array. #attached
was already available in Drupal 7, and was widely used, but now it'll be the only way to attach assets.
Read the Adding stylesheets (CSS) and JavaScript (JS) to a Drupal 8 module documentation to find code samples.
Impacts:
Site builders, administrators, editors
Module developers
Themers