Home >> FAQs/Tutorials >> XHTML Tutorials and Tips >> Index

XHTML Tutorial - Quoting Element Attribute Values

By: FYIcenter.com

(Continued from previous topic...)

How To Quote Element Attribute Values Properly?

You know that attribute values must be quoted. But how to attribute values properly? Here are some basic rules you should remember:

  • An attribute value must be quoted.
  • An attribute value can be quoted with double quotes as "...".
  • An attribute value can be quoted with single quotes as '...'.
  • If double quotes appear in an attribute value, you should use single quotes to quote the value.
  • If single quotes appear in an attribute value, you should use double quotes to quote the value.
  • If both double quotes and single quotes appear in an attribute value, you should replace those quotes with entities: " and &apos.
  • If an ampersand sign "&" appears in an attribute value, you must replace it with entity: &.

Here are some interesting examples of quoted attribute values:

  • <img src=fyi.gif alt=FYI/> - Invalid, values must be quoted.
  • <img src="fyi.gif" alt="FYI"/> - Valid, quoted with double quotes.
  • <img src='fyi.gif' alt='FYI'/> - Valid, quoted with double quotes.
  • <img src="fyi.gif" alt="FYIcenter.com's Home"/> - Valid, single quote in double quotes.
  • <img src="fyi.gif" alt='FYIcenter.com's Home'/> - Invalid, single quote in single quotes.
  • <img src="fyi.gif" alt='FYIcenter.com&apos;s Home'/> - Valid, entity in single quotes.

(Continued on next topic...)

  1. What Is an XHTML Element?
  2. How To Enter Comments into XHTML Documents?
  3. How To Write the Opening Tag of an XHTML Element?
  4. How To Close an XHTML Element?
  5. What Is Wrong with My <br> Tags?
  6. What Is Wrong with My <meta> Tags?
  7. How To Enter Element Content?
  8. Is XHTML Element Name Case Sensitive?
  9. What Is an XHTML Element Attribute?
  10. How To Write Element Attributes Properly?
  11. Is Attribute Name Case Sensitive?
  12. How To Quote Element Attribute Values Properly?
  13. How To Write Ampersand Sign in Attribute Values?
  14. What Is a Required Attribute?
  15. What Are Predefined Attribute Values?
  16. What Is Wrong with My "checked" Attribute Values?


Selected Developer Jobs:

More...