Attribute values can be quoted or, in limited cases, unquoted. Quoted values handle spaces safely and are the easiest style to maintain.
What You Need to Know
An empty quoted value, such as value="", is different from an attribute being absent. Some attributes are Boolean, while others use their string values.
Quotes are recommended around attribute values. Unquoted values have restrictions, and an empty value is not the same thing as an omitted attribute.
The goal is not to collect as many tags as possible. Pick the element that best describes what the content really is.
Example: See It in Action
Try this markup in a fresh practice file. The next section explains the parts worth paying attention to.
This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.
<a href="about.html" title="Meet the team">About us</a>
<p class="intro">Hello!</p>
<input type="text" value="" aria-label="Nickname">
Let’s Understand the Example
- An a element becomes a working link when it has an href. Its visible text should tell readers where they will go.
- A p groups a paragraph of related text. Start another paragraph for a new thought.
- Input creates a form control. Its type decides whether people type text, choose a date, move a slider and more.
- Href contains the destination of a link. A value starting with # points to an id on the same page.
- Title adds advisory information, but it is not a substitute for readable visible labels.
- Class is a reusable label for styling or scripts; several elements may share the same class.
The first example link points to about.html. Check whether that destination exists relative to the document. A link changes where readers go; it does not perform an action such as saving a form.
What Should You See?
The page should include “About us”. If it looks different from what you expected, open developer tools and compare the source with the elements the browser created.
Try removing one piece of markup in a scratch copy, refresh the page, and compare the behavior. This is often the fastest way to understand what that piece contributes.
Try It Yourself
- Change an attribute to a value containing spaces and verify that its quotation marks remain correct.
- Save your changes, open or refresh the page, and compare the result with the original example.
- Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.
Common Beginner Mistakes
- Assuming that value="" is the same as not including the value attribute at all.
- Avoid picking tags just for their default bold, italic or spaced appearance. Use CSS for presentation.
Key Takeaways
- Attribute values can be quoted or, in limited cases, unquoted.
- An a element becomes a working link when it has an href. Its visible text should tell readers where they will go.
- Quotes are recommended around attribute values. Unquoted values have restrictions, and an empty value is not the same thing as an omitted attribute.