DEV Community

loading...

Don't use the br + br selector to hide the superfluous carriage return.

yoanmalie profile image Yoan Malié ・1 min read

You probably see some advice on the web and especially on Twitter about this selector:

br + br {
  display: none;
}

Theorically, you want to hide the superfluous <br> elements that are sometime added by a text editor in a CMS when you hit Enter. This selector seem pretty neat! This Tweet from Harry Robert who got a lot of Retweets and Likes, mention this tip.

But do you know what is really happening…?

Let's give a look on this Pen I made. It's a simple text with some carriage returns added on it. You will notice that I added two siblings <br><br> tag and this is the second one that we want to hide with this selector!

The fact is that the <br> tag is part of the text DOM, you will see that all the <br> tag except the first will be hiden. This will completely interfere with the reading by showing us some big parts of unreadable text.

I'm curious if you know others tips to get rid of bad outputs from CMS. Let me know!

Discussion

pic
Editor guide