Local tasks generate tabs on pages and are defined in a {module}.links.task.yml file in the root directory of your module. In this file, you have two or more local task declarations like:
mastering_drupal_8.test_page:
title: 'Test'
route_name: mastering_drupal_8.test_page_messag
base_route: mastering_drupal_8.test_page
weight: 1
mastering_drupal_8.test_2:
title: 'Test 2'
route_name: mastering_drupal_8.test_page_2
base_route: mastering_drupal_8.test_page
weight: 2
For each local task element, you have the following attributes:
- title: Title shown in the tab
- route_name: Machine name of the route that the tab directs to
- base_route: Machine name of the route that the tab is shown on
- weight: Determines the order of the tabs; higher weight links appear later
The local task, where the route_name matches the base_route, is the default local task that is active when the user visits the route.

Like menu links, you are able to create local tasks dynamically by adding a deriver to the local tasks YAML file. The getDerivativeDefinitions() function returns an array in the same format as the local tasks YAML element.