Change record status: 
Project: 
Introduced in branch: 
8.0.x
Introduced in version: 
8.0.0-beta4
Description: 

To display a link with only a #fragment, the special route can be used.

Drupal 7

$fragment_only_url = url('', array('external' => TRUE, 'fragment' => 'fragment'));

Drupal 8

$fragment_only_url = \Drupal::url('<none>', [], ['fragment' => 'fragment']);
Impacts: 
Module developers