Skip to content

Instantly share code, notes, and snippets.

@achou11
Last active November 13, 2023 18:24
Show Gist options
  • Select an option

  • Save achou11/7d9a9b4d67bda9ce472ed1d35dbee0ab to your computer and use it in GitHub Desktop.

Select an option

Save achou11/7d9a9b4d67bda9ce472ed1d35dbee0ab to your computer and use it in GitHub Desktop.
Add a <meta> html tag to make sites more usable on mobile devices: https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag
// Call this function
function addViewportMeta() {
const head = document.head
if (!head.querySelector('meta[name=viewport]')) {
const meta = document.createElement('meta')
meta.setAttribute("name", "viewport")
meta.setAttribute("content", "width=device-width, initial-scale=1")
head.appendChild(meta)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment