>
Hyphens or underscores in CSS and HTML identifiers...
Welcome, Guest

by Rishi on Thursday, 27 May 2010
Hyphens or underscores in CSS and HTML identifiers?


Hyphens or underscores in CSS and HTML

identifiers?

 

As  building the Classes or ID's in  CSS and HTML, there are some times we encounter with the question of which identifier we use for making large class. As per our CSS Frameworks and other CSS Tools we can use 2 identifiers. These are:

1. Hyphen (-)

2. Underscore (_)

 

But in case of using the this identifiers, we have question that "Which one (Hyphen or Underscore) is better to use?"  

 AS the regular learning i come to the point that-

As both hyphen (-) and underscore (_) are valid characters in CSS and HTML identifiers, what are the advantages and disadvantages using one or the other? I prefer writing CSS class names with hyphens (e.g. field-text) and underscores for IDs (e.g. featured_content). Is there a best practice or it's only the matter of taste? 

 

It's really just preference, but if you are going to be doing programming to manipulate the DOM or passing identifiers such as form names to programming languages, usually underscores are nicer.

For example:

<input type="text" name="my_input" id="my_input" />

<input type="text" name="my-input" id="my-input" />

If you are scripting it, you can do var my_input = document.getElementById('my_input'); or parse the incoming value when POSTed to php with <?php $my_input = $_POST['my_input']; ?>. However, the dashed version won't be translatable in either JavaScript or PHP because dashes are not allowed there.

You forgot to mention that camelCase, like myInput would be yet another convention for classes and ids.  




Blogger Image
My Blog Title

Product Engineering, software engineering company, Product Development, Product Migration, Product Re-engineering, Product Maintenance, Product Testing Commercial Application Development, Business Software development, commercial software for startups, Application Support and Maintenance, software testing Product Maintenance, Outsource product maintenance, product support and maintenance Product Migration, Product Re-engineering, product re-engineering services Product Research, Product Engineering, UI Prototyping Services Software Testing Services, Quality Assurance services, professional software testers, Load Testing, Functional Testing, Cross Platform, Browser Testing, Test Automation, Testing Tools, software quality analysis Functional Testing Services, software quality analysis, Software Testing Services, Application Testing Services, Functional Testing Types Automated Testing, Automated Testing Services, automation testing, test script development, Automation Test Tools, outsource automation testing Load Testing, Performance Testing Services, Load Testing Tools Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Benefits of IT Outsourcing, Offshore Software Development companies, offshore software development firms Outsource planning, IT outsourcing, IT development services, offshore IT companies, offshore software development Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering