Add a block class programmically in drupal 8

Small snippet to show how to add a class to your block

/*
 * Implements hook_preprocess_block
 */
function MYMOUDULE_preprocess_block(&$variables)
{
    if ($block_id == 'MYBLOCKID') {
        $variables['attributes']['class'][] = 'animated fadeInLeft';
    }
}

 

 

Saved you some valuable time?

Buy me a drink 🍺 to keep me motivated to create free content like this!