LESSON 8.3
Showing Different Content on Mobile
Show a different version of your page depending on the device
Learn how to combine display: none with media queries to show desktop-only or mobile-only content, and how to stack columns on smaller screens.
💡 The Concept
The ability to show or hide content on mobile lets you tailor the experience for phone users without building a separate site. One of the most powerful techniques in responsive design is showing completely different content depending on screen size. You can create a full desktop version of a section and a simplified mobile version, then use media queries and display: none to show only the right one.
Hiding Elements on Mobile
Combine display: none with a media query to remove elements entirely on smaller screens:
@media (max-width: 768px) {
.sidebar {
display: none;
}
}
Showing Two Different Versions
The real trick is having two separate versions of an element and toggling which one is visible. This lets you show a detailed desktop version and a simpler mobile version without writing complicated CSS overrides:
<!-- Desktop version: hide on mobile -->
<div class="desktop-only">
<img src="large-banner.jpg" alt="Banner" />
<p>Read our full story...</p>
</div>
<!-- Mobile version: hide on desktop -->
<div class="mobile-only">
<p>Short version for mobile.</p>
</div>
.mobile-only {
display: none;
}
@media (max-width: 768px) {
.desktop-only {
display: none;
}
.mobile-only {
display: block;
}
}
On desktop, .mobile-only is hidden. Inside the media query, .desktop-only gets turned off and .mobile-only gets turned on. Only one version is ever visible at a time.
🎬 The Video
This video demonstrates how to use media queries with display: none to show different content on mobile.
Let’s Do It
Step 1. Open JSFiddle.
Step 2. Create two h1 tags with different text. We want to use the longer title “Beautiful Sunsets” on larger devices, but simply use the title “Sunsets” on smaller devices.
Step 3. Add a class of “mobile” to one and a class of “desktop” to the other.
Step 4. Using display:none and display:block, make one appear on smaller devices and the other on larger devices. Use 400px for the breakpoint.
💡 Why 400px instead of 768px? On a real website you would usually switch to mobile styles around 768px. JSFiddle’s result panel is already narrow, so a smaller breakpoint like 400px lets you drag the panel back and forth and clearly see the title switch.
Check your work in JSFiddle. Resize the browser box so you can see the <h1> switch.

❓ Frequently Asked Questions
When you use display: none, the element is completely removed from the rendered page. Screen readers skip it and it takes up no space. That is fine for hiding a duplicate or decorative element, but never hide something a mobile visitor still needs. When you provide a desktop version and a mobile version, keep the essential information in both so every visitor gets it. Swapping content this way for responsive design is a normal, accepted practice, so search engines will not penalize you as long as both versions cover the same content.
Sometimes a single element only needs a small CSS adjustment, like a smaller font size on a phone. But when the desktop and mobile experiences are genuinely different, such as a large image with a long description on desktop versus one short line of text on mobile, it is cleaner to build two separate elements and toggle which one shows. This avoids piling up complicated overrides and keeps each version easy to read and maintain.
The traditional breakpoints are 768px and under for smartphones and 1024px and under for tablets. These are a solid starting point, but the best approach is to design for every screen size, not just two or three. When you test your site, watch for the points where your own layout starts to break, and do not hesitate to add more breakpoints wherever they are needed. In this lesson’s exercise we used 400px only because it makes the title switch easy to see inside JSFiddle’s narrow preview panel.
★ Key Takeaways
Responsive design is about more than just resizing elements. This lesson showed you how to show or hide different content depending on the screen size using CSS. Coming up is HTML Tables, where you will learn when and how to use tables to display structured data. Tables are great for schedules, pricing charts, and comparison layouts.
Google Ads
The costs of this website are partially offset by revenue from Google Ads.Tools of the Trade
HTML/CSS Lessons
-
-
-
1.3. HTML Tag Preview
-
-
-
2.2. The HTML Framework
-
-
2.4. HTML Headings
-
-
-
-
-
-
3.01. Introduction to CSS
-
3.02. How CSS Cascades
-
-
-
-
3.05. CSS Colors
-
3.06. RGBA Colors
-
-
3.08. Font and Text Properties
-
3.09. Classes and IDs
-
-
-
-
-
4.3. HTML Embedded Images
-
-
-
-
-
-
5.1. CSS Borders
-
5.2. CSS Border Radius
-
5.3. CSS Gradients
-
5.4. CSS Box Shadows
-
5.5. CSS Text Shadows
-
7.1. The Display Property
-
-
-
7.4. The Box Model
-
-
-
-
-
-
9.1. Website Tables
-
9.2. HTML Forms
-
-
9.4. Special Form Fields
-
9.5. Embedding Multimedia
-
-
9.7. Keyboard Shortcuts
-
10.1. What Is a Framework?
-
10.2. Font Awesome Icons
-
-
10.4. Bootstrap Grid System
-
-
10.6. Bootstrap Navigation
-
-
11.2. Purchasing a Domain Name
-
11.3. Website Hosting
-
11.4. Nameservers and DNS
-
11.5. FTP
-
11.6. GitHub Pages
