Junior
What needs to be specified in CSS to configure and apply these breakpoints?
sobes.tech AI
Answer from AI
The media query @media is used. Inside it, conditions are set for applying styles based on device characteristics or viewport area.
Main parameters of media queries:
width/height: Width/height of the viewport.min-width/min-height: Minimum width/height of the viewport.max-width/max-height: Maximum width/height of the viewport.orientation: Device orientation (portraitorlandscape).
Example of usage for setting breakpoints:
/* Default styles for screens smaller than 768px */
body {
font-size: 16px;
}
/* Breakpoint for screens from 768px to 991px */
@media (min-width: 768px) and (max-width: 991px) {
body {
font-size: 18px;
}
}
/* Breakpoint for screens 992px and above */
@media (min-width: 992px) {
body {
font-size: 20px;
}
}
Common strategies for setting breakpoints:
- Mobile First: Styles are first set for the smallest screens, then media queries with
min-widthare added for larger screens. - Desktop First: Styles are first set for larger screens, then media queries with
max-widthare added for narrower screens.
The choice of strategy depends on the project and preferences.
Standard breakpoint values (approximate, depending on framework or agreement):
| Device | Width range | Media query (Mobile First) | Media query (Desktop First) |
|---|---|---|---|
| Small phones | < 576px | Not used (base styles) | @media (max-width: 575.98px) |
| Phones | >= 576px | @media (min-width: 576px) |
@media (max-width: 767.98px) |
| Tablets | >= 768px | @media (min-width: 768px) |
@media (max-width: 991.98px) |
| Laptops | >= 992px | @media (min-width: 992px) |
@media (max-width: 1199.98px) |
| Desktops | >= 1200px | @media (min-width: 1200px) |
@media (max-width: 1399.98px) |
| Large desktops | >= 1400px | @media (min-width: 1400px) |
Not used (base styles) |
It is important to choose breakpoints based on content and layout, not device standards. They should trigger where the layout begins to 'break'.