Generally speaking a back link isn't necessary… the Back button usually suffices quite nicely, and usually you can also simply link to the previous page in your site. However, sometimes you might want to provide a link back to one of several "previous" pages, and that's where a back link comes in handy. So I refer you below tutorial if you want to do in more advanced way:
var element = document.getElementById('back-link');
// Provide a standard href to facilitate standard browser features such as
// - Hover to see link
// - Right click and copy link
// - Right click and open in new tab
element.setAttribute('href', document.referrer);
// We can't let the browser use the above href for navigation. If it does,
// the browser will think that it is a regular link, and place the current
// page on the browser history, so that if the user clicks "back" again,
// it'll actually return to this page. We need to perform a native back to
// integrate properly into the browser's history behavior
element.onclick = function() {
history.back();
return false;
}
// if referrer is different from this site
if (!document.referrer.includes(window.location.host)) {
// store current history length
localStorage.setItem('historyLength', `${history.length}`);
}
// Return to stored referrer on logo click
document.querySelector('header .logo').addEventListener('click',
() =>
history.go(Number(localStorage.getItem('historyLength')) - history.length -1)
);