The CSS Media Query gives you a way to apply CSS only when the browser and device environment matches a rule that you specify the "viewport.is". Firends, whenever you see the BOILERPLATE-CODE for STARTING-HTML-DOCUMENT in VS-CODE, you all see the below HTML-DOCUMENT-STRUCTURE that is,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Webpage Title</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<!-- All visible content goes here -->
<h1>Hello World!</h1>
<script src="script.js"></script>
</body>
</html>
This boilerplate includes essential elements:
<!DOCTYPE html>: Declares the document type as HTML5 to prevent "quirks mode" in browsers.<html lang="en">: The root element, specifying the language of the content.<head>: Contains meta-information not displayed on the page, like the title and links to stylesheets.<meta charset="UTF-8">: Sets character encoding for correct text display.<meta name="viewport" content="width=device-width, initial-scale=1.0">: Configures responsive design settings for different devices.<title>Webpage Title</title>: Sets the text appearing in the browser tab.<link rel="stylesheet" href="style.css">: Links an external CSS file for styling.<body>: Contains all visible content of the webpage.<script src="script.js"></script>: Links an external JavaScript file for interactivity.So, "<meta name="viewport" content="width=device-width, initial-scale=1.0">" is the main reason that your webpage becomes responsive and you can use media-query as-per your need. Means, as-per the size of the device you apply your media-query and for the sake of your device-size, you should knew that the size depends on pixels-resolution with screen-size that is,
You, see the ranges, yes you can modify the ranges according to the responsive appearences as-per the feedback you got from your client(s).
Now, for the sake of using media-queries, you can see below points which allows you to decide ranges as-per your electronic device's screen-size that is,
<meta name="viewport" content="width=device-width, initial-scale=1.0">" tag is essential for creating responsive, mobile-friendly websites. It tells mobile browsers to set the viewport width to the physical device width and sets the initial zoom level to 100%, preventing browsers from assuming a desktop-sized layout and shrinking content. Key Components & Details
<head> section of an HTML document.width=device-width: Forces the page width to match the screen's width in CSS pixels, ensuring adaptability across different device sizes (phones, tablets).initial-scale=1.0: Defines the initial zoom level when the page loads, setting a 1:1 pixel ratio (1 CSS pixel = 1 viewport pixel).Other Possible Attributes (Less Common)
maximum-scale: Sets the maximum zoom level.minimum-scale: Sets the minimum zoom level.user-scalable=no: Prevents users from zooming, which is generally advised against for accessibility. Breakdown of the Attributes
name="viewport": Tells the browser that this meta tag contains instructions for the viewport—the user's visible area of a web page.width=device-width: Sets the width of the page to match the screen width of the device in CSS pixels. Without this, mobile browsers typically default to a "virtual" width of 980px and scale the page down, making text tiny and difficult to read.initial-scale=1.0: Sets the initial zoom level to 100% when the page first loads. This establishes a 1:1 relationship between CSS pixels and device-independent pixels.Why It Is Essential
Additional Optional Properties
Beyond the standard tag, you can add other directives to the content attribute:
user-scalable=yes/no: Controls whether users can zoom in or out. Setting this to no is generally discouraged as it hurts accessibility.maximum-scale / minimum-scale: Sets the limits for how much a user can zoom.interactive-widget: A newer property (e.g., resizes-visual) that specifies how virtual keyboards affect the viewport.Without this tag, mobile devices may render the page at a default width (often around 980 pixels) and scale it down, making text too small to read.
Now, how to write the media-queries inside your CSS-FILE, see below
@media(max-width:768px){box{display:none}} and/or @media(max-width:768px) and (min-width: 999px){box{display:none}}
According to that, for Desktop: @media screen and (min-width: 1024px), for Tablet: @media screen and (min-width: 768px) and (max-width: 1023px) and for Smartphone: @media screen and (max-width: 767px).
Now, from here onwards, I'm also discussing the three-varieties of H.T.M.L.-Elements which is BLOCK, INLINE-BLOCK AND INLINE that is,
Another BOILERPLATE-CODE for STARTING-HTML-DOCUMENT in VS-CODE with EXTERNAL-LINKS overview and you all see the below the said HTML-DOCUMENT-STRUCTURE that is,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<!-- SEO Meta Tags -->
<title>Complete HTML5 Boilerplate</title>
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="stylesheet" href="https://fonts.googleapis.com">
<!-- Bootstrap 5 CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net">
<!-- Font Awesome Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com">
<!-- Animate.css for animations -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com">
<meta name="description" content="A complete HTML5 boilerplate with CDN links.">
<meta name="keywords" content="HTML5, Boilerplate, CSS, JS, CDN">
<!-- Favicon -->
<link rel="icon" href="favicon.ico" type="image/x-icon">
<!-- CSS External Links (CDN) -->
<!-- Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Font Awesome 6 -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Custom CSS -->
<link rel="stylesheet" href="style.css">
<style>
/* Inline CSS for quick styles */
body { font-family: sans-serif; }
</style>
</head>
<body>
<h1 class="text-center mt-5">Hello, World!</h1>
<!-- JavaScript External Links (CDN) -->
<!-- Bootstrap 5 JS Bundle -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<!-- jQuery 3.7.0 (Optional) -->
<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
<!-- Custom JS -->
<div class="container py-5 text-center">
<h1 class="animate__animated animate__fadeInDown">Hello, World! <i class="fas fa-rocket"></i></h1>
<p class="lead">Ready to build something awesome.</p>
<button id="alertBtn" class="btn btn-primary">Click Me</button>
</div>
<!-- jQuery (Optional, but often used with legacy plugins) -->
<script src="https://code.jquery.com"></script>
<!-- Bootstrap 5 Bundle with Popper -->
<script src="https://cdn.jsdelivr.net"></script>
<!-- Axios for API calls -->
<script src="https://cdn.jsdelivr.net"></script>
<!-- GSAP for advanced animations -->
<script src="https://cdnjs.cloudflare.com"></script>
<script>
// Quick check to see if everything is firing
document.getElementById('alertBtn').addEventListener('click', () => {
alert('Boilerplate is live!');
});
</script>
<script src="script.js"></script>
</body>
</html>
Breakdown of Included Elements:
<!DOCTYPE html>: Declares the document as HTML5.
<meta charset="UTF-8">: Ensures proper rendering of characters.
viewport Meta: Ensures responsiveness on mobile devices.
X-UA-Compatible: Ensures compatibility with Internet Explorer.
- CDN Links: Included Bootstrap 5 (UI), Font Awesome (Icons), and jQuery (Scripting).
<body>: Contains the content to be displayed.