As explained in Your First Webpage, an inline element does not break the flow of text, but instead is used to give special meaning to a certain piece of text within a larger block of text. It can, for the most part, be considered 1-dimensional, that dimension being length.
One thing that needs to be remembered is all elements presented here must go into a block-level element such as p
.
I will present these elements in three groups:
Within these three groups, I will explain them in the alphabetical order of their element names, then give a list of their attributes. Included are some that I advise against, but include because they are still a part of the HTML 4.01 Strict and XHTML 1.0 Strict specifications. Alternatives are in italics and underlined.
You'll probably see a lot of unfamiliar elements and attributes in the coding examples. Don't worry; it's all (X)HTML, and it all follows the rules I explained in Chapters 2, 4, and 5. The element names may be new, but I say again: you've seen it all before.
The following elements have several attributes in common, but some have attributes of their own.
As I said in Attributes, there are several attributes common to almost all elements known as the core and language attributes. These attributes are all implied (optional) in the following elements, unless it is stated that they are required or forbidden.
To avoid a lot of repetition, I will not mention attributes at all for the majority of the elements. In certain cases, however, I will list attributes under the following headings:
I will not list all implied attributes associated with each element because a) several of them are rarely used, b) are difficult to explain, and c) you can build a perfectly fine webpage without them.
Element Name: span
A good introductory element is the span
element. A completely generic inline element with absolutely no semantic meaning or effect on the text, it simply contains a span of text. Thus, it is an ideal element to use when no other element will semantically do. Semantics can then be added via the class
, id
, and other attributes.
span
ElementNotice what I said about attributes giving the span
element its meaning: their respective class
attributes both mark them as being foreign phrases or words, while their lang
attributes tells you which languages they come from (Latin and German, respectively.)
The phrase elements are elements that set apart certain phrases and either give them special meaning or make their nature clear. The phrase elements are:
Element Name: abbr
Denoting abbreviations is the task of this element, and the title
attribute is used quite often to show the full name of the abbreviations in a tooltip when a mouse is hovered over the abbreviation.
Element Name: acronym
As the abbr
element is to HTML, Doctype, Ave, and USA, so is the acronym
element to NATO, URI, RADAR, and SONAR. Essentially, an acronym is a word made up of the initial letters of a name.
Technically, you could replace acronym
elements with abbr
elements and still be semantically correct, since an acronym is a type of abbreviation.
Element Name: cite
The cite
element is used when you want to name a source. For example, if you wanted to properly cite the source of the saying I think, therefore I am
, you would put René Descartes' name within a cite
element, since that is to whom the saying is attributed.
Cogito, ergo sum
(Original French: Je pense donc je suis
): I think, therefore I am
(René Descartes).
Element Name: code
The code
element is used to contain fragments of computer codes. For example, if you wanted to include an example of HTML on your webpage, you would use the code
element, since it is HTML code
code
ElementElement Name: dfn
The dfn
element is used when including the definition of a term used in a block of text.
Element Name: em
Again, this element is used to add emphasis to a word or phrase.
Element Name: kbd
This element is used to denote input that the user should enter.
Element Name: samp
Unlike the code
element, which denotes the actual code of a program, the samp
element denotes sample output from a program.
Element Name: strong
The strong
element is used to give words or phrases highlighting for a specific purpose. For example, a keyword for a programming language may be highlighted.
Keywords are often highlighted using the strong
element.
Element Name: var
In a lot of computer languages, you have something known as a variable which is just a storage spot for some information. Since HTML was used to describe computer languages a lot, there is an element to denote variables: the var
element.
The presentational elements have no meaning, but exist solely to affect the appearance of text. These elements are presented to you only because they still are a part of HTML 4.01 Strict. They are:
The b
, i
, and tt
elements all have more semantic replacements (which I'll mention when I talk about those elements).
To resize text without using the big
and small
elements, use a non-presentational element with a style
attribute. The property that controls the size of the text is font-size
. You can use any of the following measurements:
pixels
points, which is the default measurement in many word processors such as Microsoft Word. It is equal to 1/72 of an inch.
points, which is the default measurement in many word processors such as Microsoft Word. It is equal to 1/6 of an inch.
inches
centimeters
The advantage with the style attribute is that its use requires fewer tags (the big
or small
end tag is no longer necessary) and you can be more precise about the text size. With the big
and small
elements, you get three choices: big, small and the default.
Element Name: b
The b
element is used only to make text bold. A better choice is the strong
element, which has the meaning of a certain type of emphasis.
Element Name: big
This is used to make text look larger.
big
ElementUsing the style attribute allows you more precise control over the size of the text and lets you make any element big
without adding more tags.
Element Name: i
This is used to put text into italics. Better, more semantic options are:
You can also use the following declaration in the style
attribute: font-style:italic;
i
ElementElement Name: small
The small
element is used to make text look small. Remember, this sort of thing is no longer required.
Element Name: tt
The tt
element is used to denote monospaced text—that is, text where each character has exactly the same width. Better elements to use are code
and samp
, which do the same job with the added bonus of semantic meaning.
tt
ElementThe elements listed here you will use out of lack of choice: they're the only elements that will serve their purpose.
Element Name: a
This element is used for creating hyperlinks to other documents—in other words, text that will take you to another page if you click on it.
tabindex
attribute sets the order in which the links gain focus. This attribute should contain an integer greater than or equal to 1, or it won't work.Element Name: bdo
The bdo
element is used to override the default direction within a span of text. For example, in a paragraph which is read left-to-right, you may want a span of text in, say, the Hebrew script, which goes right-to-left instead.
left-to-right) and rtl (
right-to-left).
bdo
ElementA quick note on the codes in italics: remember the NCRs I mentioned in Special Characters? These are perfect examples. Please note that in both bdo
elements, the codes are written in the exact same order, but are displayed as going in opposite directions.
Element Name: br
The br
element is used to force a line break where there would not otherwise be one.
This is an empty element. It has no end tag.
You may not use the language attributes with this element.
Element Name: button
The button
element is used to place a clickable button on the page, like this: .
The button
element is unusual amongst inline elements in that can contain block elements as well—but do note it cannot contain an a
element.
disabled. It's used when you want the button present, but don't want anyone using it for some reason. The result looks like this: .
a
element, this sets the order in which the tab key focuses on each button or link.Element names:
The del
element is used for text that has been deleted, but is still included for archival purposes, while the ins
element is used for text that has been inserted. The deleted text is marked by a line running through it, while inserted text is underlined.
Element Name: img
The image element is simply used to put a picture on a page.
This is an empty element. It has no end tag.
href
attribute.id
attribute).Element Name: q
This element is used for short quotations. We've seen a few examples here, by both H.L. Mencken and René Descartes.
Just something you should be aware of: The quote symbols are automatic in many browers, but are absent in others, most notably older versions of Internet Explorer.
q
ElementElement Name: sub
Subscript text is usually placed lower than the rest of the text and is smaller. To denote this, the sub
element is used.
Element Name: sup
Occasionally, text will appear smaller and higher than the rest of the text. This is the use of the sup
element.