How To Add Media Query In WordPress

Rock WPHow toHow To Add Media Query In WordPress

WordPress is a popular content management system (CMS) used to create websites of various types. It is user-friendly and comes with many features that allow web developers to customize their websites to their liking. One such feature is media queries, which allow the website to adapt its layout and design based on the size of the user’s screen. In this article, we will explore how to add media queries in WordPress.

Media queries are added to the style.css file of the WordPress theme. This file contains the CSS rules that dictate the appearance of the website. To add media queries, follow these steps:

Theme File Editor

Open the WordPress dashboard and go to Appearance > Theme File Editor.

Theme File Editor

style.css file

In the right-hand panel, click on the style.css file.

style.css file

Add the code

Scroll down to the bottom of the file and add the following code:

@media screen and (max-width: 768px) {

/* CSS rules for screens smaller than 768px */ }

The above code is an example of a media query that targets screens smaller than 768px in width. You can customize the code to target different screen sizes or devices.

Add the code

Click save

Save the changes.


Adding media queries in WordPress is a simple process that allows web developers to make their websites more responsive and user-friendly. With media queries, the website can adjust its layout and design to fit different screen sizes and devices, providing a seamless user experience. By following the steps outlined above, web developers can easily add media queries to their WordPress themes and improve the functionality and design of their websites.

Things To Consider When Adding Media Query In WordPress

There are a few things that web developers should consider when adding media queries in WordPress. Here are some important points to keep in mind:

Mobile-First Design: With the increasing use of mobile devices, it is important to design websites with a mobile-first approach. This means that the website should be optimized for mobile devices first and then scaled up for larger screens. When adding media queries, it is recommended to start with the mobile layout and then add breakpoints for larger screens.

Breakpoint Consideration: When adding media queries, it is important to consider the different devices and screen sizes that the website will be viewed on. The breakpoints should be carefully chosen to ensure that the website looks good and functions well on all devices.

CSS Optimization: Adding too many media queries can result in a lot of CSS code, which can slow down the website’s loading time. To avoid this, web developers should try to keep the number of media queries to a minimum and optimize the CSS code for better performance.

Browser Compatibility: Not all browsers support media queries, so it is important to test the website on different browsers to ensure that the media queries are working as intended. Web developers can use browser developer tools to test the website on different screen sizes and devices.

By considering these important points, web developers can effectively add media queries in WordPress and create responsive websites that look and function well on all devices.

Help improving: How To Add Media Query In WordPress

Do you have questions, comments or feedback about this topic? Share your voice below!

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments

Looking for Cheaper & Better Hosting?

Save big and boost your site with affordable, superior WordPress hosting!

Compare Hosting Deals

Related Stories