Contents:

Course with employment: “Profession Front-end Developer"
Learn moreWhen designing a web page, it's important to consider that users will view it on a variety of devices, including smartphones, tablets, laptops, desktop computers, and even TVs. This requires the use of responsive design, which will ensure optimal content display on screens of any size. A proper approach to creating a multi-screen interface will help improve user experience and increase website conversion. Responsive design also has a positive impact on SEO, as search engines prefer websites that display correctly on all devices.
Formatting website content for different screens is accomplished using media queries in CSS. These media queries allow you to adapt the style and structure of a web page to different devices, such as mobile phones, tablets, and desktop computers. Using media queries significantly simplifies the responsive design process, allowing you to minimize changes to the HTML code and focus on the visual perception of the content. This makes the website more user-friendly and accessible, regardless of the device they use.
Content is a crucial element of any page, as it helps users quickly find the information they need. Proper structure and clarity of presentation contribute to better comprehension and increased uniqueness of the text. For search engine optimization, it's important to use keywords that match the content's topic. This not only improves the page's visibility in search results but also makes the text more relevant to users. Furthermore, it's worth considering that high-quality content increases the time visitors spend on the site, which also positively impacts its ranking. Developing informative and useful content should be the focus when creating web pages.
- What are media queries?
- Syntax
- @media
- @import
- HTML tags
- Viewport meta tag
- Browser support
- What conditions can be specified in a media query?
- Device types
- Media features (characteristics)
- Logical operators
- and
- or and ,
- not
- only
- Grouping brackets
- Summary
What are CSS media queries are an essential tool for responsive web design. They allow you to change the style of a web page based on the characteristics of the user's device, such as screen width and height, pixel density, and supported colors. Using media queries, developers can create a more user-friendly and attractive interface that ensures optimal content display on a variety of devices, from mobile phones to desktop computers. This improves user experience and contributes to higher search engine rankings. Proper use of CSS media queries is a key aspect of modern web development and plays a significant role in SEO optimization.
Media queries are conditions that are applied to CSS styles. If a specified condition is met, the style is activated; otherwise, it is ignored. This allows you to create multiple styles with different conditions for different situations. For example, media queries can be configured for different user screen widths: less than 320 pixels, from 320 to 720 pixels, from 720 to 1024 pixels, and more than 1024 pixels. Using media queries makes web design more responsive and improves the user experience across devices.
Media queries are a simple and effective adaptive layout tool that significantly simplifies the process of creating responsive web designs. Unlike more complex methods such as CSS Grid, learning media queries is quick and easy. Knowing the basic syntax of CSS, you can master them in as little as half an hour. Furthermore, media queries can be successfully combined with CSS Grid, enabling more complex and flexible content display schemes across devices. This makes media queries an indispensable tool for web developers looking to create modern and responsive websites.

Learn also:
CSS Grid Layout Tutorial
CSS Grid is a powerful tool for creating modern and responsive web pages. In this guide, we'll take a detailed look at the basic principles of CSS Grid, its benefits, and usage examples.
CSS Grid allows you to easily organize page elements in a grid, greatly simplifying the layout process. Using this method, you can create complex layouts that will display correctly on a variety of devices.
The basic concepts of CSS Grid include creating a Grid container, defining rows and columns, and placing items within the grid cells. Using the grid-template-rows and grid-template-columns properties, you can set the sizes of rows and columns, while grid-area allows you to control the placement of individual items.
The benefits of using CSS Grid include simplified code, increased flexibility, and the ability to easily adapt the layout to different screen resolutions. This makes CSS Grid an ideal choice for developers looking to create usable and attractive web interfaces.
In conclusion, learning CSS Grid will open new horizons in web development and enable you to create effective and modern layouts. Start using CSS Grid in your projects and improve the quality of your layout.
The Skillbox Media website uses media queries, which allow the design to adapt depending on the screen size. For example, when you zoom in on a page, you can see changes in the layout and content structure, improving the user experience across different devices. Media queries play a key role in creating responsive web designs, allowing a website to look attractive and usable on both desktops and mobile devices.


When scaling the web page, you can see that the empty space between elements decreases, and the side menu is hidden behind the drop-down button and then disappears completely. Such layout changes can be effectively implemented using media queries. Media queries allow you to adapt your website design to different screen sizes, ensuring ease of use and improving the user experience. Proper use of media queries helps create a responsive and modern interface that meets the needs of modern users.
Syntax
Media queries are used to adapt web content to different devices and screens. They allow you to change CSS styles depending on device characteristics, such as screen width, orientation, and resolution. This ensures optimal display of the site on mobile phones, tablets, and desktop computers.
Using media queries, you can change font sizes, rearrange elements, and hide or show certain content blocks. This not only improves the user experience but also helps improve SEO positions, as responsive design is an important ranking factor in search engines.
Proper use of media queries will help you create a modern and functional website that will be convenient for users on any device.
- in CSS @media and @import rules;
- in HTML tags
Browser Support
There are currently two main versions of media queries actively used in web development: Level 3 and Level 4. These versions are supported by all popular modern browsers, ensuring high compatibility and stability in responsive layout. Although Level 5 also exists, it is still under development and is not widely available. Using media queries of different levels allows developers to create more flexible and optimized websites that adapt to different devices and screen resolutions.
Level 3 is supported by many outdated browsers, but Level 4 introduces new media features, including the ability to customize the screen refresh rate. This expanded functionality allows developers to create more responsive and modern web applications that provide an improved user experience. With support for new media features, Level 4 is becoming an important tool for optimizing content for various devices and their characteristics.
The difference in browser support levels is insignificant and within the margin of error. According to Can I use, as of July 2023, Level 3 support is 98.29% among all browsers used by internet users, while Level 4 support is 96.15%. These statistics demonstrate high compatibility between both levels, which is important to consider when developing and optimizing web content.


What conditions can be specified in a media query
There are two main types of conditions that can be used in media queries. These conditions allow you to adapt the style of a web page depending on the characteristics of the device it is displayed on. The first type is conditions based on the width and height of the screen, which allows you to change the design depending on the size of the browser window. The second type of conditions is the use of media features, such as pixel density or screen orientation, which allows you to more precisely customize the display of content for different devices. Correct use of media queries improves the user experience and contributes to better optimization of the site for mobile and desktop devices.
- device type - is responsible for fundamentally different ways of consuming content;
- media features - are responsible for the technical characteristics of the device.
Media queries classify the devices through which websites can be accessed into four main categories. These categories help developers adapt content to different screen sizes and resolutions, ensuring an optimal user experience. Using media queries allows you to create responsive web designs that more effectively respond to changes in devices, whether mobile phones, tablets, or desktop computers. This is especially important in today's digital world, where the diversity of devices continues to grow. Correct use of media queries improves SEO, as search engines prefer sites that provide usability and accessibility on all platforms.
- all — all devices;
- screen — devices with screens;
- print — devices in print preview mode;
- speech — screen readers.
The syntax for the formatting is represented as follows (using devices with screens as an example):
The second way to specify conditions in media queries is to specify device or browser characteristics, such as window width, device orientation, and other parameters. This allows for more precise adaptation of styles to different devices, ensuring optimal display of content on mobile and desktop screens. Using these conditions in media queries is an important element of responsive web design, improving the user experience and boosting a site's SEO ranking.
Some features allow you to set minimum and maximum values, using the prefix min- to denote the minimum value and max- to denote the maximum.
Media features are denoted using parentheses. For example:
The list of current media features compatible with browsers that support both Level 3 and Level 4 includes the following:
This section presents a list of media features implemented in Level 4. These features significantly expand the capabilities for working with multimedia content and improve the user experience. Level 4 includes the latest technologies that allow for more efficient processing and playback of audio and video, ensuring high quality and ease of use. Explore the full list of media features to better understand how they can be applied in various projects and improve user experience.
Logical Operators
The application of various styles in web design often depends on a variety of factors. For example, if you want to set a minimum and maximum width for a screen, you can do so using CSS. Setting these parameters helps create a responsive design that will display correctly across different devices. Proper use of minimum and maximum widths ensures that content remains readable and aesthetically pleasing, regardless of screen size.
In situations like these, each query condition is enclosed in separate parentheses, with logical operators placed between them. This helps keep the query clearly structured and easier to understand. Proper use of parentheses and logical operators significantly improves the efficiency of data processing and simplifies the analysis of results.
Let's look at these operators and learn how to use them correctly.
The and operator functions like a logical «AND». The query will only be executed if all conditions are true. For example, in the case below, the style will be applied when the browser window width is greater than 480 px and less than 1024 px. This means that the style will work in the range between these values. Using the and operator allows for more precise styling for different screen sizes, ensuring responsiveness and improving user experience.
The or operator functions like a logical OR in media queries. The query result will be true if at least one of the specified conditions is met. In the following example, the style will be applied if the query specifies an input device, regardless of whether it is precise or imprecise.
In media queries level 4, it is acceptable to use a comma to combine conditions instead of the or operator. This simplifies the syntax and makes the code more readable. The comma is used to specify multiple conditions under which styles will be applied. This approach improves the structure of media queries and makes them easier to maintain in the future. Using the comma in media queries level 4 is an effective way to optimize CSS and improve its performance.
The not operator functions as a logical negation. It is used to invert the value of a logical expression. For example, if the expression is true, applying the not operator will make it false, and vice versa. This allows for effective management of logical conditions in programming and mathematics. Using the not operator helps create more complex logical constructs and improves code readability.
The only operator is used to improve compatibility with legacy browsers that do not support CSS3 syntax and may incorrectly interpret styles written in accordance with the CSS2 standard. This ensures that web pages display correctly across various devices and browsers, minimizing the possibility of content rendering errors. Using the only operator helps developers ensure that their websites will look and function as intended, regardless of the browser version used by the user.
An outdated browser will only be able to interpret CSS code up to the first space after @media screen. This means that the styles will apply to all devices with screens, and not just those with a viewport width greater than 480 pixels, which does not meet our requirements. To avoid this problem, it is important to use correct media queries that will ensure that content displays correctly across various devices.
Adding the only operator to a CSS media query causes the browser to process only the styles that come after it. Therefore, if you use @media only, the browser will not apply the specified styles if the media query condition is not met. This allows for more precise control over styles for different devices and screens, eliminating unnecessary rules for specific device categories.
When using the "only" operator, a specific device type must be specified. For example, this could be mobile devices, tablets, or desktop computers. This approach allows for more precise style customization and adapts content to different screens, improving the user experience and increasing the performance of the web page. Proper implementation of media queries with the "only" operator helps optimize the loading and display of the site on different devices, which is an important aspect of modern web design.
To control the order of logical operators in queries, it is recommended to use grouping parentheses. This clearly defines which operations should be performed first, significantly simplifying the interpretation and processing of queries. Proper use of parentheses will ensure more accurate results and improve the efficiency of working with data.
Summary
- Media queries are a responsive design tool that can be used in both CSS and HTML code.
- Media queries allow you to request the device type and characteristics from the user. If the received data matches the expected values, then the formatting is applied.
- If several conditions must be met for one style, they can be combined using logical operators: or, comma, and, not, and only.
Read also:
- What a layout designer should be able to do and how to improve your skills: instructions for beginners
- Start front-end development at 12, win an IT championship at 13: the story of Ali Suleimanov
- How to correctly layout HTML tables

