The functionality of aria-expanded is not functioning properly when set to false

Having trouble with the bootstrap accordion feature.
When the page loads, the accordions are expanded by default instead of being collapsed.
I want them to start collapsed and then expand when clicked.
Here is the HTML code:

<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>bootstrap accordion</title>
  <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.css'><link rel="stylesheet" href="./style3.css">
  <link href="https://fonts.googleapis.com/css?family=Open+Sans&display=swap" rel="stylesheet"> 
  <link href="https://fonts.googleapis.com/css?family=Montserrat|Tomorrow&display=swap" rel="stylesheet"> 
</head>
<body>
<!-- partial:index.partial.html -->
<section class="container">
  <div id="accordion" class="accordion-container">
    <div class="card">
      <div class="card-header" id="headingOne">
        <h5 class="mb-0">
          <button id="radio" class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
          aaaa
          </button>
        </h5>
      </div>

      <div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
        <div class="card-body">
         <p id="forward">aaaabooooody</p>
        </div>
      </div>
    </div>

      </div>

       <div id="accordion" class="accordion-container">
    <div class="card">
      <div class="card-header" id="headingOne">
        <h5 class="mb-0">
          <button id="radio" class="btn btn-link" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
          bbbbbbb
          </button>
        </h5>
      </div>

      <div id="collapseTwo" class="collapse show" aria-labelledby="headingTwo" data-parent="#accordion">
        <div class="card-body">
         <p id="forward">bbbbbbbbblaankkkk</p>
        </div>
      </div>
    </div>

      </div>



</section>
<!-- partial -->



  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/js/bootstrap.min.js'></script>
</body>
</html>


//////CSS CODE BELOW

.accordion-container .card .card-header button.btn:after {
  -webkit-transition: all 0.5s ease-in-out;
  -moz-transition: all 0.5s ease-in-out;
  -ms-transition: all 0.5s ease-in-out;
  transition: all 0.5s ease-in-out;
}
.accordion-container .card .card-header {
  position: relative;
  background-color: #00d2ff;
}
.accordion-container .card .card-header .btn-link {
  color: #FFF;
  font-family: 'Montserrat', sans-serif;
  font-size: 28px;
  /*font-weight: 600;*/
  line-height: 23px;
}
.accordion-container .card .card-header button.btn.collapsed:after {
  background-image: url();
}
.accordion-container .card .card-header button.btn:not(.collapsed):after {
  background-image: url();
}
.accordion-container .card .card-header button.btn-link {
  width: 100%;
  text-align: left;
}
.accordion-container .card .card-header button.btn:after {
  content: '';
  background-repeat: no-repeat;
  background-position: 50%;
  width: 3rem;
  height: 3rem;
  text-align: center;
  float: right;
  padding: .7rem;
  border: 1px solid #ffff;
  border-radius: 50%;
}
.accordion-container .card .card-header button.btn.collapsed:after {
  background-color: rgba(255, 255, 255, 0.31);
}
.accordion-container .card .card-header button.btn:not(.collapsed):after {
  background-color: white;
}
.accordion-container .card .card-header button.btn-link:not(.collapsed)::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: #FFF;
  opacity: .31;
}
.accordion-container .card .card-body {
  color: white;
  background-color:  #FFF;
  color: #000000;
  font-family: 'Open Sans', sans-serif;
  font-size: 18px;
  font-weight: 300;
  line-height: 19px;
}

This is what I expected on page load: https://i.stack.imgur.com/nPpSe.png
But this is what I'm seeing initially: https://i.stack.imgur.com/Mun1p.png

Answer №1

To make it function as intended, update the class="collapse show" to class="collapse".

Additionally, consider exploring this resource on the aria-expanded html attribute

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Develop a chart featuring sub-categories and column headings

I'm in the process of creating a table with subcategories and headers that resembles the image provided below: Here's what I've come up with so far: <table> <thead> <tr> <th>Item</th> & ...

refresh-free form clearing

Currently, I am working on a form that includes Recaptcha validation using jQuery. The form is functioning well as the information is sent to my email and all required fields are checked before submission. However, there is one issue that I am encounterin ...

Issue with $.ajax() functionality persists across all browsers except for Firefox

Whenever the page loads, a small script I have retrieves rental dates. Additionally, if the user selects a different month from the drop down, new dates are also fetched. Unfortunately, the site is using jQuery 1.2.3 and I'm unable to update to 1.4 d ...

Issues with interpreting PHP within HTML documents

I'm having trouble using PHP on my HTML page. I've added AddType application/x-httpd-php .html to the .htaccess file as recommended, but when I try to access the page in a browser, a dialog box pops up asking if I want to save the file or open it ...

Exploring numerical elements in interactive content

Struggling with the Wikipedia API and encountering issues with the results that are returned. {"query":{ "pages":{ "48636":{ "pageid":48636, Concerned about how to access a specific ID (such as 48636) without knowing it in advance ...

Horizontal Scroll HTML

Currently in the process of building a website for my father, everything is going smoothly. I followed a helpful Stackoverflow tutorial to create a specific webpage that I now want to customize with a hyperlink and make it scroll horizontally: Sliding divs ...

Displaying elements side by side on larger screens and centered on smaller screens

Is there a way to arrange elements next to each other on wider screens, aligning them left and right, while also centering one above the other on narrower screens? Preferably without using media queries: ...

When using jQuery to focus on an input element, the cursor fails to show up

Looking to enhance user experience by focusing on an input element upon clicking a specific div. The HTML structure being used is as follows: <div class="placeholder_input"> <input type="text" id="username" maxlength="100" /> <div ...

If the value of the input matches, set the checkbox to be

I have successfully implemented functionality that allows the value of an input to be changed by clicking a checkbox. This works without any issues. Now, I am facing the challenge of automatically checking the checkbox when the page loads, but only if the ...

Link the parameters of two polymer elements within a repeat template

In this scenario, my goal is to securely bind attr and attr1. These two variables should be independent from the variable data, unlike other attributes in use. I want each iteration to have its own set of bound components, rather than sharing one data obje ...

Transferring Visitor's Country Code Between Two Web Applications Using .NET Framework (ASP/MVC)

I'm currently working on developing an application that collects user information such as country, city, and IP address of the website they're visiting. This data is then sent to another web application of mine, which will be automatically update ...

Creating a text input that spans the full width of the form in a Bootstrap

I'm having trouble creating a text box that spans the entire width of my container. <div class="row"> <div class="col-md-12"> <form class="form-inline" role="form"> <input type="text" class= ...

Text that is curving around a D3.js pie chart

I am currently working on creating a 3D-Js chart and I would like the pie text to wrap around the pie itself. This is the exact effect that I am trying to achieve: I am facing two main issues: I am currently printing two separate charts (with labels prin ...

Executing a script on a different HTML page without the need to reload it

I'm currently working on incorporating a notification system inspired by Facebook's design. This system will feature an icon in the header that, when clicked, reveals a drop-down containing a table of sorted notifications for the user. My goal is ...

Arranging elements and buttons inside of components to create a cohesive design

My React application consists of two components: Open and Save. The Save component has a button labeled as saveButton. On the other hand, the Open component contains an openButton, as well as a stopButton and executeButton that are conditionally displayed ...

Issues with ontimeupdate event not triggering in Chrome for HTML5 audio files

After creating an HTML5 audio element and setting a listener for when its time updates, I have run into an issue where the ontimeupdate function does not fire in Chrome, including Chrome on Android. The audio plays without any issues in other browsers. va ...

Navigation bar in HTML positioned on the right side of the webpage

My goal is to have a navigation bar on the right side of the page, taking up 250px, while allowing the main content to naturally adjust its size based on the window dimensions. I do want the main content to appear before the navigation in the HTML structur ...

css how to style a table row with a specific identifier

Although this question has been asked millions of times on the internet, my English skills are not great and I struggle to find the right words to search. I have a table with a specific ID set up like this: <table class="tableClass"> <tr id="one ...

"Enforce a specific height on a div that is exclusively showing a background

I have been trying to use a div element to showcase a specific color, where the background color acts as the content. However, no matter what height or width settings I input, I am unable to achieve the desired size for the div. Even after experimenting w ...

Utilizing jQuery UI datepicker as a fallback in absence of HTML5 native date input type

Although <input type="date"> is not commonly used for desktop, it is the preferred method for mobile devices. I am attempting to incorporate the fallback code located at the end of this section: <form> <input type="date"> </form&g ...