How to add current year in Webflow

Most of the time we want to set something in Webflow and let it automatically update i.e. the copyright year. This is easily achievable with some vanilla JavaScript code tied to an ID set in Webflow designer.

First we create a custom tag or Text block element and add a unique ID in our example the ID is copyright

Set ID to webflow element
Set ID to webflow element

Next we need to target the ID with the help of JavaScript and update the number to the current year. Paste the code bellow either under Custom Code in Webflow settings or add the code to an Embeded element on every page.

document.addEventListener("DOMContentLoaded", () => {
  const currentYear = new Date().getFullYear();
  const copyrightYearElement = document.getElementById('copyright');

  if (copyrightYearElement) {
    copyrightYearElement.textContent = currentYear;