Search code examples
htmlcssviewport

HTML CSS How can I add viewport info to Cascading Style Sheet?


I have a program that generates HTML listings that uses Cascading Style Sheet templates (that are added to the HTML file upon generation) but I would like to add the following line in the CSS template:

<meta name="viewport" content="width=device-width, initial-scale=1.0">

I tried the following line at the top of the CSS template earlier, but it didn't work:

@-ms-viewport {width:device-width; initial-scale:1.0}

How should I do this correctly?


Solution

  • The viewport directive is correctly placed in the html header. I don't think there is a valid alternative for it in CSS. In the end it's not a style but instructions for the browser on how to handle the viewport.