Introduction
Breakpoints help your website look good on different screen sizes like phones, tablets, and computers.
Jump into concepts and practice - no test required
Breakpoints help your website look good on different screen sizes like phones, tablets, and computers.
@media (condition) { /* CSS rules here */ }
@media to start a breakpoint rule.max-width or min-width define when the styles apply.@media (max-width: 600px) { body { background-color: lightblue; } }
@media (min-width: 601px) and (max-width: 1024px) { body { font-size: 1.2rem; } }
@media (min-width: 1025px) { body { font-size: 1.5rem; } }
This page changes background color and font size depending on the screen width using breakpoints.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Breakpoints Example</title> <style> body { font-family: Arial, sans-serif; background-color: white; color: black; margin: 2rem; font-size: 1rem; } @media (max-width: 600px) { body { background-color: #d0f0fd; font-size: 1.2rem; } } @media (min-width: 601px) and (max-width: 1024px) { body { background-color: #f0e68c; font-size: 1.4rem; } } @media (min-width: 1025px) { body { background-color: #90ee90; font-size: 1.6rem; } } </style> </head> <body> <h1>Welcome to Responsive Design</h1> <p>Resize the browser window to see the background color and font size change.</p> </body> </html>
Always include the viewport meta tag for breakpoints to work well on mobile devices.
Use relative units like rem for font sizes to keep scaling consistent.
Test your breakpoints by resizing your browser or using device simulation in browser DevTools.
Breakpoints let you change styles based on screen size.
Use @media with conditions like max-width or min-width.
They help make websites look good on phones, tablets, and desktops.
body have on a screen width of 700px?@media (max-width: 600px) { body { background: red; } } @media (min-width: 601px) { body { background: blue; } }@media screen and max-width: 800px { body { font-size: 1.2rem; } }