creating links containing anchors
Url component is not able to generate URLs with empty anchors, so you need  create an anchor on your page or use existing one.

use Drupal\Core\Link;
use Drupal\Core\Url;

$url = Url::fromUserInput('#main-content');
print Link::fromTextAndUrl(t('Link text'), $url)-&gt;toString();