Getting external links set to target="_blank" is well-documented using client or server code:
To suggest that a link be opened in a new browsing context (typically, a new tab or a new window), which is apparently what you mean by “leave the website”, you can use the
target=_blank attribute. To set that the default for all links (and all form submissions), you can use the tag
<base target=_blank>; this might be feasible if you want to handle most links that way and override the setting with
target=_self as needed. Other than that, HTML has no tools for the purpose, and no concept of “external” vs. “internal” links. So you need to generate the attributes when generating the page, using whatever definition you have for “external”.
In CSS, there is in practice nothing that would help. Years ago, there was a proposed
target-name property, in CSS3 Hyperlink Presentation Module WD in 2004. But it was never implemented, and work on the topic has been discontinued, as briefly described in CSS3 Hyperlink Presentation Module WG Note in 2014.