Multiple viewport meta tags
See original GitHub issueBug report
Describe the bug
Custom viewport meta tags in the _document.js
page are ignored by the browser because next.js pushes it’s own viewport meta tag without checking if any exists already. As a result, we end up with this:
<head>
...
<meta name="viewport" content="viewport-fit=cover"/> <!-- ignored 🤕 -->
...
<meta name="viewport" content="width=device-width" />
...
</head>
I could trace the problem down to this part of the code:
To Reproduce
- Define a viewport meta tag in the
_document.js
page. - Open any page of your app and look for
<meta name="viewport"
I also made a full reproducible example, but I faced issues with Codesandbox. If you decide to run the reproducible, please download the source code and run it on your machine instead of the online sandbox.
Screenshots
System information
- OS: macOS
- Browser: tested in chrome, safari and firefox
- Version of Next.js: 9.4.2
- Version of Node.js: 12.16.3
Issue Analytics
- State:
- Created 3 years ago
- Comments:22 (11 by maintainers)
Top Results From Across the Web
Multiple viewport <meta> tags were found in the <head>
A <meta> viewport element gives the browser instructions on how to control the page's dimensions and scaling. Only one viewport tag is required,...
Read more >How to fix the “Multiple meta viewport tags” issue? - Sitechecker
Each HTML document should have only one viewport meta tag. If there are more of them, then this can lead to the selection...
Read more >Having two viewport meta tags - will one get overwritten?
I think the meta tag is handled like the title tag. If you use more than one, they get overridden by the later...
Read more >Viewport meta tag - HTML: HyperText Markup Language | MDN
Viewport meta tag. This article describes how to use the "viewport" <meta> tag to control the viewport's size and shape.
Read more >Responsive Web Design Viewport - W3Schools
You should include the following <meta> viewport element in all your web pages: ... Here is an example of a web page without...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
Top GitHub Comments
…And as per further discussion in #13408, I’m now working on a PR to warn users when they add a
viewport
tag tonext/document
’s<Head>
, asviewport
is supposed to be handled bynext/head
. 👍🏼So I got this warning “viewport meta tags should not be used in _document.js’s <Head>” yesterday, but even after reading through this thread I do not at all understand why it is bad practice to put viewport meta tags in the <Head> in _document.
For me it would be really useful if the documentation on _app and _document would be expanded to cover the differences between the two and the reasoning why we should put things like viewport metatags in either of those. Or is that documentation available and I’m just glaring over it…?