Help transform TAbs in accordion on mobile view only

I´m using this tabs i see the code on w3cschools

<button class=“tablink” onclick=“openPage(‘Home’, this, ‘red’)”>Home</button>
<button class=“tablink” onclick=“openPage(‘News’, this, ‘green’)” id=“defaultOpen”>News</button>
<button class=“tablink” onclick=“openPage(‘Contact’, this, ‘blue’)”>Contact</button>
<button class=“tablink” onclick=“openPage(‘About’, this, ‘orange’)”>About</button>

<div id=“Home” class=“tabcontent”>
<p>Home is where the heart is…</p>

<div id=“News” class=“tabcontent”>
<p>Some news this fine day!</p>

<div id=“Contact” class=“tabcontent”>
<p>Get in touch, or swing by for a cup of coffee.</p>

<div id=“About” class=“tabcontent”>
<p>Who we are and what we do.</p>


/* Set height of body and the document to 100% to enable “full page tabs” */
body, html {
height: 100%;
margin: 0;
font-family: Arial;

/* Style tab links */
.tablink {
background-color: #555;
color: white;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
font-size: 17px;
width: 25%;

.tablink:hover {
background-color: #777;

/* Style the tab content (and add height:100% for full page content) */
.tabcontent {
color: white;
display: none;
padding: 100px 20px;


#Home {background-color: red;}
#News {background-color: green;}
#Contact {background-color: blue;}
#About {background-color: orange;}


function openPage(pageName, elmnt, color) {
// Hide all elements with class=“tabcontent” by default */
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName(“tabcontent”);
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = “none”;

// Remove the background color of all tablinks/buttons
tablinks = document.getElementsByClassName(“tablink”);
for (i = 0; i < tablinks.length; i++) {
tablinks[i].style.backgroundColor = “”;

// Show the specific tab content
document.getElementById(pageName).style.display = “block”;

// Add the specific color to the button used to open the tab content = color;

// Get the element with id=“defaultOpen” and click on it

i WOULD LIKE TO TRANSFORM this tabs in accordion menu only on mobile menu is possible?

Sponsor our Newsletter | Privacy Policy | Terms of Service