All media queries for iPhone 13 (Pro, Max, Mini) and older iPhones
For iPhone 12 and 13
iPhone 13 mini
/* 2340x1080 pixels at 476ppi */
@media only screen
and (device-width: 375px)
and (device-height: 812px)
and (-webkit-device-pixel-ratio: 3) { }
This media query is used for: iPhone 13 mini, iPhone 12 mini, iPhone 11 Pro, iPhone Xs, and iPhone X
iPhone 13 and iPhone 13 Pro
/* 2532x1170 pixels at 460ppi */
@media only screen
and (device-width: 390px)
and (device-height: 844px)
and (-webkit-device-pixel-ratio: 3) { }
This media query is used for: iPhone 13, iPhone 12 and iPhone 12 Pro
iPhone 13 Pro Max
/* 2778x1284 pixels at 458ppi */
@media only screen
and (device-width: 428px)
and (device-height: 926px)
and (-webkit-device-pixel-ratio: 3) { }
This media query is used for: iPhone 13 Pro Max and iPhone 12 Pro Max
Older iPhones (X, Xs, XR and 11)
iPhone 11
/* 1792x828px at 326ppi */
@media only screen
and (device-width: 414px)
and (device-height: 896px)
and (-webkit-device-pixel-ratio: 2) { }
This media query is used for: iPhone 11 and iPhone XR
iPhone 11 Pro
/* 2436x1125px at 458ppi */
@media only screen
and (device-width: 375px)
and (device-height: 812px)
and (-webkit-device-pixel-ratio: 3) { }
This media query is used for: iPhone 13 mini, iPhone 12 mini, iPhone 11 Pro, iPhone Xs, and iPhone X
iPhone 11 Pro Max
/* 2688x1242px at 458ppi */
@media only screen
and (device-width: 414px)
and (device-height: 896px)
and (-webkit-device-pixel-ratio: 3) { }
This media query is used for: iPhone 11 Pro Max and iPhone Xs Max
Device orientation
Use the following code to add landscape or portrait orientation:
For portrait:
and (orientation: portrait)
For landscape:
and (orientation: landscape)
Why are iPhone CSS Breakpoints not working
The code was breaking because I used //
to comment instead of /* */
. CSS should technically never use //
to comment anything. I can't believe I overlooked this. I should have known it was something so simple. ♂️ Everything works now across all browsers.
Why do my breakpoints work if I scale down the window but not on mobile?
I you haven't done this already please try to add to the the following line
<meta name="viewport" content="width=device-width, initial-scale=1">
iPhone X / 8 / 8 Plus CSS media queries
iPhone X
@media only screen
and (device-width : 375px)
and (device-height : 812px)
and (-webkit-device-pixel-ratio : 3) { }
iPhone 8
@media only screen
and (device-width : 375px)
and (device-height : 667px)
and (-webkit-device-pixel-ratio : 2) { }
iPhone 8 Plus
@media only screen
and (device-width : 414px)
and (device-height : 736px)
and (-webkit-device-pixel-ratio : 3) { }
iPhone 6+/6s+/7+/8+ share the same sizes, while the iPhone 7/8 also do.
Looking for a specific orientation ?
Portrait
Add the following rule:
and (orientation : portrait)
Landscape
Add the following rule:
and (orientation : landscape)
References:
- https://webkit.org/blog/7929/designing-websites-for-iphone-x/
- https://developer.apple.com/ios/human-interface-guidelines/visual-design/adaptivity-and-layout/
- https://developer.apple.com/ios/human-interface-guidelines/overview/iphone-x/
- https://mydevice.io/devices/
- http://viewportsizes.com/mine/
CSS media queries doesn't reflect the device screen size
You could make this change in your index.html - This is the one I would say is likely to be the issue for you
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0"/>
Or you could try this change in your CSS
@media screen and (max-device-height: 811px) {
}
Broken responsive design (on iPhone only) - can media queries be forced with javascript?
I use below code to load CSS & JS files based on device type, also try setting maximum-scale,user-scalable and height in viewport tag-
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, height=device-height"/>
function loadDeviceSpecificFiles() {
if (navigator.userAgent.toLowerCase().match(/android/)) {
loadjscssfile("and_filename.js", "js"); //dynamically load JS
loadjscssfile("and_filename.css", "css") //dynamically load css
/*iPhone check*/
} else if (navigator.userAgent.toLowerCase().match(/iphone/) || navigator.userAgent.toLowerCase().match(/ipad/)) {
loadjscssfile("ios_filename.js", "js") //dynamically load JS
loadjscssfile("ios_filename.css", "css") //dynamically load css
}
}
function loadjscssfile(filename, filetype) {
if (filetype == "js") { //if filename is a external JavaScript file
var fileref = document.createElement('script')
fileref.setAttribute("type", "text/javascript")
fileref.setAttribute("src", filename)
} else if (filetype == "css") { //if filename is an external CSS file
var fileref = document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
}
if (typeof fileref != "undefined") document.getElementsByTagName("head")[0].appendChild(fileref)
}
Related Topics
What Is the Right Combination of Prefixes for CSS Transitions and Transforms
Bootstrap Modal Window Inside Another Div
How to Display a List in Two Rows
Adding CSS File to Stylesheets in Javafx
How to Use Media Queries in CSS
Set a Variable in SASS Depending on the Selector
What Is the Purpose of Flex-Start and Flex-End on Justify-Items and Justify-Self
CSS Alternative for Display:Box for Ie and Opera
Jekyll Site Works Locally But Not on Github Pages
How to Create a Responsive Checkerboard Background in CSS
Switching to Em-Based Media Queries
How to Convert .Svg Files to a Font
CSS Selectors Ul Li a {...} VS Ul > Li > a {...}
Bootstrap 3 Changing Div Order on Small Screens Only