Collapsible headers in articles (accordions) - how to put + on the left instead of on the right? | Community
Skip to main content

Collapsible headers in articles (accordions) - how to put + on the left instead of on the right?

  • January 30, 2024
  • 2 replies
  • 0 views

I followed Trapta Singh's very good instructions about how to create a collapsible header. However, the first question is fairly short, and the + on the far right is not immediately obvious. Can I move it to the left? 

2 replies

  • January 30, 2024

Hey @sharon16


It should be possible to adjust the position of the collapsible headers to be on the right instead of the left by modifying the CSS for the .accordion class and the .accordion:after pseudo-element. Here's how you can adjust the code:

.accordion {
  background-color: #eee;
  color: #444;
  cursor: pointer;
  padding: 18px;
  width: 100%;
  border: none;
  text-align: right; /* Align text to the right */
  outline: none;
  font-size: 15px;
  transition: 0.4s;
  margin-bottom: 10px;
}

.accordion p {
  display: inline;
}

.active, .accordion:hover {
  background-color: #ccc;
}

.accordion:after {
  content: '\002B'; /* Unicode character for '+' sign */
  color: #777;
  font-weight: bold;
  float: left; /* Float the '+' sign to the left */
  margin-right: 5px; /* Add right margin instead of left */
}

.active:after {
  content: "\2212"; /* Unicode character for '-' sign */
}

.panel {
  padding: 0 18px;
  background-color: white;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease-out;
}

In the .accordion class, I changed text-align: left; to text-align: right; to align the text to the right side of the accordion header.

In the .accordion:after pseudo-element, I changed float: right; to float: left; to position the '+' sign to the left of the text. Additionally, I replaced margin-left: 5px; with margin-right: 5px; to add spacing on the right side of the '+' sign.


  • Author
  • January 30, 2024

Thank you, Kuba! That worked perfectly!