Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
HTML
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Attributes ==== {{Main|HTML attribute}} Most of the attributes of an element are [[name–value pair]]s, separated by <code>=</code> and written within the start tag of an element after the element's name. The value may be enclosed in single or double quotes, although values consisting of certain characters can be left unquoted in HTML (but not XHTML).<ref>{{cite web |url=https://www.w3.org/TR/html401/intro/sgmltut.html#h-3.2.2|title=On SGML and HTML|publisher=World Wide Web Consortium|access-date=November 16, 2008}}</ref><ref>{{cite web |url=https://www.w3.org/TR/xhtml1/diffs.html#h-4.4|title=XHTML 1.0 – Differences with HTML 4|publisher=World Wide Web Consortium|access-date=November 16, 2008}}</ref> Leaving attribute values unquoted is considered unsafe.<ref>{{cite web|first=Jukka|last=Korpela|url=https://jkorpela.fi/qattr.html|title=Why attribute values should always be quoted in HTML|publisher=Cs.tut.fi|date=July 6, 1998|access-date=November 16, 2008}}</ref> In contrast with name-value pair attributes, there are some attributes that affect the element simply by their presence in the start tag of the element,<ref name="tagshtml">{{cite web|title=Tags used in HTML|url=https://www.w3.org/History/19921103-hypertext/hypertext/WWW/MarkUp/Tags.html|date=November 3, 1992|publisher=World Wide Web Consortium|url-status=live|archive-url=https://web.archive.org/web/20100131184344/http://www.w3.org/History/19921103-hypertext/hypertext/WWW/MarkUp/Tags.html|archive-date=January 31, 2010|access-date=November 16, 2008}}</ref> like the <code>ismap</code> attribute for the <code>img</code> element.<ref>{{cite web|url=https://www.w3.org/TR/1999/REC-html401-19991224/struct/objects.html#adef-ismap|title=Objects, Images, and Applets in HTML documents|publisher=World Wide Web Consortium|date=December 24, 1999|access-date=November 16, 2008}}</ref> There are several common attributes that may appear in many elements : * The <code>id</code> attribute provides a document-wide unique identifier for an element. This is used to identify the element so that stylesheets can alter its presentational properties, and scripts may alter, animate or delete its contents or presentation. Appended to the URL of the page, it provides a globally unique identifier for the element, typically a sub-section of the page. For example, the ID "Attributes" in <code><nowiki>https://en.wikipedia.org/wiki/HTML#Attributes</nowiki></code>. * The <code>class</code> attribute provides a way of classifying similar elements. This can be used for [[semantics|semantic]] or presentation purposes. For example, an HTML document might semantically use the designation {{code|lang=html|code=<class="notation">}} to indicate that all elements with this class value are subordinate to the main text of the document. In presentation<!-- Presentationally is not a formally accepted word -->, such elements might be gathered together and presented as footnotes on a page instead of appearing in the place where they occur in the HTML source. Class attributes are used semantically in [[microformat]]s. Multiple class values may be specified; for example {{code|lang=html|code=<class="notation important">}} puts the element into both the <code>notation</code> and the <code>important</code> classes. * An author may use the <code>style</code> attribute to assign presentational properties to a particular element. It is considered better practice to use an element's <code>id</code> or <code>class</code> attributes to select the element from within a [[Cascading Style Sheets|stylesheet]], though sometimes this can be too cumbersome for a simple, specific, or ad hoc styling. * The <code>title</code> attribute is used to attach a subtextual explanation to an element. In most [[Web browser|browsers]] this attribute is displayed as a [[tooltip]]. * The <code>lang</code> attribute identifies the natural language of the element's contents, which may be different from that of the rest of the document. For example, in an English-language document: <syntaxhighlight lang="html"><p>Oh well, <span lang="fr">c'est la vie</span>, as they say in France.</p></syntaxhighlight> The abbreviation element, <code>abbr</code>, can be used to demonstrate some of these attributes: <syntaxhighlight lang="html"><abbr id="anId" class="jargon" style="color:purple;" title="Hypertext Markup Language">HTML</abbr></syntaxhighlight> This example displays as <abbr id="anId" class="jargon" style="color:purple;" title="Hypertext Markup Language">HTML</abbr>; in most browsers, pointing the cursor at the abbreviation should display the title text "Hypertext Markup Language." Most elements take the language-related attribute <code>dir</code> to specify text direction, such as with "rtl" for right-to-left text in, for example, [[Arabic language|Arabic]], [[Persian language|Persian]] or [[Hebrew language|Hebrew]].<ref>{{cite web|title=H56: Using the dir attribute on an inline element to resolve problems with nested directional runs|url=https://www.w3.org/TR/WCAG-TECHS/H56.html|website=Techniques for WCAG 2.0|publisher=W3C|access-date=18 September 2010}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)