Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Proper word spacing syntax

Hello,

While I've been learning to code I've seen different wording syntax and I don't understand when you should use one or another. For example....

HTML: grid_5 or grid-5

Are there industry standards on this?

3 Answers

Awesome question! It varies, but usually, using hyphens as a separator has worked for me for cleanliness. You may want to explore CSS style guides such as Harry Roberts', or GitHub's own guide, too, for general great practices.

always good to see what others advocate. a bit mean to generally discriminate camels :0P. no only joking. Harry's advice seems a good example to follow

it depends how you define a class in the first place. you can use either syntax according to your liking as long as you stay internally consistent, that is if you define a

<div class="grid_5">

then you have to use

.grid_5

and vice versa

there are certain rules that the name has to adhere to when you define it:

  • Must begin with a letter A-Z or a-z
  • Can be followed by: letters (A-Za-z), digits (0-9), hyphens ("-"), and underscores ("_")
  • In HTML, all values are case-insensitive

as long as your classname follows the rules above you are free to choose whatever you find most sensible. a good practice is for the name to be descriptive so in case somebody else takes over your code they can understand your logic.

Great answers! Thank you both very much!