- HTML Tag
- Syntax
- Example of the HTML tag used with the and tags:
- Example of the HTML tag used with the tag:
- Result
- Example of the HTML tag used with the tag:
- Attributes
- : The Document Metadata (Header) element
- Attributes
- Examples
- Technical summary
- Specifications
- Browser compatibility
- See also
- Found a content problem with this page?
- HTML — The Head Element
- The HTML Element
- The HTML Element
- Example
- The HTML Element
- Example
- The HTML Element
- Example
- The HTML Element
- Examples
- Example
- Setting The Viewport
- The HTML Element
- Example
- The HTML Element
- Example
- Chapter Summary
- HTML head Elements
HTML Tag
The tag contains metadata (document title, character set, styles, links, scripts), specific information about the web page that is not displayed to the user. Metadata provides browsers and search engines with technical information about the web page.
The includes the following elements:
- The tag defines the title of a web page (required). It may be confused with the tag, but they are different. The tag specifies the title of page content, whereas the tag is metadata representing the title of the entire HTML content and not its content.
- The tag contains CSS code that defines how HTML elements should be rendered in a browser.
- The tag defines an absolute (base) URL for all relative URLs.
- The tag defines the relationship between the current HTML document and the resource to which it refers, or contains a link to an external style sheet. It can have two attributes: rel=»stylesheet» and href .
- The tag provides additional information (metadata) about HTML document. The of a page can include different kinds of elements that may contain name and content attributes.
- The tag contains a script (generally JavaScript), or reference to an external file with scripts.This element may not be included in . Sometimes, it is better to put it at the bottom of . The element may seem empty, but it’s not.
- The tag defines an alternate text, which is displayed, if the browser doesn’t support scripts or scripts are disabled by the user.
Syntax
The
tag comes in pairs. The content is written between the opening () and closing () tags.Example of the HTML tag used with the and tags:
html> html> head> title>Title of the document title> style> body< background-color: #d3d3d3; > p< color: #1c87c9; > a< color: red; > style> head> body> p>Paragraph p> a href="#">Link a> body> html>
In the given example, the tag is used with the and tags. The tag defines the title of the document, which is displayed in the browser window. In the tag the style of the document is defined: the background of the document is orange, the text in the paragraphs marked with the tag is blue, and the links within the tag are pink.
Example of the HTML tag used with the tag:
html> html> head> link rel="stylesheet" type="text/css" href="css/style.css"> head> body> p>The content of the page p> body> html>
Result
In this example, we have provided a link to the document style.css in the CSS folder.
Example of the HTML tag used with the tag:
html> html> head> meta name="title" content="HTML and CSS Books"> meta name="description" content="HTML and CSS Basics for Beginners"> meta http-equiv="refresh" content="30"> head> body> p>The content of the page p> body> html>
Attributes
Attribute | Value | Description |
---|---|---|
profile | URL | Defines the URL of metadata. Not supported in HTML5. |
media | media_query | Specifies what media/device the media resource is optimized for. New in HTML5. |
type | text/css | Specifies the media type of the tag. New in HTML5. |
The tag supports the Global Attributes and the Event Attributes.
: The Document Metadata (Header) element
The HTML element contains machine-readable information (metadata) about the document, like its title, scripts, and style sheets.
Note: primarily holds information for machine processing, not human-readability. For human-visible information, like top-level headings and listed authors, see the element.
Attributes
This element includes the global attributes.
profile Deprecated Non-standard
The URIs of one or more metadata profiles, separated by white space.
Examples
doctype html> html lang="en-US"> head> meta charset="UTF-8" /> meta name="viewport" content="width=device-width" /> title>Document titletitle> head> html>
Technical summary
If the document is an srcdoc document, or if title information is available from a higher level protocol (like the subject line in HTML email), zero or more elements of metadata content.
Otherwise, one or more elements of metadata content where exactly one is a element.
Specifications
Browser compatibility
BCD tables only load in the browser
See also
Found a content problem with this page?
This page was last modified on Jul 7, 2023 by MDN contributors.
Your blueprint for a better internet.
HTML — The Head Element
The HTML element is a container for the following elements: , , , , , and .
The HTML Element
The element is a container for metadata (data about data) and is placed between the tag and the tag.
HTML metadata is data about the HTML document. Metadata is not displayed.
Metadata typically define the document title, character set, styles, scripts, and other meta information.
The HTML Element
The element defines the title of the document. The title must be text-only, and it is shown in the browser’s title bar or in the page’s tab.
The element is required in HTML documents!
The content of a page title is very important for search engine optimization (SEO)! The page title is used by search engine algorithms to decide the order when listing pages in search results.
- defines a title in the browser toolbar
- provides a title for the page when it is added to favorites
- displays a title for the page in search engine-results
So, try to make the title as accurate and meaningful as possible!
Example
The content of the document.
The HTML Element
The element is used to define style information for a single HTML page:
Example
The HTML Element
The element defines the relationship between the current document and an external resource.
The tag is most often used to link to external style sheets:
Example
Tip: To learn all about CSS, visit our CSS Tutorial.
The HTML Element
The element is typically used to specify the character set, page description, keywords, author of the document, and viewport settings.
The metadata will not be displayed on the page, but is used by browsers (how to display content or reload page), by search engines (keywords), and other web services.
Examples
Define the character set used:
Define keywords for search engines:
Define a description of your web page:
Define the author of a page:
Refresh document every 30 seconds:
Setting the viewport to make your website look good on all devices:
Example
Setting The Viewport
The viewport is the user’s visible area of a web page. It varies with the device — it will be smaller on a mobile phone than on a computer screen.
You should include the following element in all your web pages:
This gives the browser instructions on how to control the page’s dimensions and scaling.
The width=device-width part sets the width of the page to follow the screen-width of the device (which will vary depending on the device).
The initial-scale=1.0 part sets the initial zoom level when the page is first loaded by the browser.
Here is an example of a web page without the viewport meta tag, and the same web page with the viewport meta tag:
Tip: If you are browsing this page with a phone or a tablet, you can click on the two links below to see the difference.
The HTML Element
The element is used to define client-side JavaScripts.
The following JavaScript writes «Hello JavaScript!» into an HTML element with >
Example
Tip: To learn all about JavaScript, visit our JavaScript Tutorial.
The HTML Element
The element specifies the base URL and/or target for all relative URLs in a page.
The tag must have either an href or a target attribute present, or both.
There can only be one single element in a document!
Example
Specify a default URL and a default target for all links on a page:
Chapter Summary
- The element is a container for metadata (data about data)
- The element is placed between the tag and the tag
- The element is required and it defines the title of the document
- The element is used to define style information for a single document
- The tag is most often used to link to external style sheets
- The element is typically used to specify the character set, page description, keywords, author of the document, and viewport settings
- The element is used to define client-side JavaScripts
- The element specifies the base URL and/or target for all relative URLs in a page
HTML head Elements
Tag | Description |
---|---|
Defines information about the document | |
Defines the title of a document | |
Defines a default address or a default target for all links on a page | |
Defines the relationship between a document and an external resource | |
Defines metadata about an HTML document | |
Defines a client-side script | |
Defines style information for a document |
For a complete list of all available HTML tags, visit our HTML Tag Reference.