views:

267

answers:

4

I mean to name ids, names, values, etc?

+9  A: 

While I don't think there is a single, accepted naming conventions for naming HTML elements, you might find the following article helpful. The content starting on page two is probably most helpful. Good luck!

The Meaning of Semantics Take II: Naming Conventions for Class and ID in CSS

Here are a few good paragraphs that summarize what the author is trying to get at:

A designer might name a column division #leftnav. At first glance this is logical, and in the context of smaller sites, maintained by one or just a few folks, there really aren't a lot of problems with this kind of naming.

However, consider a site the size of AOL or Yahoo, on which large teams of designers and developers manage millions of pages every day. And let's say that a design decision from high on up the corporate ladder is made to move the navigation to the right from its former home on the left side of the screen. Part of the power of CSS is that in a best-case scenario, all that switching the navigation would require is to go into the CSS and swap the column by repositioning it or floating it right instead of left. Save that file and then millions of documents are updated to reflect the change.

But now, millions of documents also have a division with an ID of #leftnav describing a column that appears on the right! Without doing a massive search and replace to change the ID name in the (X)HTML, the document is now very confusing to anyone who views source, or (more importantly) comes in to work on the site.

This is why avoiding presentation and choosing a more relevant description as simple as #nav or #subnav will be more useful in that kind of environment. So, even if it might seem a bit nitpicky, for very large sites we want to try and maintain the power of CSS and the purity of our documents. Smart class and ID names are a major part of that goal.

William Brendel
+1 for the mere mention of semantics wrt naming
annakata
+1 for copying and pasting the interesting bit. Laziness ftw.
Mike Robinson
I always try to copy and paste the interesting stuff for two reasons. The first is laziness. The second is that links break over time, and I like to think of Stack Overflow as a repository that stuff should be dumped into, not just linked from.
William Brendel
+3  A: 

w3c recommendations?

Sergey Kuznetsov
A: 

If there was one, the world would be a better place, the unicorns wouldn't be extinct, and so on. It's like deciding on indentation or brace style.

Just try to keep it consistent and sane. By sane I don't mean 'indent with 4 spaces and name with camelCase', just that you follow a style consistently. underscore_names? more power to you. tabs to the rescue? great. I'd just like not to open new projects and have to cuss for 5 minutes because the indentation is completely hosed, and stuff inside a div is three tabs to the left of it.

Fortunately, a good editor helps.

Adriano Varoli Piazza
+1  A: 

With anyone interested in standards I always recommend these two books:

Designing with Web Standards (2nd Edition) (Paperback)

Eric Meyer on CSS: Mastering the Language of Web Design (VOICES) (Paperback)

Those two books were instrumental in helping me cultivate my own standards.

Mike Robinson