Tip #13: Use Date to add the current year to your copyright claim

  • — Javascript

  • 1 min. read

  • — 2/17/2023

Typically at the bottom of websites you'll see something along the lines of "© Website Name 2023. All Rights Reserved".

While you can hard-code this piece of content in your footer, I recommend you actually inject the year using a small amount of JavaScript.

That way, when New Years comes around, you can spend your time partying instead of updating your website's footer to reflect the validity of your copyright 😉.

In HTML, you can very quickly do this by using the following snippet:

<footer>
    <p>&copy; Website Name <span data-year></span>. All Rights Reserved.</p>
</footer>

<script>
    document.querySelector("[data-year]").textContent = new Date().getFullYear()
</script>

If you're using a frontend library like React, it's even simpler!

<footer>
	<p>&copy; Website Name {new Date().getFullYear()}. All Rights Reserved.</p>
</footer>
Shaun Chander

hey (again), I'm shaun

I'm posting 3 tips on creative web development daily. Subscribe below to to get tips delivered straight into your inbox!