How to add custom class in custom module?
you can try code :

  $url = Url::fromRoute('entity.node.canonical', ['node' =&gt; $previous_next['next'],'an'=&gt;'left']);
  $url-&gt;setOptions([
      'attributes' =&gt; [
          'class' =&gt; ['ajax-link custom-class']
      ],
  ]);

  $build['prevnext_next'] = [
      '#type' =&gt; 'link',
      '#title' =&gt; t('Next'),
      '#url' =&gt;  $url,
  ];