HTML Attributes: Names and Values
Attribute syntax
Attributes appear in an opening tag and provide information or configuration. A common form is name="value". Use quoted values consistently. The lang attribute identifies the language of an element and its content.
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <title>Languages</title> </head> <body> <p lang="fr">Bonjour!</p> </body></html>Bonjour! is visible; the language annotation can help tools such as screen readers choose the appropriate pronunciation.
More than one attribute
Separate attributes with whitespace. The id attribute identifies one element in a document; its value must be unique within that document. An ID does not change appearance by itself.
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <title>Greetings</title> </head> <body> <p id="greeting" lang="es">Hola!</p> </body></html>The paragraph displays Hola! and carries both an identifier and a language annotation.
Common mistake: duplicate IDs
Do not give two elements the same id. Use distinct values, such as intro and summary. Practice adding a unique ID to a paragraph.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Attributes: Names and Values — Knowledge Check
Apply the concepts and examples from this lesson.
Where does id="intro" belong in a paragraph?
Which markup separates attributes correctly?
Two paragraphs have id="summary". What is the correction?
What is the effect of adding id="intro" alone to a paragraph?
A French sentence appears in an English document. Which attribute identifies the sentence's language?