In jsFiddle I need to put viewport metatag in the head
element. But since jsFiddle already includes html, head and body tags, it shows a warning: "No need for the HTML tag, it's already in the output."
Is there a way to put viewport metatag in the head?
<meta name="viewport" content="width=device-width, initial-scale=1" />
Generally, meta elements (including viewport) should be placed in the document's <head> . CSS rules should either be added to a CSS stylesheet and referenced with a <link> element or, if you're not using stylesheets for some reason, in a <style> element (also in the document's <head> ).
The viewport is the user's visible area of a web page. It varies with the device - it will be smaller on a mobile phone than on a computer screen. You should include the following <meta> element in all your web pages: <meta name="viewport" content="width=device-width, initial-scale=1.0">
HTML5 introduced a method to let web designers take control over the viewport, through the <meta> tag. This gives the browser instructions on how to control the page's dimensions and scaling.
One way to edit a jsFiddle's head
tag is to use the CSS panel style
hack.
If there is a need to edit the header, one can close the
style
element and access the header. After all modifications, please open thestyle
tag again./* your custom CSS */ </style> <!-- access to the HEAD element --> <style>
Inserting the above code into the CSS panel will change the CSS section of the
head
to<style type='text/css'> /* your custom CSS */ </style> <!-- access to the HEAD element --> <style> </style>
Alternatively, if you're a bit more flexible and are okay with editing the viewport after the page has been loaded, you may use JavaScript or jQuery.
var viewport = document.createElement("meta");
viewport.setAttribute('name', 'viewport');
viewport.setAttribute('content', 'width=device-width, initial-scale=1');
document.getElementsByTagName('head')[0].appendChild(viewport);
$('head').append('<meta name="viewport" content="width=device-width, initial-scale=1" />');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With