Generating an absolute node URL from its node id
Drupal 8
$nid = 5;
// Or $nid = $node-&gt;id();
$node_title = 'Node Title'
// Or $node-&gt;getTitle();

Create absolute URL:
// Will output http://example.com/path-to-my-node
$options = ['absolute' =&gt; TRUE];
$url_object = \Drupal\Core\Url::fromRoute('entity.node.canonical', ['node' =&gt; $nid], $options);
// In Twig use {{ url_object }}.
// In PHP (outside a render array) use $url_object-&gt;toString().

Create absolute link object (and inner span):
// Will output &lt;a href=&quot;http://example.com/path-to-my-node&quot; class=&quot;this-class&quot;&gt;&lt;span&gt;Node Title&lt;/span&gt;&lt;/a&gt;
$options = ['absolute' =&gt; TRUE, 'attributes' =&gt; ['class' =&gt; 'this-class']];
$node_title = \Drupal\Core\Render\Markup::create('&lt;span&gt;' . $node_title . '&lt;/span&gt;');
$link_object = \Drupal\Core\Link::createFromRoute($node_title, 'entity.node.canonical', ['node' =&gt; $nid], $options);
// In Twig use {{ link_object }}.
// In PHP (outside a render array) use $link_object-&gt;toString().