What is a CSS3 media query? CSS3 media query is used to create responsive web pages. If we want to create a responsive design for our laptop, tablet, and mobile then we can apply the CSS3 media query rule on our web page.
If you have some knowledge of the device width range. Then you can easily create responsive web layouts by using the code given below.
<style>
@media screen and (max-width:480px){
property: value;
property: value;
property: value;
}
</style>
Note: please do not use container width greater than the max-width of a media query and always try to use width percentage(%) unit.
<head>
<style>
h1{color:green}
@media screen and (max-width:300px){
h1{color:red}
}
</style>
</head>
<body>
<h1>@media-query</h1>
</body>
When we use min-width then the code inside the @media rule is used for the screen width is greater than that min-width value. We can see the example of @media min-width below.
<style>
@media screen and (min-width:500px){
property: value;
property: value;
property: value;
}
</style>
<head>
<style>
h1{color:green}
@media screen and (min-width:400px)
{
h1{
color:red
}
}
</style>
</head>
<body>
<h1>
@media-query
</h1>
</body>