Styling a category link

Here is an example of how you can do it with your code, using the category name as the class name:

<?php 
             // category link   
$categories = get_the_category();
        if ( ! empty( $categories ) ) {
echo '<a class="' .esc_html( $categories[0]->name ) . '" href="' . esc_url( get_category_link( $categories[0]->term_id ) 
      ) . '">' . esc_html( $categories[0]->name ) . '</a>';
      }
    // category link
         ?>