MOCKSTACKS
EN
Questions And Answers

More Tutorials









CSS Mediatype

Media queries have an optional mediatype parameter. This parameter is placed directly after the @media declaration (@media mediatype), for example:

General Structure of a Media Query

@media print {
 html {
 background-color: white;
 }
}

The above CSS code will give the DOM HTML element a white background color when being printed

The mediatype parameter has an optional not or only prefix that will apply the styles to everything except the specified mediatype or only the specified media type, respectively. For example, the following code example will apply the style to every media type except print.

@media not print {
 html {
 background-color: green;
 }
}

Basic Example

@media screen and (min-width: 720px) {
 body {
 background-color: skyblue;
 }
}

The above media query specifies two conditions:

1. The page must be viewed on a normal screen (not a printed page, projector, etc).

2. The width of the user's view port must be at least 720 pixels.

If these conditions are met, the styles inside the media query will be active, and the background color of the page will be sky blue.

Media queries are applied dynamically. If on page load the conditions specified in the media query are met, the CSS will be applied, but will be immediately disabled should the conditions cease to be met. Conversely, if the conditions are initially not met, the CSS will not be applied until the specified conditions are met.

In our example, if the user's view port width is initially greater than 720 pixels, but the user shrinks the browser's width, the background color will cease to be sky blue as soon as the user has resized the view port to less than 720 pixels in width.


And the same way, for just showing it only on the screen, this can be used:

@media only screen {
 .fadeInEffects {
 display: block;
 }
}


The list of mediatype can be understood better with the following table:

Media Type Description
all Apply to all devices
screen Default computers
print Printers in general. Used to style print-versions of websites
handheld PDA's, cellphones and hand-held devices with a small screen
projection For projected presentation, for example projectors
aural Speech Systems
braille Braille tactile devices
embossed Paged braille printers
tv Television-type devices
tty Devices with a fixed-pitch character grid. Terminals, portables.




Conclusion

In this page (written and validated by ) you learned about CSS Mediatype . What's Next? If you are interested in completing CSS tutorial, your next topic will be learning about: CSS Media Queries for Retina and Non Retina Screens.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.