SeanWM
SeanWM

Reputation: 16989

HTML Naming Conventions

I know there are a lot of posts on this but I couldn't find one mentioning the actual name attribute of an HTML input element. I'm trying to form a standard for myself but I'm confused on what the name attribute should look like. If ids look like: id="this-id" what's best practice for names? I currenly use the underscore but I don't think it goes will with the hyphen.

Upvotes: 0

Views: 3362

Answers (3)

nom_nutella
nom_nutella

Reputation: 171

I used to almost always use an underscore such as name="random_name" but lately I have been just dropping the underscore and using capital letters for the first letter of each word such as name="RandomName"

I am not sure that it completely matters how you name them, as long as you can figure out what they are. Also with HTML5 the name attribute is not supported for the image (<img>) tag.

Upvotes: 2

Matt Maclennan
Matt Maclennan

Reputation: 1304

I personally make the ID and the Name the same, therefore, it is a lot easier to remember when altering CSS/manipulating form submission, for example

<input type="text" name="your-name" id="your-name">

The name and ID won't clash, as you will know, because they serve two different purposes, as explained here. In summary, if you have a naming convention for ids in place, then use that to make things easy to remember.

Upvotes: 4

ravb79
ravb79

Reputation: 752

You would use the most descriptive name, I suppose. There aren't any naming conventions for this that I know of. Using a descriptive name would increase readability and therefore, maintainability. Just only use letters and digits and no spaces.

Upvotes: 0

Related Questions