Home > Enterprise >  Is there a specific order for <label for="" type="" ...></label>?
Is there a specific order for <label for="" type="" ...></label>?

Time:12-07

I have some questions:

  1. If you type something like this <label type="" id="" name="">, is there a specific order that needs to be adhered to when it comes to type, id, name, etc, or is considered best practice to just follow the examples shown on let's say W3Schools?
  2. What's the difference between commenting using <!-- some comment --> and /* some comment */? I (think I) observed that both sometimes work in either a HTML and a CSS document

CodePudding user response:

About your first question, you can use a name or id or both. you don't have to use all of them or even one of them. About your second question, this comment - for Html, and this comment - /* some comment */ for the CSS. If you try those comments in other files, it doesn't work.

CodePudding user response:

  1. There is no specific order for the HTML tag attributes, i.e. you can add it in any order, as long as all required attributes are added.

  2. <!-- some comment --> is HTML comment, /* some comment */ is CSS and JS comment (and some other languages as well, such as Swift and Objective-C).

CodePudding user response:

First question, The answer is No.

No you don't need a specific order to set properties of a HTML element, you can do this

<label class="someClass" id="someID"></label>

Or

<label id="someID" class="someClass"></label>

the order of attributes of a HTML element doesn't matter, but order of the HTML element itself does matter.

For Example:

This HTML Code:

<label for="firstName">First Name: </label>
<input type="text" id="firstName" name="firstName">

Shouldn't/Can't Be Written as this:

<input type="text" id="firstName" name="firstName">
<label for="firstName">First Name: </label>

Second question

this Syntax <!-- Comment --> is used in only HTML Documents

whereas this Syntax /* Comment */ is used in only CSS Documents

But this doesn't mean you can't use this syntax in HTML /* Comment */, for example inside of style tag in HTML, you can directly write CSS inside your HTML Document you can use the CSS Comment Syntax

For Example:

<style>
  /* This is a CSS Comment */
  h1 { background-color: #ccc; }
</style>
<h1>Hey There Brother!</h1>

Or you can use the CSS Comment Syntax in the style attribute of a HTML Element.

For Example

<h1 style="background-color: #ccc; /* This is a CSS Comment */">Hey There Brother!</h1>

But you can't use HTML Comment Syntax inside of CSS, there might be an exception which i don't know but as far as i know you can't.

CodePudding user response:

There's a document in GitHub that outlines a reasonable style guide for HTML development. I suggest you read it. https://github.com/necolas/idiomatic-html

  1. HTML attributes should be listed in an order that reflects the fact that class names are the primary interface through which CSS and JavaScript select elements.
  • class
  • id
  • data-*
  • Everything else

Example:

<a class="[value]" id="[value]" data-name="[value]" href="[url]">[text]</a>
  1. About comments:

<!-- some comment --> is a HTML comment.

/* comment */ is a CSS and JavaScript comment.

In short: Have a style!

  • Related