HTML and CSS Reference
In-Depth Information
media
: the media for which the linked resource is intended. This attribute's value must be a valid
media type or media query.
hreflang
: the natural (human) language of the linked resource, such as English, German, or
Hindi, indicated by an abbreviated language code. This is similar to the global
lang
attribute, and
is most important when the link's destination is in a language different from that of the current
document.
sizes
: gives the sizes of icons for visual media. The attribute's value is a set of space-separated
sizes, each in the format
[width]x[height]
, for example:
sizes="16x16 32x32
. See
w3.org/TR/html5/links.html#attr-link-sizes
for more information. This attribute should
only appear when the
rel
attribute has a value of
icon
.
base
The
base
element allows you to specify the
base URL
to be used for resolving any relative URLs within a
document, or to specify a default target window where links in the document will open. This is an empty
element that can only appear in a document's
head
, and there can be only one
base
element in a single
document. It requires either an
href
attribute or a
target
attribute, though it can have both.
Base URL
When the
base
element has an
href
attribute, that attribute's value acts as the base URL for the entire
document. Any relative URLs in the document following the
base
element will have the base URL
prepended to them.
The value of the
href
attribute must be a valid URL, but it can be either absolute or relative. For example,
if your page has been moved into a different subdirectory on the server but all of its relative URLs should
still point to the original parent directory, you could use a
base
element with a relative URL in its
href
:
<base href="/products/">
Any subsequent relative URLs that are
relative to the current document
—meaning they don't begin with a
leading slash (
/
) or up-level directive (
../
)—will be prepended with the relative base URL. Thus a URL
written in the document as
utility-belts.html
would behave in the browser as if it were
/products/utility-belts.html
. This can be useful if your page has been moved from its original
location or if your server isn't properly configured to handle relative URLs.
A
base
element with an absolute URL might look like:
<base href="
http://power-outfitters.com">
Any relative URLs throughout the document (still limited to those relative to the current document, not
those relative to the site root or to a higher directory) would then use that URL as their base and would
point to the
power-outfitters.com
domain, even if the document itself is hosted somewhere else.
But this doesn't apply only to hyperlinks;
all
locally relative URLs throughout the document will use this
URL as their base. That includes any
link
or
script
elements in the header (if they appear after the