Empowering you to understand your world

JavaScript Tutorials: How To Change Meta Tags Dynamically Using JavaScript

You can change your meta title, meta description, meta author, and all other meta tags dynamically using JavaScript code. The following example changes the ‘meta description’ tag:

let metas = document.getElementsByTagName("meta");
metas.description.content = "New meta description";

This is useful if you are loading web pages or similar content from a database.

To change the author meta tag using JavaScript:

let metas = document.getElementsByTagName("meta");
metas.author.content = "The author's name";

To change the meta title tag using JavaScript:

let metas = document.getElementsByTagName("meta");
metas.title.content = "New meta title";

Further Reading

How To Set Page Title In JavaScript

Introduction To JavaScript Variables

Breakdown Of The Various Meta Tags

Subscribe to our newsletter
Get notified when new content is published