How do I use a css media query in a link tag?



  • Note: If your media queries apply to all media types, " screen and" can be left out.

    Also see: How do I use css media queries?

    This example show the use of a media query in a <link> tag.

    <!doctype html>
    
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>Starter HTML Page</title>
      <meta name="description" content="HTML starter page">
      <meta name="author" content="Demo">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link rel="stylesheet" media="screen and (max-width: 375px)" href="375px.css" />
    </head>
    
    <body>
    
    <h2>The wonderful colors of flowers</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Sit amet massa vitae tortor. Pretium nibh ipsum consequat nisl vel pretium. Interdum posuere lorem ipsum dolor.</p>
    
    </body>
    </html>
    

    375px.css file

    body {
      background-color: green;
    }
    

    For a tablet device, this is the display:
    ad5e932f-3c72-40aa-8577-755bf74c9813-image.png

    For a phone device, this is the display.
    d8cadd8e-cc70-43bf-90dc-496b78d10f11-image.png


Log in to reply
 

© Lightnetics 2024