Quoting HTML attribute values – important HTML tip

Quoting HTML attribute values – important HTML tip cover image
  1. Home
  2. HTML
  3. Quoting HTML attribute values – important HTML tip

This is an important HTML tip.

The values of attributes can contain text, hexadecimal color codes or numbers. In case of JavaScript event handlers, the values consist of small JavaScript code. A sincere advice for good and clean HTML coding is to ALWAYS put quotes around attribute values. It is a good habit, will save you many headaches and avoid errors especially when attribute values contain spaces.

Thus, using bgcolor=”#ffffff” instead of bgcolor=#ffffff results is greater browser compatibility and differentiates it nicely from other attribute-value pairs. Quoting attribute values is also required in XHTML. Your pages will fail the W3C validation if you leave the values haning around with the quotes.

HTML