If both <br> and <br /> are valid syntaxes, which one should I use?

I think there are different style guides for each. I don’t understand why you put them together. We were talking about a HTML guide style, not about having one for both of the coding languages. Though I can understand you and agree with you on the practical aspect, my observation wasn’t on what’s the best way to code, but regarding how a style guide should be. As mrf said, we should look for objective directions. You cannot be subjective with the minimum requirement. The fact that different files types (HTML and XML) have different minimum requirements is not subjective. The point wasn’t to create a universal style guide for all the coding languages but a style guide for each one of them separately. Having this in mind you cannot be subjective by following the minimum requirement for each coding language. The fact that you want to have a common coding style for both coding languages is subjective.

I understand that you want to make users happy but that’s exactly what subjectivity is. A style guide purpose is not to make users happy but to guide them. What you consider to make the users happy may be good, indeed, and I don’t disagree with what you consider to be good. My objection was on the subjective-objective matter, not regarding which is the best way to code.

3 Likes

i think br is a self closing tag witch close itself, so we dont need to colse it with /br right?

thank you, this is helpful

Enjoyed this thread and think I learned a bit about both HTML/XML and logical reasoning :slight_smile: thank you

4 Likes

if you use validator to validate ( https://validator.w3.org/) use

Thanks for the suggestion :heart_eyes: :heart_eyes:

bit43…, I agree with you. Even though mtf and nemo242 may have annoyed each other (I don’t know if that was the case), their debate really made clear some aspects of HTML that would have been hard to clarify well in a simple statement.

mtf and nemo242, my thanks for your debate!

2 Likes

Let’s say I have a picture of myself. What would be the appropirate alt text for that? Would I simply use my name?(I assume no because that doesn’t describe me)

The forward slash is a convention inherited from XHTML which is strongly conformant with XML. In XML there are no void elements so when the recommendations for XHTML were devised in the late 90s it was decided that void tags would end with a /.

<img />
<input />

and so on. The original spec didn’t have a space but for some odd reason IE5.2 for the Mac was choking on that syntax. Someone discovered that it could handle it if there was a space.

Today, HTML5 has two flavors that it can be served out as. Plain text or XML application. Most of what we are doing is using the MIME type="text/html" so the slash is not needed. However when serving as XML the slash is needed. The space is not, but if it is there, it is ignored.

<img>
<img/>
<img />

are all valid in HTML served as text.

4 Likes

I appreciate this explanation, as it is making me pause to consider what you are explaining and reflect on my original observation and questions. You are a wealth of knowledge and always find your posts helpful. I just want to clarify that I am understanding.

  1. In the course, I just completed the introduction to HTML section about basic elements, and noted that the image tag is a self-closing tag. This would explain why the forward slash is paired with the closing bracket of the single tag in your first example. Apparently the input tag is also a self-closing tag.

  2. I have noticed that all the slashes for the closing tags In the Codecademy examples come before the text in the closing element. Like the paragraph tag,

Screen Shot 2022-02-18 at 1.52.46 PM
or the button tag
Screen Shot 2022-02-18 at 1.53.20 PM

It is possible then that the examples that caught my attention within the discussion board comments were void tags, or self-closing tags, or other tags I have not yet learned that don’t follow the format of a tag with a closing element such as the paragraph tag, but with my limited tag knowledge thought they might be just another accepted order of writing a closing element of a tag. (Of course, I don’t recall all the discussions where I saw them, but will examine future examples that don’t follow the expected order and see what I learn).

1 Like

Void tags (self-closing tags in XHTML) have no content, hence they do not need a closing tag. Everything of import is in the element attributes.

Elements that are containers need a closing tag. They are usually categorized as sectioning elements. They may contain other HTML, or plain text. The paragraph above is a good example, mind we don’t enclose many HTML elements, mostly text and other inline elements such as <span></span>, <img>, etc. The <button></button> element contains plain text, only, in most cases.

There are only a handful of void elements. Check W3C for HTML Elements to get a complete rundown of the differing purposes. Pay close attention to what content is allowed, as well as what attributes are allowed.

3 Likes

What are void elements/tags and MIME?
MIME I have no idea about and its the first time in the course, I’ve seen it mentioned!
Currently just passed Line Breaks!
Thank you

That is an example of a void element: One that does not contain or wrap text or other HTML content. Void elements have no closing tag because of that.

<br>
<img>
<input>
<hr>

are among the most common ones we use.

MIME - Wikipedia

All media that is transmitted over the internet has a MIME type. For instance, HTML when served as text has the MIME, type="text/html". CSS, type="text/css". JS, type="text/javascript", and so on. Those are the defaults for the three built in APIs of the browser.

5 Likes

Did you mean MTF?..

Nice comparisons to understand the situation

Thank you webdev58. Really appreciate this explanation. Very helpful to a newbie like me. :smile:

Thank you. This explanation has added more clarity to my understanding.

1 Like

I recommend to go for the shorter version in this case, i.e.
. Best, Anja

what about these
it also works