Home > Designing, Others > Creating a Details Element That Opens But Never Closes

Creating a Details Element That Opens But Never Closes

February 15th, 2020 Leave a comment Go to comments

The

and

elements in HTML are useful for making content toggles for bits of text. By default, you see the

element with a toggle triangle (??) next to it. Click that to expand the rest of the text inside the

element.

But let’s say you want to be able to click it open and that’s that. Interactivity over. I saw this used in one of those “Read more” article designs, where you click that “Read more” button and the article expands, but there is no going back.

I’ll preface this by saying that I’m not sure that this is a great idea in general. Removing controls just doesn’t feel great, nor does slapping too much important content within a

element. But, hey, the web is a big place and you never know what you might need. The fact that this can be done in a few lines of HTML/CSS is compelling and might reduce the need for heavier solutions.

The main trick here is to hide the summary when details is open.

details[open] summary {
  display: none;
}

That’s it really.

CodePen Embed Fallback

The post Creating a Details Element That Opens But Never Closes appeared first on CSS-Tricks.

Categories: Designing, Others Tags:
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.