How do I set the title tag for the maintenance page? I need to change the default title tag for the maintenance page, which currently is "Site under maintenance | [sitename]".

I tried to set $variables['head_title'] in hook_preprocess_maintenance_page() but it doesn't work.

Also I think it can be set in hook_preprocess_html(), but I don't know how to check the served page is the maintenance page.

How can I achieve this?
TEMPLATE_preprocess_maintenance_page changes only variables for maintenance-page.html.twig. But &lt;title&gt; is outputted in html.html.twig, so you have to choose another preprocessor template_preprocess_html. So you can use this code(don't forget to clean cache after it):

function mytheme_preprocess_html(&amp;$variables) {
  $maintenance_mode = \Drupal::state()-&gt;get('system.maintenance_mode');
  if (!empty($maintenance_mode)) {
    $variables['head_title'] = (string)t('My Custom Maintenance Title');
  }
}