Media Queries
Media queries
Media queries are used when we want to customize our website's presentation according to
the user's screen size. With the help of media queries, you can display different markups
based upon the device's general type(mobile, desktop, tablet).
A media query is a logical operation. Whenever a media query becomes true, then the related
CSS is applied to the target element.
Media queries
Media queries can be used to check many things, such as:
• width and height of the viewport
• width and height of the device
• orientation (is the tablet/phone in landscape or portrait mode?)
• resolution
Syntax :
@media media-type and (media-feature)
{
/* CSS Rules to be applies*/
}
Media queries
Media queries example:
@media screen and (max-width: 800px)
{
#box2 {
background-color: black;
}
}
• @media: A media query always starts with @media.
• Screen: It is the applicable media type.
• max-width: It is the media feature.
• (background-color: black) : It is the CSS to be applied when the conditions
are met. Now, we will spend some time understanding how to use media queries on a
website.
Media features
Media features describe specific characteristics of the user agent, output device, or environment.
Media feature expressions test for their presence or value, and are entirely optional. Each media
feature expression must be surrounded by parentheses. .
• Hover
• color
• Device-height
• Device-width
• Display-mode
• Grid