0

Something I find somewhat odd is that by default, Wordpress always seems to make paragraphs, not divs when you press enter. At first this may seem like the common way to make paragraphs, but it's actually not that common:

  • Gmail uses brs, not paragraphs in its editor.
  • The Outlook mail online uses divs (or br tags).
  • There are good technical reasons the editor would be better to use divs instead of paragraphs, not just because it's more popular. What about shortcodes that output divs for example?

Is it just the fact that TinyMCE doesn't support forced_root_block very well, that Wordpress doesn't fully support divs?

  • In content, it's totally understandable to add <p> tags for paragraphs. Emails are a little different and email service providers use different tags for new lines, to offer maximum compatibility for thousands of different (old) clients. Because you have to display emails right on other's platform/software. On the other side in WordPress, you need to display content right on your own website so it's either <p> or <div>, do not really matter. But developers prefer <p> instead of '<div>' because if you mess up with '<div>' in content then you will probably mess us your whole page. – Robert hue Nov 5 '15 at 5:15
  • WordPress uses paragraph tags where you would reasonably expect paragraphs. Why is that controversial? – s_ha_dum Nov 5 '15 at 5:22
  • @s_ha_dum It means you can't have divs within them, for one thing. See links above. – NoBugs Nov 7 '15 at 1:42
  • @s_ha_dum It also means certain shortcodes with divs would seem to break if you color their container's text-color. divs can't actually be in a paragraph. Thus they should be divs, not paragraphs. – NoBugs Nov 28 '15 at 1:18
1

You should simply not use <div>-elements to seperate paragraphs from each other. It´s wrong in the semantical context, I think.

When you press "Enter" you make, from a historical point of view, a "carriage return" and then a "line feed". You start a new line, maybe a new paragraph but nothing completely new.

If you want to start a new paragraph, use a <p>-element. Use a <br /> if you just want to start a new line. Use a <div> if you want to enclose several <p> elements. (Okay, we got <article> and <section> and stuff like that with HTML5, but div is no replacement for <p>.)

The W3 notes: (Pretty interesting document btw.)

Authors are strongly encouraged to view the div element as an element of last resort, for when no other element is suitable. Use of more appropriate elements instead of the div element leads to better accessibility for readers and easier maintainability for authors.

Last resort. Not your "bread and butter and works for everything"-element... ;-)

  • So divs shouldn't be used as a general element? What about... on this page? Run this in console: ['div','li','p','span','a'].forEach(function(el) { console.log(el +':'+ document.getElementsByTagName(el).length ) } ) – NoBugs Nov 6 '15 at 3:19
  • Divs shouldn´t be used when there is a better element for the task. No question, browsers will display it well anyway and it´s quite useful that divs are block elements by default, but semantically a div is nothing you can get your hands on, because there could be anything in it. That´s fine if you use divs for positioning and containing other, specific elements, but you shouldn´t use it for general markup. – flomei Nov 6 '15 at 13:18
  • Yeah, if you are writing "paragraphs", as most bloggers might, that may make sense. Usually sites won't do that in practice - run that script on php.net for example: div:153 li:75 p:6 span:542 a:230 or cnn.com: div:882 li:247 p:0 span:476 a:436 – NoBugs Nov 7 '15 at 1:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.