Anonymous

What are the three guidelines for writing good HTML code?

3

3 Answers

Hitesh Patel Profile
Hitesh Patel answered

The  Basic Rules for
Writing HTML

  • Use
        well-formed HTML
  • Respect
        syntax and semantics
  • Don’t
        use presentational or behavioral markup
  • Leave
        everything out that is not absolutely necessary
  • Standardize
        character case.
  • Use
        comments judiciously.

Yo Kass Profile
Yo Kass answered

There are lots of rules and recommendations for writing good html.

As someone who has only recently got into writing html and css, the 5 rules that I've found most useful are (I know you said 3 rules, but these are all mistakes that I made when I first started, so thought I'd throw in a few bonus rules):

1. Try to keep your code well-formatted, neat and easily legible.

Opening and closing tags should align, and your html should be structured with indents and spaces in the right places.

2. Don't use html tables for layout

Just don't.

3. Don't use <div> tags unless you actually need them.

This is something I was guilty of initially. Also z-index those divs!

4. Don't use attributes you don't need.

A bit obvious, not every element needs an id, a class, a name and a value... #justsaying

5. If you are going to use a class, id or name - for God's sake make it relevant to what they actually do.

If you're specifying a css id that styles an element to look like a large searchbar with a red border, call it something like #large-red-search

Do not use an id like #qwerty123 because you will struggle to remember what the hell it does when you're going through your code looking for bugs.

Hope this helps!

Anonymous Profile
Anonymous answered

1. Respect Syntax and Semantics

In other words: Validate your code and use markup according to its purpose. For validation there are validators, and both syntax and semantics are explained in specifications. Many advantages spring out of respecting syntax and semantics. Most notably, avoiding a few accessibility pitfalls and being professional.

2. Don’t Use Presentational or Behavioral Markup

In other words: Avoid presentational and behavioral elements and attributes, avoid presentational and behavorial ID and class names, avoid linking off to too many style sheets and scripts, avoid screwing up file names, &c. Pp. Markup changes continue to be most expensive. Separation of concerns is the only option you have to write markup that is reusable and maintainable.

3. Leave Everything out that Is Not Absolutely Necessary

In other words: Leave everything out that is not absolutely necessary. Question everything. Just using the markup you really need sounds easy but, unfortunately, it’s not. It requires experience and expertise. When questioning everything and omitting even more, look into syntactical opportunities, too (protocol-less URLs, optional tags, unquoted attribute values, &c.). Once comfortable with the techniques, welcome not only performance but also maintainability benefits.

Learn HTML5 & CSS3 for beginner

Answer Question

Anonymous