The accept attribute specifies the types of files that the server accepts (that can be submitted through a file upload).
Note: The accept attribute can only be used with <input type="file">.
Tip: Do not use this attribute as a validation tool. File uploads should be validated on the server.
The accept attribute can be used on the following element:
Element | Attribute |
---|---|
<input> | accept |
Specify that the server accepts only image files in the file upload.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The input accept attribute</h1>
<form action="/action_page.php">
<label for="img">Select image:</label>
<input type="file" id="img" name="img" accept="image/*">
<input type="submit">
</form>
<p><strong>Note:</strong> Because of security issues, this example will not allow you to upload files.</p>
</body>
</html>
The accept-charset attribute specifies the character encodings that are to be used for the form submission.
The default value is the reserved string "UNKNOWN" (indicates that the encoding equals the encoding of the document containing the <form> element).
The accept-charset attribute can be used on the following element:
Element | Attribute |
---|---|
<form> | accept-charset |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The form accept-charset attribute</h1>
<form action="/action_page.php" accept-charset="utf-8">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
The accesskey attribute specifies a shortcut key to activate/focus an element.
Note: The way of accessing the shortcut key is varying in different browsers:
Browser | Windows | Linux | Mac |
---|---|---|---|
Internet Explorer | [Alt] + accesskey | N/A | |
Chrome | [Alt] + accesskey | [Alt] + accesskey | [Control] [Alt] + accesskey |
Firefox | [Alt] [Shift] + accesskey | [Alt] [Shift] + accesskey | [Control] [Alt] + accesskey |
Safari | [Alt] + accesskey | N/A | [Control] [Alt] + accesskey |
Opera | Opera 15 or newer: [Alt] + accesskey Opera 12.1 or older: [Shift] [Esc] + accesskey |
However, in most browsers the shortcut can be set to another combination of keys.
Tip: The behavior if more than one element has the same access key differs:
The accesskey is part of the Global Attributes, and can be used on any HTML element.
Element | Attribute |
---|---|
All HTML elements | accesskey |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<a href="https://horje.com/sub/31/196/html" accesskey="h">HTML tutorial</a><br>
<a href="https://horje.com/sub/31/364/css" accesskey="c">CSS tutorial</a>
<p>The accesskey attribute specifies a shortcut key to activate/focus an element.</p>
<p><strong>Note:</strong> The shortcut is varying in different browsers:</p>
<ul>
<li>Edge, IE, Chrome, Safari, Opera 15+: [ALT] + <em>accesskey</em></li>
<li>Opera prior version 15: [SHIFT] [ESC] + <em>accesskey</em></li>
<li>Firefox: [ALT] [SHIFT] + <em>accesskey</em></li>
</ul>
</body>
</html>
The action
attribute specifies where to send the form-data when a form is submitted.
The action
attribute can be used on the following element:
Element | Attribute |
---|---|
<form> | action |
Example:
HTML
<form action="/action_page.php" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
The alt attribute provides alternative information for an image if a user for some reason cannot view it (because of slow connection, an error in the src attribute, or if the user uses a screen reader).
Note: The alt attribute is required for the <img> element.
Note: For <input> elements, the alt attribute can only be used with <input type="image">.
Tip: To create a tooltip for an image, use the title attribute!
The alt attribute can be used on the following elements:
Elements | Attribute |
---|---|
<area> | alt |
<img> | alt |
<input> | alt |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The map and area elements</h1>
<p>Click on the computer, the phone, or the cup of coffee to go to a new page and read more about the topic:</p>
<img src="https://horje.com/avatar.png" alt="Workplace" usemap="#workmap" width="400" height="379">
<map name="workmap">
<area shape="rect" coords="34,44,270,350" alt="Computer" href="computer.htm">
<area shape="rect" coords="290,172,333,250" alt="Phone" href="phone.htm">
<area shape="circle" coords="337,300,44" alt="Cup of coffee" href="coffee.htm">
</map>
</body>
</html>
The img element.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The img element</h1>
<img src="https://horje.com/avatar.png" alt="Girl in a jacket" width="500" height="600">
</body>
</html>
Note: The image input type sends the X and Y coordinates of the click that activated the image button as default.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The input alt attribute</h1>
<p>Click on the image, and the input will be sent to a page on the server called "/action_page.php".</p>
<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname">
<input type="image" src="https://horje.com/avatar.png" alt="Submit" width="48" height="48">
</form>
<p><b>Note:</b> The image input type sends the X and Y coordinates of the click that activated the image button as default.</p>
</body>
</html>
The alt
attribute has the following browser support for each element.
The async
attribute is a boolean attribute.
When present, it specifies that the script will be executed asynchronously as soon as it is available.
Note: The async
attribute is only for external scripts (and should only be used if the src
attribute is present).
Note: There are several ways an external script can be executed:
async
is present: The script is executed asynchronously with the rest of the page (the script will be executed while the page continues the parsing) async
is not present and defer
is present: The script is executed when the page has finished parsing async
or defer
is present: The script is fetched and executed immediately, before the browser continues parsing the pageThe async
attribute can be used on the following element:
Elements | Attribute |
---|---|
<script> | async |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The script async attribute</h1>
<p id="p1">Hello World!</p>
<script src="demo_async.js" async></script>
</body>
</html>
The autocomplete
attribute specifies whether a form or an input field should have autocomplete on or off.
Autocomplete allows the browser to predict the value. When a user starts to type in a field, the browser should display options to fill in the field, based on earlier typed values.
Tip: It is possible to have autocomplete "on" for the form, and "off" for specific input fields, or vice versa.
Note: The autocomplete
attribute works with the following <input>
types: text, search, url, tel, email, password, datepickers, range, and color.
The autocomplete
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<form> | autocomplete |
<input> | autocomplete |
The autocomplete
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The form autocomplete attribute</h1>
<p>Fill in and submit the form, then reload the page, start to fill in the form again - and see how autocomplete works.</p>
<p>Then, try to set autocomplete to "off".</p>
<form action="/action_page.php" method="get" autocomplete="on">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="email">Email:</label>
<input type="text" id="email" name="email"><br><br>
<input type="submit">
</form>
<p><b>Note:</b> The autocomplete attribute of the form element is not supported in Opera 12 and earlier versions.</p>
</body>
</html>
Fill in and submit the form, then reload the page to see how autocomplete works.
Notice that autocomplete is "on" for the form, but "off" for the e-mail field!
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The autocomplete attribute</h1>
<p>Fill in and submit the form, then reload the page to see how autocomplete works.</p>
<p>Notice that autocomplete is "on" for the form, but "off" for the e-mail field!</p>
<form action="/action_page.php" autocomplete="on">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" autocomplete="off"><br><br>
<input type="submit">
</form>
</body>
</html>
The autofocus
attribute is a boolean attribute.
When present, it specifies that the element should automatically get focus when the page loads.
The autofocus
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<button> | autofocus |
<input> | autofocus |
<select> | autofocus |
<textarea> | autofocus |
The autofocus
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The button autofocus attribute</h1>
<button type="button" autofocus onclick="alert('Hello world!')">Click Me!</button>
</body>
</html>
Let the "First name" input field automatically get focus when the page loads.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The autofocus attribute</h1>
<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname" autofocus><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit">
</form>
</body>
</html>
The textarea autofocus attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The textarea autofocus attribute</h1>
<textarea rows="4" cols="50" autofocus>
At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies.
</textarea>
</body>
</html>
The autoplay
attribute is a boolean attribute.
When present, the audio/video will automatically start playing as soon as it can do so without stopping.
The autoplay
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<audio> | autoplay |
<video> | autoplay |
The autoplay
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The audio autoplay attribute</h1>
<p>Click on the play button to play a sound:</p>
<audio controls autoplay>
<source src="https://samplelib.com/lib/preview/mp3/sample-3s.mp3" type="audio/ogg">
<source src="https://samplelib.com/lib/preview/mp3/sample-3s.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</body>
</html>
The video autoplay attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The video autoplay attribute</h1>
<video width="320" height="240" controls autoplay>
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_30mb.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
</body>
</html>
When used by the <meta>
element, the charset
attribute specifies the character encoding for the HTML document.
When used by the <script>
element, the charset
attribute specifies the character encoding used in an external script file.
The HTML5 specification encourages web developers to use the UTF-8 character set, which covers almost all of the characters and symbols in the world!
The charset
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<meta> | charset |
<script> | charset |
The charset
attribute has the following browser support for each element.
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<h1>My Website</h1>
<p>Some text...</p>
</body>
</html>
The script charset attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The script charset attribute</h1>
<script charset="UTF-8" src="demo_script_charset.js">
</script>
<p>The Greek characters display correctly because they are part of the "UTF-8" character set.</p>
<p>Try changing character sets to "ISO-8859-1" (default), "windows-1252" or "UTF-16".</p>
</body>
</html>
The checked
attribute is a boolean attribute.
When present, it specifies that an <input>
element should be pre-selected (checked) when the page loads.
The checked
attribute can be used with <input type="checkbox">
and <input type="radio">
.
The checked
attribute can also be set after the page load, with a JavaScript.
The checked
attribute can be used on the following element:
Element | Attribute |
---|---|
<input> | checked |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<form action="/action_page.php">
<input type="checkbox" name="vehicle" value="Bike"> I have a bike<br>
<input type="checkbox" name="vehicle" value="Car" checked> I have a car<br>
<input type="submit" value="Submit">
</form>
The cite
attribute specifies a URL to a document that explains the quote, or why the text was inserted/changed.
The cite
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<blockquote> | cite |
<del> | cite |
<ins> | cite |
<q> | cite |
The cite
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The blockquote element</h1>
<p>Here is a quote from WWF's website:</p>
<blockquote cite="http://www.worldwildlife.org/who/index.html">
For 50 years, WWF has been protecting the future of nature. The world's leading conservation organization, WWF works in 100 countries and is supported by 1.2 million members in the United States and close to 5 million globally.
</blockquote>
</body>
</html>
It is The del cite attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The del cite attribute</h1>
<p><del cite="del_demo_cite.htm">This text has been deleted</del></p>
</body>
</html>
It is The ins cite attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The ins cite attribute</h1>
<p>This is a text. <ins cite="why_inserted.htm">This is an inserted text.</ins></p>
<p><b>Note:</b> The cite attribute does not render as anything special in any of the major browsers.</p>
</body>
</html>
It is The q cite attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The q cite attribute</h1>
<p>WWF's goal is to:
<q cite="http://www.wwf.org">
Build a future where people live in harmony with nature.</q>
We hope they succeed.
</p>
<p><b>Note:</b> The cite attribute has no visual effect in ordinary web browsers, but can be used by screen readers.</p>
</body>
</html>
The class
attribute specifies one or more classnames for an element.
The class
attribute is mostly used to point to a class in a style sheet. However, it can also be used by a JavaScript (via the HTML DOM) to make changes to HTML elements with a specified class.
The class
attribute is part of the Global Attributes, and can be used on any HTML element.
Element | Attribute |
---|---|
All HTML elements | class |
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<style>
h1.intro {
color: blue;
}
p.important {
color: green;
}
</style>
</head>
<body>
<h1 class="intro">Header 1</h1>
<p>A paragraph.</p>
<p class="important">Note that this is an important paragraph. :)</p>
</body>
</html>
The cols
attribute specifies the visible width of a text area.
Tip: The size of a textarea can also be set by the CSS height and width properties.
The cols
attribute can be used on the following element:
Elements | Attribute |
---|---|
<textarea> | cols |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The textarea rows and cols attributes</h1>
<textarea rows="4" cols="50">
At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies.
</textarea>
<p>This textarea has 4 visible rows.</p>
<p>You can change that by changing the value of the "rows" attribute.</p>
</body>
</html>
The colspan
attribute defines the number of columns a table cell should span.
The colspan
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<td> | colspan |
<th> | colspan |
The colspan
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<h1>The td colspan attribute</h1>
<table>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
<tr>
<td colspan="2">Sum: $180</td>
</tr>
</table>
</body>
</html>
The th colspan attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<h1>The th colspan attribute</h1>
<table>
<tr>
<th colspan="2">Monthly Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</table>
</body>
</html>
The content
attribute gives the value associated with the http-equiv
or name
attribute.
The content
attribute can be used on the following element:
Element | Attribute |
---|---|
<meta> | content |
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Free Web tutorials">
<meta name="keywords" content="HTML,CSS,XML,JavaScript">
</head>
<body>
<p>The meta elements of this document describe the document and its keywords.</p>
</body>
</html>
The contenteditable
attribute specifies whether the content of an element is editable or not.
Note: When the contenteditable
attribute is not set on an element, the element will inherit it from its parent.
The contenteditable
attribute is a Global Attribute, and can be used on any HTML element.
Element | Attribute |
---|---|
All HTML elements | contenteditable |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p contenteditable="true">This is a paragraph. It is editable. Try to change this text.</p>
</body>
</html>
The controls
attribute is a boolean attribute.
When present, it specifies that audio/video controls should be displayed.
Controls should include:
The controls
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<audio> | controls |
<video> | controls |
The controls
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The audio controls attribute</h1>
<p>Click on the play button to play a sound:</p>
<audio controls>
<source src="https://freetestdata.com/wp-content/uploads/2021/09/Free_Test_Data_100KB_MP3.mp3" type="audio/ogg">
<source src="https://freetestdata.com/wp-content/uploads/2021/09/Free_Test_Data_100KB_MP3.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</body>
</html>
The video controls attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The video controls attribute</h1>
<video width="320" height="240" controls>
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_1mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_1mb.mp4" type="video/ogg">
Your browser does not support the video tag.
</video>
</body>
</html>
The coords
attribute specifies the coordinates of an area in an image map.
The coords
attribute is used together with the shape
attribute to specify the size, shape, and placement of an area.
Tip: The coordinates of the top-left corner of an area are 0,0.
The coords
attribute can be used on the following element:
Element | Attribute |
---|---|
<area> | coords |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The map and area elements</h1>
<p>Click on the computer, the phone, or the cup of coffee to go to a new page and read more about the topic:</p>
<img src="https://horje.com/avatar.png" alt="Workplace" usemap="#workmap" width="400" height="379">
<map name="workmap">
<area shape="rect" coords="34,44,270,350" alt="Computer" href="computer.htm">
<area shape="rect" coords="290,172,333,250" alt="Phone" href="phone.htm">
<area shape="circle" coords="337,300,44" alt="Cup of coffee" href="coffee.htm">
</map>
</body>
</html>
The data
attribute specifies the URL of the resource to be used by the object.
The data
attribute can be used on the following element:
Element | Attribute |
---|---|
<object> | data |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The object element</h1>
<object data="https://horje.com/avatar.png" width="300" height="200"></object>
</body>
</html>
The data-*
attribute is used to store custom data private to the page or application.
The data-*
attribute gives us the ability to embed custom data attributes on all HTML elements.
The stored (custom) data can then be used in the page's JavaScript to create a more engaging user experience (without any Ajax calls or server-side database queries).
The data-*
attribute consist of two parts:
Note: Custom attributes prefixed with "data-" will be completely ignored by the user agent.
The data-*
attribute is a Global Attribute, and can be used on any HTML element.
Element | Attribute |
---|---|
All HTML elements | data-* |
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<script>
function showDetails(animal) {
let animalType = animal.getAttribute("data-animal-type");
alert("The " + animal.innerHTML + " is a " + animalType + ".");
}
</script>
</head>
<body>
<h1>Species</h1>
<p>Click on a species to see what type it is:</p>
<ul>
<li onclick="showDetails(this)" id="owl" data-animal-type="bird">Owl</li>
<li onclick="showDetails(this)" id="salmon" data-animal-type="fish">Salmon</li>
<li onclick="showDetails(this)" id="tarantula" data-animal-type="spider">Tarantula</li>
</ul>
</body>
</html>
The datetime
attribute specifies the date and time when the text was deleted/inserted.
When used together with the <time>
element, it represents a date and/or time of the <time>
element.
The datetime
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<del> | datetime |
<ins> | datetime |
<time> | datetime |
The datetime
attribute has the following browser support for each element.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The del datetime attribute</h1>
<p><del datetime="2015-11-15T22:55:03Z">This text has been deleted</del></p>
</body>
</html>
This is a text. This is an inserted text.
Note: The datetime attribute does not render as anything special in any of the major browsers.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The ins datetime attribute</h1>
<p>This is a text. <ins datetime="2015-09-15T22:55:03Z">This is an inserted text.</ins></p>
<p><b>Note:</b> The datetime attribute does not render as anything special in any of the major browsers.</p>
</body>
</html>
I have a date on Valentines day.
Note: The time element does not render as anything special in any of the major browsers.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The time datetime attribute</h1>
<p>I have a date on <time datetime="2017-02-14 20:00">Valentines day</time>.</p>
<p><b>Note:</b> The time element does not render as anything special in any of the major browsers.</p>
</body>
</html>
The controls
attribute is a boolean attribute.
When present, it specifies that audio/video controls should be displayed.
Controls should include:
The controls
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<audio> | controls |
<video> | controls |
Example:
HTML
<video width="320" height="240" controls>
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_1mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_1mb.mp4" type="video/ogg">
<track src="subtitles_en.vtt" kind="subtitles" srclang="en" label="English" default>
<track src="subtitles_no.vtt" kind="subtitles" srclang="no" label="Norwegian">
</video>
The video controls attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The video controls attribute</h1>
<video width="320" height="240" controls>
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_1mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_1mb.mp4" type="video/ogg">
Your browser does not support the video tag.
</video>
</body>
</html>
The default
attribute is a boolean attribute.
When present, it specifies that the track is to be enabled if the user's preferences do not indicate that another track would be more appropriate.
Note: There must not be more than one <track>
element with a default
attribute per <media>
element.
The default
attribute can be used on the following element:
Element | Attribute |
---|---|
<track> | default |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<video width="320" height="240" controls>
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_1mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_1mb.mp4" type="video/ogg">
<track src="subtitles_en.vtt" kind="subtitles" srclang="en" label="English" default>
<track src="subtitles_no.vtt" kind="subtitles" srclang="no" label="Norwegian">
</video>
The default
attribute is a boolean attribute.
When present, it specifies that the track is to be enabled if the user's preferences do not indicate that another track would be more appropriate.
Note: There must not be more than one <track>
element with a default
attribute per <media>
element.
The default
attribute can be used on the following element:
Element | Attribute |
---|---|
<track> | default |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_1mb.mp4" type="video/mp4">
<video width="320" height="240" controls>
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_1mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_1mb.mp4" type="video/ogg">
<track src="subtitles_en.vtt" kind="subtitles" srclang="en" label="English" default>
<track src="subtitles_no.vtt" kind="subtitles" srclang="no" label="Norwegian">
</video>
The defer
attribute is a boolean attribute.
When present, it specifies that the script is executed when the page has finished parsing.
Note: The defer
attribute is only for external scripts (should only be used if the src
attribute is present).
Note: There are several ways an external script can be executed:
async
is present: The script is executed asynchronously with the rest of the page (the script will be executed while the page continues the parsing) async
is not present and defer
is present: The script is executed when the page has finished parsing async
or defer
is present: The script is fetched and executed immediately, before the browser continues parsing the pageThe defer
attribute can be used on the following element:
Element | Attribute |
---|---|
<script> | defer |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The script defer attribute</h1>
<script src="demo_defer.js" defer></script>
<p>The script above requests information from the paragraph below. Normally, this is not possible, because the script is executed before the paragraph exists.</p>
<p id="p1">Hello World!</p>
<p>However, the defer attribute specifies that the script should be executed later. This way the script can request information from the paragraph.</p>
</body>
</html>
The dir
attribute specifies the text direction of the element's content.
The dir
attribute can have the following values:
The dir
attribute is a Global Attribute, and can be used on any HTML element.
Element | Attribute |
---|---|
All HTML elements | dir |
Example:
TRY
<!DOCTYPE html>
<html>
<body>
<p dir="rtl">Write this text right-to-left!</p>
</body>
</html>
The dirname
attribute enables the submission of the text direction of the input field/textarea
The dirname
attribute's value is always the name of the input field/textarea, followed by ".dir".
The dirname
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<input> | dirname |
<textarea> | dirname |
The dirname
attribute has the following browser support for each element.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The dirname attribute</h1>
<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname" dirname="fname.dir">
<input type="submit" value="Submit">
</form>
<p>When the form is being submitted, the text direction of the input field will also be submitted.</p>
</body>
</html>
Textarea Example.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The textarea dirname attribute</h1>
<form action="/action_page.php">
Text:<br>
<textarea name="explanation"dirname="explanation.dir"></textarea>
<input type="submit" value="Submit">
</form>
<p>When the form is being submitted, the text direction of the textarea will also be submitted.</p>
</body>
</html>
The disabled
attribute is a boolean attribute.
When present, it specifies that the element should be disabled.
A disabled element is unusable.
The disabled
attribute can be set to keep a user from using the element until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the element usable again.
The disabled
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<button> | disabled |
<fieldset> | disabled |
<input> | disabled |
<optgroup> | disabled |
<option> | disabled |
<select> | disabled |
<textarea> | disabled |
The disabled
attribute has the following browser support for each element.
Example:
HTML
<button type="button" disabled>Click Me!</button>
Fieldset Example.
Example:
HTML
<fieldset disabled>
<legend>Personalia:</legend>
Name: <input type="text"><br>
Email: <input type="text"><br>
Date of birth: <input type="text">
</fieldset>
An HTML form with a disabled input field.
Example:
HTML
<form action="/action_page.php">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname" disabled><br>
<input type="submit" value="Submit">
</form>
Optgroup Example. A disabled option-group.
Example:
HTML
<select>
<optgroup label="German Cars" disabled>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</optgroup>
</select>
Option Example. A drop-down list with one disabled option.
Example:
HTML
<select>
<option value="volvo" disabled>Volvo</option>
<option value="saab">Saab</option>
<option value="vw">VW</option>
<option value="audi">Audi</option>
</select>
Select Example.
Example:
HTML
<select disabled>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
Textarea Example.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The textarea disabled attribute</h1>
<textarea disabled>
At Horje.com you will learn how to make a website. We offer free tutorials in all web development technologies.
</textarea>
</body>
</html>
The download
attribute specifies that the target will be downloaded when a user clicks on the hyperlink.
This attribute is only used if the href attribute is set.
The value of the download
attribute will be the new name of the downloaded file. There are no restrictions on allowed values, and the browser will automatically detect the correct file extension and add it to the file (.img, .pdf, .txt, .html, etc.).
If the value is omitted, the original filename is used.
The download
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<a> | download |
<area> | download |
The download
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The a download attribute</h1>
<p>Click on the image to download it:<p>
<a href="https://horje.com/avatar.png" download>
<img src="https://horje.com/avatar.png" alt="Horje" width="104" height="142">
</a>
<p><b>Note:</b> The download attribute is not supported in IE or Edge (prior version 18), or in Safari (prior version 10.1).</p>
</body>
</html>
Area Example.
Click on the sun or on one of the planets to download its content.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The area download attribute</h1>
<p>Click on the sun or on one of the planets to download its content.</p>
<img src="https://horje.com/avatar.png" width="145" height="126" alt="Planets" usemap="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun" href="https://horje.com/avatar.png" download>
<area shape="circle" coords="90,58,3" alt="Mercury" href="merglobe.gif" download>
<area shape="circle" coords="124,58,8" alt="Venus" href="https://horje.com/avatar.png" download>
</map>
<p><b>Note:</b> The download attribute is not supported in IE, Safari or Opera version 12 (and earlier).</p>
</body>
</html>
The draggable
attribute specifies whether an element is draggable or not.
Tip: Links and images are draggable by default.
Tip: The draggable
attribute is often used in drag and drop operations. Read our HTML Drag and Drop tutorial to learn more.
The draggable
attribute is a Global Attribute, and can be used on any HTML element.
Element | Attribute |
---|---|
All HTML elements | draggable |
The numbers in the table specify the first browser version that fully supports the attribute.
<p draggable="true">This is a draggable paragraph.</p>
The enctype
attribute specifies how the form-data should be encoded when submitting it to the server.
Note: The enctype
attribute can be used only if method="post"
.
The enctype
attribute can be used on the following element:
Element | Attribute |
---|---|
<form> | enctype |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The form enctype attribute</h1>
<form action="/action_page_binary.asp" method="post" enctype="multipart/form-data">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
The enterkeyhint
attribute allows you to change the appearance of the "Enter" key on a virtual keyboard.
Here is an input field with the enterkeyhint value set to "search":
<input type="text" enterkeyhint="search">
Result (do you see the blue "search" button):
If you set the enterkeyhint value to "go":
<input type="text" enterkeyhint="go">
The result will be like this:
The enterkeyhint
attribute is a Global Attribute, and can be used on any HTML element, but the element must be editable.
Element | Attribute |
---|---|
All HTML elements | enterkeyhint |
Example:
HTML
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
font-family:"Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
text-align:center;
}
</style>
<body>
<h2>The enterkeyhint Attribute</h2>
<p>Browse this page with a phone.</p>
<p>Click the input field:</p>
<input type="text" enterkeyhint="search">
<p>And check the "Enter" button on the keyboard.</p>
</body>
</html>
When used together with the <label>
element, the for
attribute specifies which form element a label is bound to.
When used together with the <output>
element, the for
attribute specifies the relationship between the result of the calculation, and the elements used in the calculation.
The for
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<label> | for |
<output> | for |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The label element</h1>
<p>Click on one of the text labels to toggle the related radio button:</p>
<form action="/action_page.php">
 <input type="radio" id="html" name="fav_language" value="HTML">
 <label for="html">HTML</label><br>
 <input type="radio" id="css" name="fav_language" value="CSS">
 <label for="css">CSS</label><br>
 <input type="radio" id="javascript" name="fav_language" value="JavaScript">
 <label for="javascript">JavaScript</label><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Output Example.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The output element</h1>
<form oninput="x.value=parseInt(a.value)+parseInt(b.value)">
<input type="range" id="a" value="50">
+<input type="number" id="b" value="25">
=<output name="x" for="a b"></output>
</form>
<p><strong>Note:</strong> The output element is not supported in Edge 12 (or earlier).</p>
</body>
</html>
The form
attribute specifies the form the element belongs to.
The value of this attribute must be equal to the id
attribute of a <form>
element in the same document.
The form
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<button> | form |
<fieldset> | form |
<input> | form |
<label> | form |
<meter> | form |
<object> | form |
<output> | form |
<select> | form |
<textarea> | form |
The form
attribute has the following browser support for each element:
Example:
HTML
<form action="/action_page.php" method="get" id="form1">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
</form>
<button type="submit" form="form1" value="Submit">Submit</button>
Fieldset Example.
Example:
HTML
<form action="/action_page.php" method="get" id="form1">
What is your favorite color? <input type="text" name="fav_color"><br>
<input type="submit">
</form>
<fieldset form="form1">
Name: <input type="text" name="username"><br>
Email: <input type="text" name="usermail"><br>
</fieldset>
Input Example.
Example:
HTML
<form action="/action_page.php" id="form1">
First name: <input type="text" name="fname"><br>
<input type="submit" value="Submit">
</form>
Last name: <input type="text" name="lname" form="form1">
Label Example.
Example:
HTML
<form action="/action_page.php" id="form1">
<input type="radio" id="html" name="fav_language" value="HTML"><br>
<input type="radio" id="css" name="fav_language" value="CSS">
<label for="css">CSS</label><br>
<input type="radio" id="javascript" name="fav_language" value="JavaScript">
<label for="javascript">JavaScript</label><br><br>
<input type="submit" value="Submit">
</form>
<label for="html">HTML</label>
Meter Example.
Example:
HTML
<form action="/action_page.php" method="get" id="form1">
First name: <input type="text" name="fname"><br>
<input type="submit" value="Submit">
</form>
<meter form="form1" name="x1" min="0" low="40" high="90" max="100" value="95"></meter>
Object Example.
Example:
HTML
<form action="/action_page.php" id="form1">
First name: <input type="text" name="fname"><br>
<input type="submit" value="Submit">
</form>
<object data="helloworld.swf" height="400" width="400" form="form1" name="obj1"></object>
Output Example.
Example:
HTML
<form action="/action_page.php" id="numform"
oninput="x.value=parseInt(a.value)+parseInt(b.value)">0
<input type="range" id="a" name="a" value="50">100
+<input type="number" id="b" name="b" value="50">
<br><br>
<input type="submit">
</form>
<output form="numform" name="x" for="a b"></output>
Select Example.
Example:
HTML
<form action="/action_page.php" id="carform">
Firstname:<input type="text" name="fname">
<input type="submit">
</form>
<select name="carlist" form="carform">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
Textarea Example.
Example:
HTML
<form action="/action_page.php" id="usrform">
Name: <input type="text" name="usrname">
<input type="submit">
</form>
<textarea name="comment" form="usrform">Enter text here...</textarea>
The formaction
attribute specifies where to send the form-data when a form is submitted. This attribute overrides the form's action
attribute.
The formaction
attribute is only used for inputs/buttons with type="submit"
.
The formaction
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<button> | formaction |
<input> | formaction |
The formaction
attribute has the following browser support for each element:
Example:
HTML
<form action="/action_page.php" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<button type="submit">Submit</button><br>
<button type="submit" formaction="/action_page2.php">Submit to another page</button>
</form>
Input Example.
Example:
HTML
<form action="/action_page.php">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit"><br>
<input type="submit" formaction="/action_page2.php" value="Submit to another page">
</form>
The headers
attribute specifies one or more header cells a table cell is related to.
The headers
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<td> | headers |
<th> | headers |
The headers
attribute has the following browser support for each element.
Example:
HTML
<table>
<tr>
<th id="name">Name</th>
<th id="email">Email</th>
<th id="phone">Phone</th>
<th id="addr">Address</th>
</tr>
<tr>
<td headers="name">John Doe</td>
<td headers="email">[email protected]</td>
<td headers="phone">+45342323</td>
<td headers="addr">Rosevn 56,4300 Sandnes,Norway</td>
</tr>
</table>
Th Example.
Example:
HTML
<table>
<tr>
<th id="name" colspan="2">Name</th>
</tr>
<tr>
<th headers="name">Firstname</th>
<th headers="name">Lastname</th>
</tr>
</table>
The height
attribute specifies the height of the element, in pixels.
The height
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<canvas> | height |
<embed> | height |
<iframe> | height |
<img> | height |
<input> | height |
<object> | height |
<video> | height |
The height
attribute has the following browser support for each element.
Example:
HTML
<canvas id="myCanvas" width="200" height="200" style="border:1px solid">
Example:
HTML
<embed src="helloworld.swf" width="200" height="200">
Example:
HTML
<iframe src="https://horje.com" width="200" height="200">
</iframe>
Example:
HTML
<img src="smiley.gif" alt="Smiley face" height="42" width="42">
Example:
HTML
<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="image" src="https://horje.com/avatar.png" alt="Submit" width="48" height="48">
</form>
Example:
HTML
<object data="https://horje.com/avatar.png" width="300" height="200"></object>
Example:
HTML
<video width="320" height="240" controls>
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_2mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_2mb.mp4" type="video/ogg">
Your browser does not support the video tag.
</video>
The hidden
attribute is a boolean attribute.
When present, it specifies that an element is not yet, or is no longer, relevant.
Browsers should not display elements that have the hidden
attribute specified.
The hidden
attribute can also be used to keep a user from seeing an element until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the hidden attribute, and make the element visible.
The hidden
attribute is a Global Attribute, and can be used on any HTML element.
Element | Attribute |
---|---|
All HTML elements | hidden |
Example:
HTML
<p hidden>This paragraph should be hidden.</p>
<p>This is a visible paragraph.</p>
The high
attribute specifies the range where the gauge's value is considered to be a high value.
The high
attribute value must be less than the max
attribute value, and it also must be greater than the low
and min
attribute values.
The high
attribute can be used on the following element:
Element | Attribute |
---|---|
<meter> | high |
Example:
HTML
<meter min="0" low="40" high="90" max="100" value="95"></meter>
For <a>
and <area>
elements, the href
attribute specifies the URL of the page the link goes to.
For <base>
elements, the href
attribute specifies the base URL for all relative URLs on a page.
For <link>
elements, the href
attribute specifies the location (URL) of the external resource (most often a style sheet file).
The href
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<a> | href |
<area> | href |
<base> | href |
<link> | href |
The href
attribute has the following browser support for each element.
Example:
HTML
<p>An absolute URL: <a href="https://horje.com">Horje</a></p>
<p>A relative URL: <a href="tag_a.asp">The a tag</a></p>
Click on the computer, the phone, or the cup of coffee to go to a new page and read more about the topic:
Example:
HTML
<img src="https://horje.com/avatar.png" alt="Workplace" usemap="#workmap" width="400" height="379">
<map name="workmap">
<area shape="rect" coords="34,44,270,350" alt="Computer" href="computer.htm">
<area shape="rect" coords="290,172,333,250" alt="Phone" href="phone.htm">
<area shape="circle" coords="337,300,44" alt="Cup of coffee" href="coffee.htm">
</map>
Base Example.
Example:
HTML
<head>
<base href="https://horje.com">
</head>
Link Example.
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://www.w3schools.com/tags/styles.css">
</head>
<body>
<h1>Hello World!</h1>
<h2>I am formatted with a linked style sheet.</h2>
<p>Me too!</p>
</body>
</html>
The hreflang
attribute specifies the language of the linked document.
Note: This attribute is purely advisory.
The hreflang
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<a> | hreflang |
<area> | hreflang |
<link> | hreflang |
The hreflang
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The a hreflang attribute</h1>
<p><a hreflang="en" href="https://horje.com">Horje.com</a></p>
</body>
</html>
Example:
HTML
<img src="https://horje.com/avatar.png" width="145" height="126" alt="Planets" usemap="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.htm" hreflang="en">
</map>
Example:
HTML
<link href="tag_link.asp" rel="parent" rev="subsection" hreflang="en">
The http-equiv
attribute provides an HTTP header for the information/value of the content
attribute.
The http-equiv
attribute can be used to simulate an HTTP response header.
The http-equiv
attribute can be used on the following element:
Element | Attribute |
---|---|
http-equiv |
Example:
HTML
<meta http-equiv="refresh" content="30">
The id
attribute specifies a unique id for an HTML element (the value must be unique within the HTML document).
The id
attribute is most used to point to a style in a style sheet, and by JavaScript (via the HTML DOM) to manipulate the element with the specific id.
The id
attribute is a Global Attribute, and can be used on any HTML element.
Element | Attribute |
---|---|
All HTML elements | id |
Example:
HTML
<!DOCTYPE HTML>
<html>
<body>
<h1 id="myHeader">Hello World!</h1>
<button onclick="displayResult()">Change text</button>
<script>
function displayResult() {
document.getElementById("myHeader").innerHTML = "Have a nice day!";
}
</script>
</body>
</html>
The inert
attribute disables an element and all the elements inside.
The elements are still visible, but they have no function: buttons and links cannot be clicked, input fields are disabled etc., and they are ignored by screen readers.
The inert
attribute is a Global Attribute, and can be used on any HTML element.
Element | Attribute |
---|---|
All HTML elements | inert |
Example:
HTML
<div inert>
<button onclick="alert(42)">
<input type="text">
<a href="https://horje.com">Horje.com</a>
</div>
The inputmode
attribute allows you to change the appearance of the keyboard on a phone or tablet (any device with a virtual keyboard).
Here is an input field wtih the input mode set so "numeric":
<input type="text" inputmode="numeric">
Result:
If you set inputmode to "email":
<input type="text" inputmode="email">
The result will be like this:
The inputmode
attribute is a Global Attribute, and can be used on any HTML element, but the element must be editable.
Element | Attribute |
---|---|
All HTML elements | inputmode |
Example:
HTML
<input type="text" inputmode="numeric">
The ismap
attribute is a boolean attribute.
When present, it specifies that the image is part of a server-side image map (an image map is an image with clickable areas).
When clicking on a server-side image map, the click coordinates are sent to the server as a URL query string.
Note: The ismap
attribute is allowed only if the <img>
element is a descendant of an <a>
element with a valid href
attribute.
The ismap
attribute can be used on the following element:
Element | Attribute |
---|---|
<img> | ismap |
Example:
HTML
<a href="/action_page.php">
<img src="https://horje.com/avatar.png" alt="Horje.com" width="100" height="132" ismap>
</a>
The kind
attribute specifies the kind of text track.
The kind
attribute can be used on the following element:
Element | Attribute |
---|---|
<track> | kind |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<video width="320" height="240" controls>
<source src="https://www.sample-videos.com/video321/flv/360/big_buck_bunny_360p_5mb.flv" type="video/mp4">
<source src="https://www.sample-videos.com/video321/flv/360/big_buck_bunny_360p_5mb.flv" type="video/ogg">
<track src="subtitles_en.vtt" kind="subtitles" srclang="en" label="English">
<track src="subtitles_no.vtt" kind="subtitles" srclang="no" label="Norwegian">
</video>
The label
attribute specifies the title of the text track.
The title of the text track is used by the browser when listing available text tracks.
The label
attribute can be used on the following element:
Element | Attribute |
---|---|
<track> | label |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<video width="320" height="240" controls>
<source src="https://www.sample-videos.com/video321/flv/360/big_buck_bunny_360p_5mb.flv" type="video/mp4">
<source src="https://www.sample-videos.com/video321/flv/360/big_buck_bunny_360p_5mb.flv" type="video/ogg">
<track src="subtitles_en.vtt" kind="subtitles" srclang="en" label="English">
<track src="subtitles_no.vtt" kind="subtitles" srclang="no" label="Norwegian">
</video>
The lang
attribute specifies the language of the element's content.
Common examples are "en" for English, "es" for Spanish, "fr" for French and so on.
The lang
attribute is a Global Attribute, and can be used on any HTML element.
Element | Attribute |
---|---|
All HTML elements | lang |
Example:
HTML
<p lang="fr">Ceci est un paragraphe.</p>
The list
attribute refers to a <datalist>
element that contains pre-defined options for an <input>
element.
The list
attribute can be used on the following element:
Element | Attribute |
---|---|
<input> | list |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<input list="browsers">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Google Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
The loop
attribute is a boolean attribute.
When present, it specifies that the audio will start over again, every time it is finished.
The loop
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<audio> | loop |
<video> | loop |
The loop
attribute has the following browser support for each element:
Example:
HTML
<audio controls loop>
<source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="audio/ogg">
<source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Example:
HTML
<video width="320" height="240" controls loop>
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_30mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_30mb.mp4" type="video/ogg">
Your browser does not support the video tag.
</video>
The low
attribute specifies the range where the gauge's value is considered to be a low value.
The low
attribute value must be greater than the min
attribute value, and it also must be less than the high
and max
attribute values.
The low
attribute can be used on the following element:
Element | Attribute |
---|---|
<meter> | low |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<meter min="0" low="40" high="90" max="100" value="95"></meter>
The max
attribute specifies the maximum value of the element.
When used by the <progress>
element, the max
attribute specifies how much work the task requires in total.
The max
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<input> | max |
<meter> | max |
<progress> | max |
The max
attribute has the following browser support for each element.
Example:
HTML
<form action="/action_page.php">
<label for="datemax">Enter a date before 1980-01-01:</label>
<input type="date" id="datemax" name="datemax" max="1979-12-31"><br><br>
<label for="datemin">Enter a date after 2000-01-01:</label>
<input type="date" id="datemin" name="datemin" min="2000-01-02"><br><br>
<label for="quantity">Quantity (between 1 and 5):</label>
<input type="number" id="quantity" name="quantity" min="1" max="5"><br><br>
<input type="submit">
</form>
Example:
HTML
<meter min="0" low="40" high="90" max="100" value="95"></meter>
Example:
HTML
<progress value="22" max="100"></progress>
The maxlength
attribute specifies the maximum number of characters allowed in the element.
The maxlength
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<input> | maxlength |
<textarea> | maxlength |
The maxlength
attribute has the following browser support for each element.
Example:
HTML
<form action="/action_page.php">
<label for="username">Username:</label>
<input type="text" id="username" name="username" maxlength="10"><br><br>
<input type="submit" value="Submit">
</form>
Example:
HTML
<textarea maxlength="50">
Enter text here...
</textarea>
The media
attribute specifies what media/device the linked document is optimized for.
This attribute is used to specify that the target URL is designed for special devices (like iPhone) , speech or print media.
This attribute can accept several values.
The media
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<a> | media |
<area> | media |
<link> | media |
<source> | media |
<style> | media |
The media
attribute has the following browser support for each element.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The a media attribute</h1>
<p>
<a href="att_a_media.asp?output=print" media="print and (resolution:300dpi)">Open media attribute page for print</a>
</p>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The area media attribute</h1>
<p>Click on the sun to watch it closer:</p>
<img src="https://horje.com/avatar.png" width="145" height="126" alt="Planets" usemap="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.htm" media="screen and (min-color-index:256)">
</map>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://www.w3schools.com/tags/demo_screen.css">
<link rel="stylesheet" type="text/css" href="https://www.w3schools.com/tags/demo_print.css" media="print">
</head>
<body>
<h1>Horje Example</h1>
<p><a href="tryhtml_link_media.htm" target="_blank">Click here</a> to open this page in a new window (without the tryit part).</p>
<p>If you print this page, or open it in print preview, you will see that it is styled with the media="print" stylesheet. The "print" stylesheet contains black text on white background.</p>
</body>
</html>
Example:
HTML
<picture>
<source media="(min-width: 650px)" srcset="https://horje.com/avatar.png">
<source media="(min-width: 465px)" srcset="https://horje.com/avatar.png">
<img src="https://horje.com/avatar.png" alt="Flowers" style="width:auto;">
</picture>
Example:
HTML
<style>
h1 {color:#FF0000;}
p {color:#0000FF;}
body {background-color:#FFEFD6;}
</style>
The method
attribute specifies how to send form-data (the form-data is sent to the page specified in the action
attribute).
The form-data can be sent as URL variables (with method="get"
) or as HTTP post transaction (with method="post"
).
Notes on GET:
Notes on POST:
The method
attribute can be used on the following element:
Element | Attribute |
---|---|
<form> | method |
Example:
HTML
<form action="/action_page.php" method="get" target="_blank">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit">
</form>
The min
attribute specifies the minimum value of an element element.
When used together with the <meter>
element, the min
attribute specifies the lower bound of the gauge.
The min
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<input> | min |
<meter> | min |
The min
attribute has the following browser support for each element
Example:
HTML
<form action="/action_page.php">
Enter a date before 1980-01-01:
<input type="date" name="bday" max="1979-12-31">
Enter a date after 2000-01-01:
<input type="date" name="bday" min="2000-01-02">
Quantity (between 1 and 5):
<input type="number" name="quantity" min="1" max="5">
<input type="submit">
</form>
Example:
HTML
<meter min="0" low="40" high="90" max="100" value="95"></meter>
The multiple
attribute is a boolean attribute.
When present, it specifies that the user is allowed to enter/select more than one value.
The multiple
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<input> | multiple |
<select> | multiple |
The multiple
attribute has the following browser support for each element:
Example:
HTML
<form action="/action_page.php">
Select images: <input type="file" name="img" multiple>
<input type="submit">
</form>
Example:
HTML
<select multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
The muted
attribute is a boolean attribute.
When present, it specifies that the audio output of the video should be muted.
The muted
attribute can be used on the following element:
Element | Attribute |
---|---|
<video> | muted |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<video width="320" height="240" controls muted>
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_5mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_5mb.mp4" type="video/ogg">
Your browser does not support the video tag.
</video>
The name
attribute specifies a name for an HTML element.
This name
attribute can be used to reference the element in a JavaScript.
For a <form>
element, the name
attribute is used as a reference when the data is submitted.
For an <iframe>
element, the name
attribute can be used to target a form submission.
For a <map>
element, the name
attribute is associated with the <img>
's usemap
attribute and creates a relationship between the image and the map.
For a <meta>
element, the name
attribute specifies a name for the information/value of the content
attribute.
For a <param>
element, the name
attribute is used together with the value
attribute to specify parameters for the plugin specified with the <object>
tag.
The name
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<button> | name |
<fieldset> | name |
<form> | name |
<iframe> | name |
<input> | name |
<map> | name |
<meta> | name |
<object> | name |
<output> | name |
<param> | name |
<select> | name |
<textarea> | name |
The name
attribute has the following browser support for each element.
Example:
HTML
<form action="/action_page.php" method="get">
Choose your favorite subject:
<button name="subject" type="submit" value="HTML">HTML</button>
<button name="subject" type="submit" value="CSS">CSS</button>
</form>
Example:
HTML
<fieldset name="personalia">
Name: <input type="text"><br>
Email: <input type="text"><br>
</fieldset>
Example:
HTML
<form action="/action_page.php" method="get" name="myForm">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="button" onclick="formSubmit()" value="Send form data!">
</form>
Example:
HTML
<iframe src="https://horje.com/" name="iframe_a">
<p>Your browser does not support iframes.</p>
</iframe>
</br>
<a href="https://horje.com/" target="iframe_a">Horje.com</a>
Example:
HTML
<form action="/action_page.php">
Name: <input type="text" name="fullname"><br>
Email: <input type="text" name="email"><br>
<input type="submit" value="Submit">
</form>
Example:
HTML
<img src="https://horje.com/avatar.png" alt="Workplace" usemap="#workmap" width="400" height="379">
<map name="workmap">
<area shape="rect" coords="34,44,270,350" alt="Computer" href="computer.htm">
<area shape="rect" coords="290,172,333,250" alt="Phone" href="phone.htm">
<area shape="circle" coords="337,300,44" alt="Cup of coffee" href="coffee.htm">
</map>
Example:
HTML
<head>
<meta name="description" content="Free Web tutorials">
<meta name="keywords" content="HTML,CSS,JavaScript">
<meta name="author" content="Hege Refsnes">
</head>
Example:
HTML
<object data="https://horje.com/avatar.png" name="obj1" width="300" height="200">
</object>
Example:
HTML
<form oninput="x.value=parseInt(a.value)+parseInt(b.value)">0
<input type="range" id="a" value="50">100
+<input type="number" id="b" value="50">
=<output name="x" for="a b"></output>
</form>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The param element</h1>
<object data="https://download.samplelib.com/wav/sample-3s.wav">
<param name="autoplay" value="true">
</object>
</body>
</html>
Example:
HTML
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
Example:
HTML
<form action="/action_page.php">
<textarea name="comment">Enter text here...</textarea>
<input type="submit">
</form>
The novalidate
attribute is a boolean attribute.
When present, it specifies that the form-data (input) should not be validated when submitted.
The novalidate
attribute can be used on the following element:
Element | Attribute |
---|---|
<form> | novalidate |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<form action="/action_page.php" novalidate>
E-mail: <input type="email" name="user_email">
<input type="submit">
</form>
The onabort
attribute defines a script to be run if the loading of the media file aborts.
This event occurs when the media data download has been aborted, and not because of an error.
The onabort
attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | onabort |
<embed> | onabort |
<img> | onabort |
<object> | onabort |
<video> | onabort |
The onabort
attribute has the following browser support for each element
Example:
HTML
<video id="myVideo" onabort="alert('Video load aborted')">
The onafterprint
attribute fires when a page has started printing, or if the print dialogue box has been closed.
Tip: The onafterprint
attribute is often used together with the onbeforeprint
attribute.
The onafterprint
attribute is part of the Event Attributes, and can be used on the following element:
Elements | Event |
---|---|
<body> | onafterprint |
Example:
HTML
<script>
function myFunction() {
alert("This document is now being printed");
}
</script>
The onbeforeprint
attribute fires when a page is about to be printed (before the print dialogue box appears).
Tip: The onbeforeprint
attribute is often used together with the onafterprint
attribute.
The onbeforeprint
attribute is part of the Event Attributes, and can be used on the following element:
Elements | Event |
---|---|
<body> | onbeforeprint |
Example:
HTML
<h1>Try to print this document</h1>
<p><b>Tip:</b> Keyboard shortcuts, such as Ctrl+P sets the page to print.</p>
<p><b>Note:</b> The onbeforeprint event is not supported in Safari and Opera.</p>
<script>
function myFunction() {
alert("You are about to print this document!");
}
</script>
The onbeforeunload
event fires when the document is about to be unloaded.
This event allows you to display a message in a confirmation dialog box to inform the user whether he/she wants to stay or leave the current page.
The default message that appears in the confirmation box, is different in different browsers. However, the standard message is something like "Are you sure you want to leave this page?". You cannot remove this message.
However, you can write a custom message together with the default message. See the first example on this page.
Note: In Firefox, only the default message will be displayed (not the custom message (if any)).
The onbeforeunload
attribute is part of the Event Attributes, and can be used on the following element:
Elements | Event |
---|---|
<body> | onbeforeunload |
The numbers in the table specify the first browser version that fully supports the event.
Example:
HTML
<!DOCTYPE html>
<html>
<body onbeforeunload="return myFunction()">
<p>Close this window, press F5 or click on the link below to invoke the onbeforeunload event.</p>
<a href="https://horje.com">Click here to go to horje.com</a>
<script>
function myFunction() {
return "Write something clever here...";
}
</script>
</body>
</html>
The onblur
attribute fires the moment that the element loses focus.
Onblur is most often used with form validation code (e.g. when the user leaves a form field).
Tip: The onblur
attribute is the opposite of the onfocus
attribute.
The onblur
attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | onblur |
Example:
HTML
Enter your name: <input type="text" name="fname" id="fname" onblur="myFunction()">
<p>When you leave the input field, a function is triggered which transforms the input text to upper case.</p>
<script>
function myFunction() {
let x = document.getElementById("fname");
x.value = x.value.toUpperCase();
}
</script>
The oncanplay
attribute defines a script to run when the browser can start playing the specified media (when it has buffered enough to begin).
The oncanplay
attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | canplay |
<embed> | canplay |
<object> | canplay |
<video> | canplay |
The oncanplay
attribute has the following browser support for each element:
Example:
HTML
<audio id="myAudio" controls oncanplay="myFunction()">
<source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="audio/ogg">
<source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<script>
function myFunction() {
alert("Can start playing the audio");
}
</script>
Video Example.
Example:
HTML
<video id="myVideo" width="320" height="176" controls oncanplay="myFunction()">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_20mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_20mb.mp4" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<script>
function myFunction() {
alert("Can start playing video");
}
</script>
The oncanplaythrough
event occurs when the browser estimates it can play through the specified audio/video without having to stop for buffering.
The oncanplaythrough
attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | canplaythrough |
<video> | canplaythrough |
The oncanplaythrough
attribute has the following browser support for each element.
Example:
HTML
<audio id="myAudio" controls oncanplaythrough="myFunction()">
<source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="audio/ogg">
<source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<script>
function myFunction() {
alert("Can play the audio without any buffering");
}
</script>
Example:
HTML
<video id="myVideo" width="320" height="176" controls oncanplaythrough="myFunction()">
<source src="https://www.sample-videos.com/video321/flv/240/big_buck_bunny_240p_10mb.flv" type="video/mp4">
<source src="https://www.sample-videos.com/video321/flv/240/big_buck_bunny_240p_10mb.flv" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<script>
function myFunction() {
alert("Can play the video without buffering");
}
</script>
The onchange
attribute fires the moment when the value of the element is changed.
Tip: This event is similar to the oninput
event. The difference is that the oninput
event occurs immediately after the value of an element has changed, while onchange
occurs when the element loses focus. The other difference is that the onchange
event also works on <select>
elements.
The onchange
attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | onchange |
Example:
HTML
<p>Select a new car from the list.</p>
<select id="mySelect" onchange="myFunction()">
<option value="Audi">Audi
<option value="BMW">BMW
<option value="Mercedes">Mercedes
<option value="Volvo">Volvo
</select>
<p>When you select a new car, a function is triggered which outputs the value of the selected car.</p>
<p id="demo"></p>
<script>
function myFunction() {
let x = document.getElementById("mySelect").value;
document.getElementById("demo").innerHTML = "You selected: " + x;
}
</script>
Example:
HTML
<p>Modify the text in the input field, then click outside the field to fire the onchange event.</p>
Enter some text: <input type="text" name="txt" value="Hello" onchange="myFunction(this.value)">
<script>
function myFunction(val) {
alert("The input value has changed. The new value is: " + val);
}
</script>
The onclick
attribute fires on a mouse click on the element.
The onclick
attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | onclick |
Example:
HTML
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
<p>A function is triggered when the button is clicked. The function outputs some text in a p element with id="demo".</p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello World";
}
</script>
Example:
HTML
<p id="demo" onclick="myFunction()">Click me to change my text color.</p>
<p>A function is triggered when the p element is clicked. The function sets the color of the p element to red.</p>
<script>
function myFunction() {
document.getElementById("demo").style.color = "red";
}
</script>
The oncontextmenu
attribute fires when the user right-clicks on an element to open the context menu.
Note: Although the oncontextmenu
event is supported in all browsers, the contextmenu
attribute is currently only supported in Firefox.
The oncontextmenu
attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | oncontextmenu |
Example:
HTML
<div oncontextmenu="myFunction()" contextmenu="mymenu">
<p>Right-click inside this box to see the context menu!
<menu type="context" id="mymenu">
<menuitem label="Refresh" onclick="window.location.reload();" icon="ico_reload.png"></menuitem>
<menu label="Share on...">
<menuitem label="Twitter" icon="ico_twitter.png" onclick="window.open('//twitter.com/intent/tweet?text=' + window.location.href);"></menuitem>
<menuitem label="Facebook" icon="ico_facebook.png" onclick="window.open('//facebook.com/sharer/sharer.php?u=' + window.location.href);"></menuitem>
</menu>
<menuitem label="Email This Page" onclick="window.location='mailto:?body='+window.location.href;"></menuitem>
</menu>
</div>
<p><strong>Note:</strong> The contextmenu <strong>attribute</strong> only works in Firefox!</p>
<script>
function myFunction() {
alert("You right-clicked inside the div!");
}
</script>
The oncopy
attribute fires when the user copies the content of an element.
Tip: The oncopy
attribute also fires when the user copies an element, for example, an image, created with the <img>
element.
Tip: The oncopy
attribute is mostly used on <input>
elements with type="text"
.
Tip: There are three ways to copy an element/the content of an element:
The oncopy
attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | oncopy |
Note: The oncopy attribute may not work as expected in some browsers when trying to copy an image (See example above).
Example:
HTML
<input type="text" oncopy="myFunction()" value="Try to copy this text">
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "You copied text!"
}
</script>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p oncopy="myFunction()">Try to copy this text</p>
<script>
function myFunction() {
alert("You copied text!");
}
</script>
</body>
</html>
Example:
HTML
<p>Try to copy the image below (Right click on the image and select "Copy Image").</p>
<img src="https://horje.com/avatar.png" oncopy="myFunction()" alt="The Scream" width="220" height="277">
<p><strong>Note:</strong> This example may not work as expected in some browsers.</p>
<script>
function myFunction() {
alert("You copied image!");
}
</script>
The oncuechange
attribute defines a script to run when the cue changes in a <track>
element.
The oncuechange
attribute is part of the Event Attributes, and can be used on the following element:
Element | Event |
---|---|
<track> | oncuechange |
The oncuechange
attribute has the following browser support.
Example:
HTML
<video width="320" height="240" controls>
<source src="forrest_gump.mp4" type="video/mp4">
<source src="forrest_gump.ogg" type="video/ogg">
<track src="fgsubtitles_en.vtt" kind="subtitles" srclang="en" label="English">
<track src="fgsubtitles_no.vtt" kind="subtitles" srclang="no" label="Norwegian">
</video>
The oncut
attribute fires when the user cuts the content of an element.
Note: Although the oncut
attribute is supported by all HTML elements, it is not actually possible to cut the content of, for example, a <p>
element, UNLESS the element has set the contenteditable
attribute to "true" (See "More Examples" below).
Tip: There are three ways to cut the content of an element:
The oncut
attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | oncut |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<input type="text" oncut="myFunction()" value="Try to cut this text">
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "You cut text!";
}
</script>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p contenteditable="true" oncut="myFunction()">Try to cut this text</p>
<script>
function myFunction() {
alert("You cut text!");
}
</script>
</body>
</html>
The ondblclick
attribute fires on a mouse double-click on the element.
The ondblclick
attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | ondblclick |
Example:
TRY
<!DOCTYPE html>
<html>
<body>
<button ondblclick="myFunction()">Double-click me</button>
<p id="demo"></p>
<p>A function is triggered when the button is double-clicked. The function outputs some text in a p element with id="demo".</p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello World";
}
</script>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p id="demo" ondblclick="myFunction()">Double-click me to change my text color.</p>
<p>A function is triggered when the p element is double-clicked. The function sets the color of the p element to red.</p>
<script>
function myFunction() {
document.getElementById("demo").style.color = "red";
}
</script>
</body>
</html>
The ondrag
attribute fires when an element or text selection is being dragged.
To learn about Drag and Drop, read our HTML Tutorial on HTML5 Drag and Drop.
Tip: Links and images are draggable by default, and do not need the draggable
attribute.
There are many event attributes that are used, and can occur, in the different stages of a drag and drop operation:
ondragstart
- fires when the user starts to drag an elementondrag
- fires when an element is being draggedondragend
- fires when the user has finished dragging the elementondragenter
- fires when the dragged element enters the drop targetondragover
- fires when the dragged element is over the drop targetondragleave
- fires when the dragged element leaves the drop targetondrop
- fires when the dragged element is dropped on the drop targetNote: While dragging an element, the ondrag
event fires every 350 milliseconds.
The ondrag
attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | ondrag |
The numbers in the table specify the first browser version that fully supports the event attribute.
Example:
HTML
<!DOCTYPE HTML>
<html>
<head>
<style>
.droptarget {
float: left;
width: 100px;
height: 35px;
margin: 15px;
padding: 10px;
border: 1px solid #aaaaaa;
}
</style>
</head>
<body>
<p>Drag the p element back and forth between the two rectangles:</p>
<div class="droptarget" ondrop="drop(event)" ondragover="allowDrop(event)">
<p ondragstart="dragStart(event)" ondrag="dragging(event)" draggable="true" id="dragtarget">Drag me!</p>
</div>
<div class="droptarget" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<p style="clear:both;" id="demo"></p>
<script>
function dragStart(event) {
event.dataTransfer.setData("Text", event.target.id);
}
function dragging(event) {
document.getElementById("demo").innerHTML = "The p element is being dragged";
}
function allowDrop(event) {
event.preventDefault();
}
function drop(event) {
event.preventDefault();
let data = event.dataTransfer.getData("Text");
event.target.appendChild(document.getElementById(data));
document.getElementById("demo").innerHTML = "The p element was dropped";
}
</script>
</body>
</html>
The ondragend
attribute fires when the user has finished dragging an element or text selection.
To learn about Drag and Drop, read our HTML Tutorial on HTML5 Drag and Drop.
Tip: Links and images are draggable by default, and do not need the draggable
attribute.
There are many event attributes that are used, and can occur, in the different stages of a drag and drop operation:
ondragstart
- fires when the user starts to drag an elementondrag
- fires when an element is being draggedondragend
- fires when the user has finished dragging the elementondragenter
- fires when the dragged element enters the drop targetondragover
- fires when the dragged element is over the drop targetondragleave
- fires when the dragged element leaves the drop targetondrop
- fires when the dragged element is dropped on the drop targetThe ondragend
attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | ondragend |
The numbers in the table specify the first browser version that fully supports the event attribute.
Example:
TRY
<!DOCTYPE HTML>
<html>
<head>
<style>
.droptarget {
float: left;
width: 100px;
height: 35px;
margin: 15px;
padding: 10px;
border: 1px solid #aaaaaa;
}
</style>
</head>
<body>
<p>Drag the p element back and forth between the two rectangles:</p>
<div class="droptarget" ondrop="drop(event)" ondragover="allowDrop(event)">
<p ondragstart="dragStart(event)" ondragend="dragEnd(event)" draggable="true" id="dragtarget">Drag me!</p>
</div>
<div class="droptarget" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<p style="clear:both;" id="demo"></p>
<script>
function dragStart(event) {
event.dataTransfer.setData("Text", event.target.id);
document.getElementById("demo").innerHTML = "Started to drag the p element";
}
function dragEnd(event) {
document.getElementById("demo").innerHTML = "Finished dragging the p element.";
}
function allowDrop(event) {
event.preventDefault();
}
function drop(event) {
event.preventDefault();
let data = event.dataTransfer.getData("Text");
event.target.appendChild(document.getElementById(data));
}
</script>
</body>
</html>
The ondragenter attribute fires when a draggable element or text selection enters a valid drop target.
The ondragenter and ondragleave events can help the user to understand that a draggable element is about to enter or leave a drop target. This can be done by, for example, setting a background color when the draggable element enters the drop target, and removing the color when the element is moved out of the target.
To learn about Drag and Drop, read our HTML Tutorial on HTML5 Drag a
nd Drop.
Tip: Links and images are draggable by default, and do not need the draggable attribute.
There are many event attributes that are used, and can occur, in the different stages of a drag and drop operation:
The ondragenter attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | ondragenter |
The numbers in the table specify the first browser version that fully supports the event attribute.
Example:
HTML
<!DOCTYPE HTML>
<html>
<head>
<style>
.droptarget {
float: left;
width: 100px;
height: 35px;
margin: 15px;
margin-right: 100px;
padding: 10px;
border: 1px solid #aaaaaa;
}
</style>
</head>
<body>
<p>Drag the p element back and forth between the two rectangles:</p>
<div class="droptarget" ondrop="drop(event)" ondragenter="dragEnter(event)" ondragleave="dragLeave(event)" ondragover="allowDrop(event)">
<p ondragstart="dragStart(event)" draggable="true" id="dragtarget">Drag me!</p>
</div>
<div class="droptarget" ondragenter="dragEnter(event)" ondragleave="dragLeave(event)" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<p style="clear:both;" id="demo"></p>
<script>
function dragStart(event) {
event.dataTransfer.setData("Text", event.target.id);
}
function dragEnter(event) {
if ( event.target.className == "droptarget" ) {
event.target.style.border = "3px dotted red";
document.getElementById("demo").innerHTML = "Entered the dropzone";
}
}
function dragLeave(event) {
if ( event.target.className == "droptarget" ) {
event.target.style.border = "";
document.getElementById("demo").innerHTML = "Left the dropzone";
}
}
function allowDrop(event) {
event.preventDefault();
}
function drop(event) {
event.preventDefault();
let data = event.dataTransfer.getData("Text");
event.target.appendChild(document.getElementById(data));
}
</script>
</body>
</html>
The ondragleave attribute fires when a draggable element or text selection leaves a valid drop target.
The ondragenter and ondragleave events can help the user to understand that a draggable element is about to enter or leave a drop target. This can be done by, for example, setting a background color when the draggable element enters the drop target, and removing the color when the element is moved out of the target.
To learn about Drag and Drop, read our HTML Tutorial on HTML5 Drag and Drop.
Tip: Links and images are draggable by default, and do not need the draggable attribute.
There are many event attributes that are used, and can occur, in the different stages of a drag and drop operation:
The ondragleave attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | ondragleave |
The numbers in the table specify the first browser version that fully supports the event attribute.
Example:
HTML
<!DOCTYPE HTML>
<html>
<head>
<style>
.droptarget {
float: left;
width: 100px;
height: 35px;
margin: 15px;
margin-right: 100px;
padding: 10px;
border: 1px solid #aaaaaa;
}
</style>
</head>
<body>
<p>Drag the p element back and forth between the two rectangles:</p>
<div class="droptarget" ondrop="drop(event)" ondragenter="dragEnter(event)" ondragleave="dragLeave(event)" ondragover="allowDrop(event)">
<p ondragstart="dragStart(event)" draggable="true" id="dragtarget">Drag me!</p>
</div>
<div class="droptarget" ondragenter="dragEnter(event)" ondragleave="dragLeave(event)" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<p style="clear:both;" id="demo"></p>
<script>
function dragStart(event) {
event.dataTransfer.setData("Text", event.target.id);
}
function dragEnter(event) {
if ( event.target.className == "droptarget" ) {
event.target.style.border = "3px dotted red";
document.getElementById("demo").innerHTML = "Entered the dropzone";
}
}
function dragLeave(event) {
if ( event.target.className == "droptarget" ) {
event.target.style.border = "";
document.getElementById("demo").innerHTML = "Left the dropzone";
}
}
function allowDrop(event) {
event.preventDefault();
}
function drop(event) {
event.preventDefault();
let data = event.dataTransfer.getData("Text");
event.target.appendChild(document.getElementById(data));
}
</script>
</body>
</html>
The ondragover attribute fires when a draggable element or text selection is being dragged over a valid drop target.
By default, data/elements cannot be dropped in other elements. To allow a drop, we must prevent the default handling of the element. This is done by calling the event.preventDefault() method for the ondragover attribute.
To learn about Drag and Drop, read our HTML Tutorial on HTML5 Drag and Drop.
Tip: Links and images are draggable by default, and do not need the draggable attribute.
There are many event attributes that are used, and can occur, in the different stages of a drag and drop operation:
Note: While dragging an element, the ondragover event fires every 350 milliseconds.
The ondragover attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | ondragover |
The numbers in the table specify the first browser version that fully supports the event attribute.
Example:
HTML
<!DOCTYPE HTML>
<html>
<head>
<style>
#droptarget {
float: left;
width: 200px;
height: 35px;
margin: 55px;
margin-top: 155px;
padding: 10px;
border: 1px solid #aaaaaa;
}
</style>
</head>
<body>
<p ondragstart="dragStart(event)" draggable="true" id="dragtarget">Drag me into the rectangle!</p>
<div id="droptarget" ondrop="drop(event)" ondragover="allowDrop(event)">
</div>
<p style="clear:both;" id="demo"></p>
<script>
function dragStart(event) {
event.dataTransfer.setData("Text", event.target.id);
}
function allowDrop(event) {
event.preventDefault();
document.getElementById("demo").innerHTML = "The p element is OVER the droptarget.";
event.target.style.border = "4px dotted green";
}
function drop(event) {
event.preventDefault();
let data = event.dataTransfer.getData("Text");
event.target.appendChild(document.getElementById(data));
document.getElementById("demo").innerHTML = "The p element was dropped.";
}
</script>
</body>
</html>
The ondragstart attribute fires when the user starts to drag an element or text selection.
To learn about Drag and Drop, read our HTML Tutorial on HTML5 Drag and Drop.
Tip: Links and images are draggable by default, and do not need the draggable attribute.
There are many event attributes that are used, and can occur, in the different stages of a drag and drop operation:
The ondragstart attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | ondragstart |
The numbers in the table specify the first browser version that fully supports the event attribute.
Example:
HTML
<!DOCTYPE HTML>
<html>
<head>
<style>
.droptarget {
float: left;
width: 100px;
height: 35px;
margin: 15px;
padding: 10px;
border: 1px solid #aaaaaa;
}
</style>
</head>
<body>
<p>Drag the p element back and forth between the two rectangles:</p>
<div class="droptarget" ondrop="drop(event)" ondragover="allowDrop(event)">
<p ondragstart="dragStart(event)" ondragend="dragEnd(event)" draggable="true" id="dragtarget">Drag me!</p>
</div>
<div class="droptarget" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<p style="clear:both;" id="demo"></p>
<script>
function dragStart(event) {
event.dataTransfer.setData("Text", event.target.id);
document.getElementById("demo").innerHTML = "Started to drag the p element";
}
function dragEnd(event) {
document.getElementById("demo").innerHTML = "Finished dragging the p element.";
}
function allowDrop(event) {
event.preventDefault();
}
function drop(event) {
event.preventDefault();
let data = event.dataTransfer.getData("Text");
event.target.appendChild(document.getElementById(data));
}
</script>
</body>
</html>
The ondrop attribute fires when a draggable element or text selection is dropped on a valid drop target.
To learn about Drag and Drop, read our HTML Tutorial on HTML5 Drag and Drop.
Tip: Links and images are draggable by default, and do not need the draggable attribute.
There are many event attributes that are used, and can occur, in the different stages of a drag and drop operation:
The ondrop attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | ondrop |
The numbers in the table specify the first browser version that fully supports the event attribute.
Example:
HTML
<!DOCTYPE HTML>
<html>
<head>
<style>
.droptarget {
float: left;
width: 100px;
height: 35px;
margin: 15px;
padding: 10px;
border: 1px solid #aaaaaa;
}
</style>
</head>
<body>
<p>Drag the p element back and forth between the two rectangles:</p>
<div class="droptarget" ondrop="drop(event)" ondragover="allowDrop(event)">
<p ondragstart="dragStart(event)" draggable="true" id="dragtarget">Drag me!</p>
</div>
<div class="droptarget" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<p style="clear:both;" id="demo"></p>
<script>
function dragStart(event) {
event.dataTransfer.setData("Text", event.target.id);
document.getElementById("demo").innerHTML = "Started to drag the p element";
}
function allowDrop(event) {
event.preventDefault();
}
function drop(event) {
event.preventDefault();
let data = event.dataTransfer.getData("Text");
event.target.appendChild(document.getElementById(data));
document.getElementById("demo").innerHTML = "The p element was dropped";
}
</script>
</body>
</html>
The durationchange event occurs when the duration data of the specified audio/video is changed.
Note: When an audio/video is loaded, the duration will change from "NaN" to the actual duration of the audio/video.
During the loading process of an audio/video, the following events occur, in this order:
The ondurationchange attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | durationchange |
<video> | durationchange |
The ondurationchange
attribute has the following browser support for each element:
Example:
HTML
<audio id="myAudio" controls ondurationchange="myFunction(this)">
<source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="audio/ogg">
<source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<script>
function myFunction(x) {
alert("The duration of this audioclip is : " + x.duration + " seconds");
}
</script>
Example:
HTML
<video id="myVideo" width="320" height="176" controls ondurationchange="myFunction(this)">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_5mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_5mb.mp4" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<script>
function myFunction(x) {
alert("The duration of this video is : " + x.duration + " seconds");
}
</script>
Fires when the current playlist is empty
The onemptied attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | onemptied |
<video> | onemptied |
The onended event occurs when the audio/video has reached the end.
This event is useful for messages like "thanks for listening", "thanks for watching", etc.
The onended attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | ended |
<video> | ended |
The onended
attribute has the following browser support for each element:
Example:
HTML
<audio id="myAudio" controls onended="myFunction()">
<source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="audio/ogg">
<source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<p>Play the audio file:</p>
<script>
function myFunction() {
alert("Thank you for listening");
}
</script>
Example:
HTML
<video id="myVideo" width="320" height="176" controls onended="myFunction()">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_10mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_10mb.mp4" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<p>Play the video:</p>
<script>
function myFunction() {
alert("Thank you for watching");
}
</script>
The error event occurs when an error occurred during the loading of a media file.
The onerror attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | onerror |
<body> | onerror |
<embed> | onerror |
<img> | onerror |
<link> | onerror |
<object> | onerror |
<script> | onerror |
<video> | onerror |
The onerror
attribute has the following browser support for each element:
Example:
HTML
<audio onerror="myFunction()">
Example:
HTML
<video onerror="myFunction()">
The onfocus attribute fires the moment that the element gets focus.
Onfocus is most often used with <input>, <select>, and <a>.
Tip: The onfocus attribute is the opposite of the onblur attribute.
The onfocus attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | onfocus |
Example:
HTML
First name: <input type="text" id="fname" onfocus="myFunction(this.id)"><br>
Last name: <input type="text" id="lname" onfocus="myFunction(this.id)">
<script>
function myFunction(x) {
document.getElementById(x).style.background = "yellow";
}
</script>
The onhashchange attribute fires when there has been changes to the anchor part (begins with a '#' symbol) of the current URL.
An example of what an anchor part actually is: Assume that the current URL is
http://www.example.com/test.htm#part2 - The anchor part of this URL would be #part2.
To invoke this event, you can:
The onhashchange attribute is part of the Event Attributes, and can be used on the following element:
Elements | Event |
---|---|
<body> | onhashchange |
The numbers in the table specify the first browser version that fully supports the event attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body onhashchange="myFunction()">
<p>Click the button to change the anchor part of the current URL to #part5</p>
<button onclick="changePart()">Try it</button>
<p id="demo"></p>
<script>
// Using the location.hash property to change the anchor part
function changePart() {
location.hash = "part5";
let x = "The anchor part is now: " + location.hash;
document.getElementById("demo").innerHTML = x;
}
// Alert some text if there has been changes to the anchor part
function myFunction() {
alert("The anchor part has changed!");
}
</script>
</body>
</html>
The oninput attribute fires when an element gets user input.
The oninput attribute fires when the value of an <input> or <textarea> element is changed.
Tip: This event is similar to the onchange event. The difference is that the oninput event occurs immediately after the value of an element has changed, while onchange occurs when the element loses focus. The other difference is that the onchange event also works on <select> elements.
The oninput attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | oninput |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p>Write something in the text field to trigger a function.</p>
<input type="text" id="myInput" oninput="myFunction()">
<p id="demo"></p>
<script>
function myFunction() {
let x = document.getElementById("myInput").value;
document.getElementById("demo").innerHTML = "You wrote: " + x;
}
</script>
</body>
</html>
The oninvalid event occurs when a submittable <input> element is invalid.
For example, the input field is invalid if the required attribute is set and the field is empty (the required attribute specifies that the input field must be filled out before submitting the form).
The oninvalid attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | oninvalid |
The numbers in the table specify the first browser version that fully supports the event attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php" method="get">
Name: <input type="text" oninvalid="alert('You must fill out the form!');" name="fname" required>
<input type="submit" value="Submit">
</form>
<p>If you click submit, without filling out the text field, an alert message will occur.</p>
<p><strong>Note:</strong> The oninvalid event is not supported in Safari.</p>
</body>
</html>
The onkeydown attribute fires when the user is pressing a key (on the keyboard).
Tip: The order of events related to the onkeydown event:
The onkeydown attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | onkeydown |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p>A function is triggered when the user is pressing a key in the input field.</p>
<input type="text" onkeydown="myFunction()">
<script>
function myFunction() {
alert("You pressed a key inside the input field");
}
</script>
</body>
</html>
The onkeypress attribute fires when the user presses a key (on the keyboard).
Tip: The order of events related to the onkeypress event:
Note: The onkeypress event is not fired for all keys (e.g. ALT, CTRL, SHIFT, ESC) in all browsers. To detect only whether the user has pressed a key, use onkeydown instead, because it works for all keys.
The onkeypress attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | onkeypress |
A function is triggered when the user is pressing a key in the input field.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p>A function is triggered when the user is pressing a key in the input field.</p>
<input type="text" onkeypress="myFunction()">
<script>
function myFunction() {
alert("You pressed a key inside the input field");
}
</script>
</body>
</html>
The onkeyup attribute fires when the user releases a key (on the keyboard).
Tip: The order of events related to the onkeyup event:
The onkeyup attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | onkeyup |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p>A function is triggered when the user releases a key in the input field. The function transforms the character to upper case.</p>
Enter your name: <input type="text" id="fname" onkeyup="myFunction()">
<script>
function myFunction() {
let x = document.getElementById("fname");
x.value = x.value.toUpperCase();
}
</script>
</body>
</html>
The onload attribute fires when an object has been loaded.
onload is most often used within the <body> element to execute a script once a web page has completely loaded all content (including images, script files, CSS files, etc.). However, it can be used on other elements as well (see "Supported HTML tags" below).
For input elements, the onload attribute is only supported when <input type="image">
The onload attribute can be used to check the visitor's browser type and browser version, and load the proper version of the web page based on the information.
The onload attribute is part of the Event Attributes, and can be used on the following elements:
Elements |
---|
<body> |
<iframe> |
<img> |
<input> |
<link> |
<script> |
<style> |
The onload
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
alert("Page is loaded");
}
</script>
</head>
<body onload="myFunction()">
<h1>Hello World!</h1>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<img src="https://horje.com/avatar.png" onload="loadImage()" width="100" height="132">
<script>
function loadImage() {
alert("Image is loaded");
}
</script>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<input type="image" onload="loadImage()" src="https://horje.com/uploads/category/2024-08-31-06-56-41-php_script.png" alt="Submit" width="48" height="48">
<script>
function loadImage() {
alert("Image is loaded");
}
</script>
</body>
</html>
The loadeddata event occurs when data for the current frame is loaded, but not enough data to play next frame of the specified audio/video.
During the loading process of an audio/video, the following events occur, in this order:
The onloadeddata attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
loadeddata | |
loadeddata |
The onloadeddata
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<audio id="myAudio" controls onloadeddata="myFunction()">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/ogg">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<p>Play the audio file:</p>
<script>
function myFunction() {
alert("Data is loaded");
}
</script>
<p>This example demonstrates how to use the "onloadeddata" attribute on an AUDIO element.</p>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<video id="myVideo" width="320" height="176" controls onloadeddata="myFunction()">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_2mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_2mb.mp4" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<p>Play the video:</p>
<script>
function myFunction() {
alert("Data is loaded");
}
</script>
<p>This example demonstrates how to use the "onloadeddata" attribute on a VIDEO element.</p>
<p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>
</body>
</html>
The loadedmetadata event occurs when meta data for the specified audio/video has been loaded.
Meta data for audio/video consists of: duration, dimensions (video only) and text tracks.
During the loading process of an audio/video, the following events occur, in this order:
The onloadedmetadata attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | loadedmetadata |
<video> | loadedmetadata |
The onloadedmetadata
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<audio id="myAudio" controls onloadedmetadata="myFunction()">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/ogg">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<p>Play the audio file:</p>
<script>
function myFunction() {
alert("Meta data is loaded");
}
</script>
<p>This example demonstrates how to use the "onloadedmetadata" attribute on an AUDIO element.</p>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<video id="myVideo" width="320" height="176" controls onloadedmetadata="myFunction()">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_2mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_2mb.mp4" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<p>Play the video:</p>
<script>
function myFunction() {
alert("Meta data is loaded");
}
</script>
<p>This example demonstrates how to use the "onloadedmetadata" attribute on a VIDEO element.</p>
<p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>
</body>
</html>
The onloadstart event occurs when the browser starts looking for the specified audio/video. This is when the loading process starts.
During the loading process of an audio/video, the following events occur, in this order:
The onloadstart attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | loadstart |
<video> | loadstart |
The onloadstart
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<audio id="myAudio" controls onloadstart="myFunction()">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_5MG.mp3" type="audio/ogg">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_5MG.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<p>Play the audio file:</p>
<script>
function myFunction() {
alert("The media file has started loading");
}
</script>
<p>This example demonstrates how to use the "onloadstart" attribute on an AUDIO element.</p>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<video id="myVideo" width="320" height="176" controls onloadstart="myFunction()">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_2mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_2mb.mp4" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<p>Play the video:</p>
<script>
function myFunction() {
alert("The media file has started loading");
}
</script>
<p>This example demonstrates how to use the "onloadstart" attribute on a VIDEO element.</p>
<p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>
</body>
</html>
The onmousedown attribute fires when a mouse button is pressed down on the element.
Tip: The order of events related to the onmousedown event (for the left/middle mouse button):
The order of events related to the onmousedown event (for the right mouse button):
The onmousedown attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | onmousedown |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p id="p1" onmousedown="mouseDown()" onmouseup="mouseUp()">
Click the text! The mouseDown() function is triggered when the mouse button is pressed down over this paragraph. The function sets the color of the text to red. The mouseUp() function is triggered when the mouse button is released. The mouseUp() function sets the color of the text to green.
</p>
<script>
function mouseDown() {
document.getElementById("p1").style.color = "red";
}
function mouseUp() {
document.getElementById("p1").style.color = "green";
}
</script>
</body>
</html>
The onmousemove attribute fires when the pointer is moving while it is over an element.
The onmousemove attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | onmousemove |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<img onmousemove="bigImg(this)" onmouseout="normalImg(this)" border="0" src="smiley.gif" alt="Smiley" width="32" height="32">
<p>The function bigImg() is triggered when the user mouse pointer is moved over the image. This function enlarges the image.</p>
<p>The function normalImg() is triggered when the mouse pointer is moved out of the image. That function sets the height and width of the image back to normal.</p>
<script>
function bigImg(x) {
x.style.height = "64px";
x.style.width = "64px";
}
function normalImg(x) {
x.style.height = "32px";
x.style.width = "32px";
}
</script>
</body>
</html>
The onmouseout attribute fires when the mouse pointer moves out of an element.
Tip: The onmouseout attribute is often used together with the onmouseover attribute.
The onmouseout attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | onmouseout |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<img onmouseover="bigImg(this)" onmouseout="normalImg(this)" border="0" src="smiley.gif" alt="Smiley" width="32" height="32">
<p>The function bigImg() is triggered when the user mouse over the image. This function enlarges the image.</p>
<p>The function normalImg() is triggered when the mouse pointer is moved out of the image. That function sets the height and width of the image back to normal.</p>
<script>
function bigImg(x) {
x.style.height = "64px";
x.style.width = "64px";
}
function normalImg(x) {
x.style.height = "32px";
x.style.width = "32px";
}
</script>
</body>
</html>
The onmouseover attribute fires when the mouse pointer moves over an element.
Tip: The onmouseover attribute is often used together with the onmouseout attribute.
The onmouseover attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | onmouseover |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<img onmouseover="bigImg(this)" onmouseout="normalImg(this)" border="0" src="https://horje.com/avatar.png" alt="Smiley" width="32" height="32">
<p>The function bigImg() is triggered when the user mouse over the image. This function enlarges the image.</p>
<p>The function normalImg() is triggered when the mouse pointer is moved out of the image. That function sets the height and width of the image back to normal.</p>
<script>
function bigImg(x) {
x.style.height = "64px";
x.style.width = "64px";
}
function normalImg(x) {
x.style.height = "32px";
x.style.width = "32px";
}
</script>
</body>
</html>
The onmouseup attribute fires when a mouse button is released over the element.
Tip: The order of events related to the onmouseup event (for the left/middle mouse button):
The order of events related to the onmouseup event (for the right mouse button):
The onmouseup attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | onmouseup |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p id="p1" onmousedown="mouseDown()" onmouseup="mouseUp()">
Click the text! The mouseDown() function is triggered when the mouse button is pressed down over this paragraph. The function sets the color of the text to red. The mouseUp() function is triggered when the mouse button is released. The mouseUp() function sets the color of the text to green.
</p>
<script>
function mouseDown() {
document.getElementById("p1").style.color = "red";
}
function mouseUp() {
document.getElementById("p1").style.color = "green";
}
</script>
</body>
</html>
The onmousewheel attribute fires when the mouse wheel is rolled up or down over an element.
Deprecated. The onmousewheel attribute is deprecated, you should use the onwheel attribute instead.
The onmousewheel attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | onmousewheel |
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {
border: 1px solid black;
}
</style>
</head>
<body>
<div id="myDIV" onmousewheel="myFunction()">This example demonstrates how to assign an "onmousewheel" event to a DIV element. Roll the mouse wheel over me - either up or down!</div>
<p>A function is triggered when you roll the mouse wheel over div. The function sets the font-size of div to 35 pixels.</p>
<script>
function myFunction() {
document.getElementById("myDIV").style.fontSize = "35px";
}
</script>
</body>
</html>
The onoffline attribute fires when the browser starts to work offline.
Tip: The onoffline attribute is the opposite of the ononline attribute.
The onoffline attribute is part of the Event Attributes, and can be used on the following element:
Elements | Event |
---|---|
<body> | onoffline |
Example:
HTML
<!DOCTYPE html>
<html>
<body ononline="onFunction()" onoffline="offFunction()">
<p>Try to disconnect from the internet to toggle between working online and offline.</p>
<script>
function onFunction() {
alert ("Your browser is working online.");
}
function offFunction() {
alert ("Your browser is working offline.");
}
</script>
</body>
</html>
The ononline attribute fires when the browser starts to work online.
Tip: The ononline attribute is the opposite of the onoffline attribute.
The ononline attribute is part of the Event Attributes, and can be used on the following element:
Elements | Event |
---|---|
<body> | ononline |
The numbers in the table specify the first browser version that fully supports the event attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body ononline="onFunction()" onoffline="offFunction()">
<p>Try to disconnect from the internet to toggle between working online and offline.</p>
<script>
function onFunction() {
alert ("Your browser is working online.");
}
function offFunction() {
alert ("Your browser is working offline.");
}
</script>
</body>
</html>
The onpageshow event occurs when a user navigates to a webpage.
The onpageshow event is similar to the onload event, except that it occurs after the onload event when the page first loads. Also, the onpageshow event occurs every time the page is loaded, whereas the onload event does not occur when the page is loaded from the cache.
The onpageshow attribute is part of the Event Attributes, and can be used on the following element:
Elements | Event |
---|---|
<body> | onpageshow |
The numbers in the table specify the first browser version that fully supports the event attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body onpageshow="myFunction()">
<h1>Hello World!</h1>
<script>
function myFunction() {
alert("Welcome!");
}
</script>
</body>
</html>
The onpaste
attribute fires when the user pastes some content in an element.
Note: Although the onpaste
attribute is supported by all HTML elements, it is not actually possible to paste some content in, for example, a <p> element, UNLESS the element has set contenteditable to "true" (See "More Examples" below).
Tip: The onpaste
attribute is mostly used on <input> elements with type="text".
Tip: There are three ways to paste some content in an element:
The onpaste
attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | onpaste |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<input type="text" onpaste="myFunction()" value="Try to paste something in here" size="40">
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "You pasted text!";
}
</script>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p contenteditable="true" onpaste="myFunction()">Try to paste something inside this paragraph.</p>
<script>
function myFunction() {
alert("You pasted text!");
}
</script>
</body>
</html>
The onpause
attribute defines a script to be run when the audio/video is paused either by the user or programmatically.
Tip: The onplay attribute is used to define a script to run when the audio/video has been started or is no longer paused.
The onpause
attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | pause |
<video> | pause |
The onpause
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p>Play and pause the audio file.</p>
<audio id="myAudio" controls onpause="myFunction()">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/ogg">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<script>
function myFunction() {
alert("The audio file has been paused");
}
</script>
<p>This example demonstrates how to use the "onpause" attribute on an AUDIO element.</p>
</body>
</html>
Video Example. This example demonstrates how to use the "onpause" attribute on a VIDEO element.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p>Play and pause the video.</p>
<video id="myVideo" width="320" height="176" controls onpause="myFunction()">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_2mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_2mb.mp4" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<script>
function myFunction() {
alert("The video has been paused");
}
</script>
<p>This example demonstrates how to use the "onpause" attribute on a VIDEO element.</p>
<p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>
</body>
</html>
The onplay
attribute defines a script to be run when the audio/video has been started or is no longer paused.
Tip: The onpause attribute is used to define a script when the audio/video has been paused.
The onplay
attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | play |
<video> | play |
The onplay
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p>Play the audio file.</p>
<audio id="myAudio" controls onplay="myFunction()">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_1MG.mp3" type="audio/ogg">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_1MG.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<script>
function myFunction() {
alert("The audio file is playing");
}
</script>
<p>This example demonstrates how to use the "onplay" attribute on an AUDIO element.</p>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p>Play the video.</p>
<video id="myVideo" width="320" height="176" controls onplay="myFunction()">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_20mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_20mb.mp4" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<script>
function myFunction() {
alert("The video is playing");
}
</script>
<p>This example demonstrates how to use the "onplay" attribute on a VIDEO element.</p>
<p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>
</body>
</html>
The onplay
attribute defines a script to be run when the audio/video has been started or is no longer paused.
Tip: The onpause attribute is used to define a script when the audio/video has been paused.
The onplay
attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | play |
<video> | play |
The onplay
attribute has the following browser support for each element:
Audio Example. This example demonstrates how to use the "onplaying" attribute on an AUDIO element.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p>Play the audio file.</p>
<audio id="myAudio" controls onplaying="myFunction()">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/ogg">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<script>
function myFunction() {
alert("The audio file has started playing");
}
</script>
<p>This example demonstrates how to use the "onplaying" attribute on an AUDIO element.</p>
</body>
</html>
Video Example. This example demonstrates how to use the "onplaying" attribute on a VIDEO element.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p>Play the video.</p>
<video id="myVideo" width="320" height="176" controls onplaying="myFunction()">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_2mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_2mb.mp4" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<script>
function myFunction() {
alert("The video has started playing");
}
</script>
<p>This example demonstrates how to use the "onplaying" attribute on a VIDEO element.</p>
<p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>
</body>
</html>
The onprogress
attribute defines a script to be run when the browser is downloading the specified audio/video.
During the loading process of an audio/video, the following events occur, in this order:
The onprogress
attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | progress |
<video> | progress |
The onprogress
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<audio id="myAudio" controls onprogress="myFunction()">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/ogg">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<script>
function myFunction() {
alert("The audio file has started downloading");
}
</script>
<p>This example demonstrates how to use the "onprogress" attribute on an AUDIO element.</p>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<video id="myVideo" width="320" height="176" controls onprogress="myFunction()">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_20mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_20mb.mp4" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<script>
function myFunction() {
alert("The video has started downloading");
}
</script>
<p>This example demonstrates how to use the "onprogress" attribute on a VIDEO element.</p>
<p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>
</body>
</html>
The onratechange
attribute defines a script to be run when the playing speed of the audio/video is changed (like when a user switches to a slow motion or fast forward mode).
The onratechange
attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | ratechange |
<video> | ratechange |
The onratechange
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<audio id="myAudio" controls onratechange="myFunction()">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/ogg">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<p id="demo">Change the speed of the audio</p>
<input type="range" min="0.5" max="3" step="0.1" value="1"oninput="changeRate(this)">
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "The audio's speed is " + document.getElementById("myAudio").playbackRate;
}
function changeRate(obj) {
document.getElementById("myAudio").playbackRate = obj.value;
}
</script>
<p>This example demonstrates how to use the "onratechange" attribute on an AUDIO element.</p>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<video id="myVideo" width="320" height="176" controls onratechange="myFunction()">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_30mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_30mb.mp4" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<p id="demo">Change the speed of the video</p>
<input type="range" min="0.1" max="3" step="0.1" value="1"oninput="changeRate(this)">
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "The video's speed is " + document.getElementById("myVideo").playbackRate;
}
function changeRate(obj) {
document.getElementById("myVideo").playbackRate = obj.value;
}
</script>
<p>This example demonstrates how to use the "onratechange" attribute on a VIDEO element.</p>
<p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>
</body>
</html>
The onreset
attribute fires when a form is reset.
The onreset
attribute is part of the Event Attributes, and can be used on the following element:
Elements | Event |
---|---|
<form> | onreset |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p>When you reset the form, a function is triggered which alerts some text.</p>
<form onreset="myFunction()">
Enter name: <input type="text">
<input type="reset">
</form>
<script>
function myFunction() {
alert("The form was reset");
}
</script>
</body>
</html>
The onresize
attribute fires when the browser window is resized.
The onresize
attribute is part of the Event Attributes, and can be used on the following element:
Elements | Event |
---|---|
<body> | onresize |
Example:
HTML
<!DOCTYPE html>
<html>
<body onresize="myFunction()">
<p>Try to resize the browser window.</p>
<script>
function myFunction() {
alert("You have changed the size of the browser window!");
}
</script>
</body>
</html>
The onscroll
attribute fires when an element's scrollbar is being scrolled.
Tip: use the CSS overflow style property to create a scrollbar for an element.
The onscroll
attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | onscroll |
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {
border: 1px solid black;
width: 200px;
height: 100px;
overflow: scroll;
}
</style>
</head>
<body>
<p>Try the scrollbar in div.</p>
<div id="myDIV" onscroll="myFunction()">In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since.
<br><br>
'Whenever you feel like criticizing anyone,' he told me, just remember that all the people in this world haven't had the advantages that you've had.'</div>
<script>
function myFunction() {
document.getElementById("myDIV").style.color = "red";
}
</script>
<p>A function is triggered when you scroll in div. The function sets the color of the text in div to red.</p>
</body>
</html>
The onsearch
attribute fires when a user presses the "ENTER" key or clicks the "x" button in an <input> element with type="search".
The onsearch
attribute is part of the Event Attributes, and can be used on the following element:
Elements | Event |
---|---|
<input type="search"> | onsearch |
The numbers in the table specify the first browser version that fully supports the event attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p>Write something in the search field and press "ENTER".</p>
<input type="search" id="myInput" onsearch="myFunction()">
<p><strong>Note:</strong> The onsearch event is not supported in Internet Explorer, Firefox or Opera 12 and earlier versions.</p>
<p id="demo"></p>
<script>
function myFunction() {
let x = document.getElementById("myInput");
document.getElementById("demo").innerHTML = "You are searching for: " + x.value;
}
</script>
</body>
</html>
The onseeked
attribute defines a script to run when the user is finished moving/skipping to a new position in the audio/video.
Tip: Use the currentTime property of the Audio/Video Object to get the current playback position.
The onseeked
attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | seeked |
<video> | seeked |
The onseeked
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p id="demo">Move to a new position in the audio:</p>
<audio id="myAudio" controls onseeked="myFunction()">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_5MG.mp3" type="audio/ogg">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_5MG.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "You moved to position " + document.getElementById("myAudio").currentTime;
}
</script>
<p>This example demonstrates how to use the "onseeked" attribute on an AUDIO element.</p>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p id="demo">Move to a new position in the video:</p>
<video id="myVideo" width="320" height="176" controls onseeked="myFunction()">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_30mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_30mb.mp4" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "You moved to position " + document.getElementById("myVideo").currentTime;
}
</script>
<p>This example demonstrates how to use the "onseeked" attribute on a VIDEO element.</p>
<p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>
</body>
</html>
The onseeking
attribute defines a script to run when the user starts moving/skipping to a new position in the audio/video.
Tip: Use the currentTime property of the Audio/Video Object to get the current playback position.
The onseeking
attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | seeking |
<video> | seeking |
The onseeking
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p id="demo">Move to a new position in the audio:</p>
<audio id="myAudio" controls onseeking="myFunction()">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_1MG.mp3" type="audio/ogg">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_1MG.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "You moved to position " + document.getElementById("myAudio").currentTime;
}
</script>
<p>This example demonstrates how to use the "onseeking" attribute on an AUDIO element.</p>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p id="demo">Move to a new position in the video:</p>
<video id="myVideo" width="320" height="176" controls onseeking="myFunction()">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_20mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_20mb.mp4" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "You moved to position " + document.getElementById("myVideo").currentTime;
}
</script>
<p>This example demonstrates how to use the "onseeking" attribute on a VIDEO element.</p>
<p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>
</body>
</html>
The onstalled
attribute defines a script to run when the browser is trying to get media data, but data is not available.
Tip: Related events that occurs when there is some kind of disturbance to the media loading process, are:
The onstalled
attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | stalled |
<video> | stalled |
The onstalled
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<title>
HTML onstalled Attribute
</title>
</head>
<body>
<center>
<h1 style="color:green">Horje</h1>
<h2>HTML onstalled Attribute</h2>
<video controls id="videoID">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_20mb.mp4"
type="video/mp4">
</video>
</center>
<script>
document.getElementById(
"videoID").addEventListener("stalled", GFGfun);
function GFGfun() {
alert(
"Data of this media not available");
}
</script>
</body>
</html>
The onsubmit
attribute fires when a form is submitted.
The onsubmit
attribute is part of the Event Attributes, and can be used on the following element:
Elements | Event |
---|---|
<form> | onsubmit |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p>When you submit the form, a function is triggered which alerts some text.</p>
<form action="/action_page.php" onsubmit="myFunction()">
Enter name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>
<script>
function myFunction() {
alert("The form was submitted");
}
</script>
</body>
</html>
The onsuspend
attribute defines a script to run when the browser is intentionally not getting media data.
This event occurs when the loading of the media is suspended (prevented from continuing). This can happen when the download has completed, or because it has been paused for some reason.
Tip: Related events that occurs when there is some kind of disturbance to the media loading process, are:
The onsuspend
attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | suspend |
<video> | suspend |
The onsuspend
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<title>
HTML onsuspend Attribute
</title>
</head>
<body>
<center>
<h1 style="color:green">Horje</h1>
<h2>HTML onsuspend Attribute</h2>
<audio controls id-"audioID">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/mpeg">
</audio>
</center>
<script>
document.getElementById(
"audioID").addEventListener("suspend", GFGfun);
function GFGfun() {
alert(
"Media loading suspended");
}
</script>
</body>
</html>
The ontimeupdate
attribute defines a script to run when the playing position of an audio/video has changed.
This event is invoked by:
Tip: This timeupdate event is often used together with the currentTime property of the Audio/Video Object, which returns the current position of the audio/video playback, in seconds.
The ontimeupdate
attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | timeupdate |
<video> | timeupdate |
The ontimeupdate
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p id="demo">Move to a new position in the audio:</p>
<audio id="myAudio" controls ontimeupdate="myFunction()">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/ogg">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "You moved to position " + document.getElementById("myAudio").currentTime;
}
</script>
<p>This example demonstrates how to use the "ontimeupdate" attribute on an AUDIO element.</p>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p id="demo">Move to a new position in the video:</p>
<video id="myVideo" width="320" height="176" controls ontimeupdate="myFunction()">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_2mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_2mb.mp4" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "You moved to position " + document.getElementById("myVideo").currentTime;
}
</script>
<p>This example demonstrates how to use the "ontimeupdate" attribute on a VIDEO element.</p>
<p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>
</body>
</html>
The ontoggle
attribute fires when the user opens or closes a <details>
element.
The <details>
element specifies additional details that the user can view or hide on demand.
The ontoggle
attribute is part of the Event Attributes, and can be used on the following element:
Elements | Event |
---|---|
<details> | ontoggle |
The numbers in the table specify the first browser version that fully supports the event attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p>Open the details.</p>
<details ontoggle="myFunction()">
<summary>Copyright 1999-2014.</summary>
<p> - by Refsnes Data. All Rights Reserved.</p>
<p>All content and graphics on this web site are the property of the company Refsnes Data.</p>
</details>
<script>
function myFunction() {
alert("The ontoggle event occured");
}
</script>
</body>
</html>
The onunload
attribute fires once a page has unloaded (or the browser window has been closed).
onunload occurs when the user navigates away from the page (by clicking on a link, submitting a form, closing the browser window, etc.)
Note: If you reload a page, you will also trigger the onunload event (and the onload event).
The onunload
attribute is part of the Event Attributes, and can be used on the following element:
Elements | Event |
---|---|
<body> | onunload |
Example:
HTML
<!DOCTYPE html>
<html>
<body onunload="myFunction()">
<h1>Welcome to my Home Page</h1>
<p>Close this window or press F5 to reload the page.</p>
<p><strong>Note:</strong> Due to different browser settings, this event may not always work as expected.</p>
<script>
function myFunction() {
alert("Thank you for visiting W3Schools!");
}
</script>
</body>
</html>
The onvolumechange
attribute defines a script to run each time the volume of a video/audio has been changed.
This event is invoked by:
Tip: Use the volume property of the Audio/Video Object to set or return the audio volume of an audio/video.
The onvolumechange
attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | volumechange |
<video> | volumechange |
The onvolumechange
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p id="demo">Change the volume of the audio:</p>
<audio id="myAudio" controls onvolumechange="myFunction()">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_2MG.mp3" type="audio/ogg">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_2MG.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "You changed the volume";
}
</script>
<p>This example demonstrates how to use the "onvolumenchange" attribute on an AUDIO element.</p>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p id="demo">Change the volume of the video:</p>
<video id="myVideo" width="320" height="176" controls onvolumechange="myFunction()">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_30mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_30mb.mp4" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "You changed the volume";
}
</script>
<p>This example demonstrates how to use the "onvolumechange" attribute on a VIDEO element.</p>
<p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>
</body>
</html>
The onwaiting
attribute defines a script to run when the video stops because it needs to buffer the next frame.
This event can also be used on <audio>
elements, but it is mostly used for videos.
The onwaiting
attribute is part of the Event Attributes, and can be used on the following elements:
Elements | Event |
---|---|
<audio> | waiting |
<video> | waiting |
The onwaiting
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<title>HTML DOM onwaiting Attribute</title>
</head>
<body>
<center>
<h1 style="color:green">Horje</h1>
<h2>HTML onwaiting Attribute</h2>
<video controls id="videoID">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_30mb.mp4" type="video/mp4">
</video>
</center>
<script>
document.getElementById(
"videoID").addEventListener("waiting", GFGfun);
function GFGfun() {
alert(" start Buffering");
}
</script>
</body>
</html>
The onwheel
attribute fires when the wheel of a pointing device is rolled up or down over an element.
The onwheel
attribute also fires when the user scrolls or zooms on an element by using a touchpad (like the "mouse" of a laptop).
The onwheel
attribute is part of the Event Attributes, and can be used on any HTML elements.
Elements | Event |
---|---|
All HTML elements | onwheel |
The numbers in the table specify the first browser version that fully supports the event attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {
border: 1px solid black;
}
</style>
</head>
<body>
<div id="myDIV" onwheel="myFunction()">This example demonstrates how to assign an "onwheel" event event to a DIV element. Roll the mouse wheel over me - either up or down!</div>
<p>A function is triggered when you roll the mouse wheel over div. The function sets the font-size of div to 35 pixels.</p>
<p><strong>Note:</strong> The onwheel event is not supported in Internet Explorer or Safari.</p>
<script>
function myFunction() {
document.getElementById("myDIV").style.fontSize = "35px";
}
</script>
</body>
</html>
The open
attribute is a boolean attribute.
When present, it specifies that the details should be visible (open) by default.
The open
attribute can be used on the following element:
Element | Attribute |
---|---|
<details> | open |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The details open attribute</h1>
<details open>
<summary>Epcot Center</summary>
<p>Epcot is a theme park at Walt Disney World Resort featuring exciting attractions, international pavilions, award-winning fireworks and seasonal special events.</p>
</details>
<p>This example demonstrates a details element that is open by default.</p>
</body>
</html>
The optimum
attribute specifies the range where the gauge's value is considered to be an optimal value.
The optimum
attribute can be used on the following element:
Element | Attribute |
---|---|
optimum |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<meter id="yinyang" value="0.3" high="0.9" low="0.1" optimum="0.5"></meter>
The pattern
attribute specifies a regular expression that the <input>
element's value is checked against.
Note: The pattern
attribute works with the following input types: text, date, search, url, tel, email, and password.
Tip: Use the global title
attribute to describe the pattern to help the user.
Tip: Learn more about regular expressions in our JavaScript tutorial.
The pattern
attribute can be used on the following element:
Element | Attribute |
---|---|
<input> | pattern |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The input pattern attribute</h1>
<form action="/action_page.php">
<label for="country_code">Country code:</label>
<input type="text" id="country_code" name="country_code" pattern="[A-Za-z]{3}" title="Three letter country code"><br><br>
<input type="submit">
</form>
<p><strong>Note:</strong> The pattern attribute of the input tag is not supported in Safari 10 (or earlier).</p>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The input pattern attribute</h1>
<p>A form with a password field that must contain 8 or more characters:</p>
<form action="/action_page.php">
<label for="pwd">Password:</label>
<input type="password" id="pwd" name="pwd" pattern=".{8,}" title="Eight or more characters">
<input type="submit">
</form>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The input pattern attribute</h1>
<p>A form with a password field that must contain 8 or more characters that are of at least one number, and one uppercase and lowercase letter:</p>
<form action="/action_page.php">
<label for="pwd">Password:</label>
<input type="password" id="pwd" name="pwd" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="Must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters">
<input type="submit">
</form>
</body>
</html>
The placeholder
attribute specifies a short hint that describes the expected value of an input field or a textarea.
The short hint is displayed in the field before the user enters a value.
The placeholder
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<input> | placeholder |
<textarea> | placeholder |
The placeholder
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The input placeholder attribute</h1>
<form action="/action_page.php">
<label for="phone">Enter a phone number:</label><br><br>
<input type="tel" id="phone" name="phone" placeholder="123-45-678" pattern="[0-9]{3}-[0-9]{2}-[0-9]{3}"><br><br>
<small>Format: 123-45-678</small><br><br>
<input type="submit">
</form>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The textarea placeholder attribute</h1>
Who are you?
<textarea rows="4" cols="50" placeholder="Describe yourself here..."></textarea>
</body>
</html>
The popover
attribute defines an element as a popover element, meaning that when it is invoked, it will be placed on top of the content, not interfere with the position of other HTML elements.
A popover element will be invisible until it is invoked by another element. The other element must have a popovertarget
attribute where the value refers to the popover element's id.
The popover element will be placed on top of all other content, and by clicking the popovertarget element, the popover element will toggle between showing and hiding:
The popover element can be a single HTML element, or an entire section of HTML elements. See examples below.
The popover
attribute is a Global Attribute, and can be used on any HTML element, but the element must be editable.
Element | Attribute |
---|---|
All HTML elements | popover |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The popover Attribute</h1>
<h1 popover id="myheader">Hello</h1>
<button popovertarget="myheader">Click me!</button>
<p>Click the button and it will toggle between showing and hiding the popover element.</p>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<style>
#mydiv {
text-align:center;
padding:40px;
background-color:lightblue;
font-family:"Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
</style>
<h1>The popover Attribute</h1>
<div popover id="mydiv">
<h2>Popover</h2>
<hr>
<p>A popover is an element that is placed on top of everything else.</p>
<p>It can be used when you want to tell something important.</p>
<button popovertarget="mydiv" popovertargetaction="hide">Close</button>
</div>
<button popovertarget="mydiv">Click me!</button>
<p>You can style popover elements with CSS.</p>
<p>Click the button to show the popover element.</p>
</body>
</html>
With the popovertarget
attribute you can refer to the popover element with the specified id, and toggle between showing and hiding it:
The popovertarget
only works when type="button".
The popovertarget
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<input> | popovertarget |
<button> | popovertarget |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The input popovertarget Attribute</h1>
<h1 popover id="myheader">Hello</h1>
<input type="button" popovertarget="myheader" value="Click me!">
<p>Click the button and it will toggle between showing and hiding the popover element.</p>
</body>
</html>
The popovertargetaction
attribute allows you to define what happens when you click the button.
You can choose between the values "show", "hide", and "toggle".
The popovertargetaction
only works when type="button".
If the popovertargetaction
attribute is not specified, the default "toggle" value will be used.
The popovertargetaction
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<input> | popovertargetaction |
<button> | popovertargetaction |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The input popovertargetaction Attribute</h1>
<h1 popover id="myheader">Hello</h1>
<input type="button" popovertarget="myheader" popovertargetaction="show" value="Show popover">
<p>Click the button and it will show the popover element.</p>
</body>
</html>
The poster
attribute specifies an image to be shown while the video is downloading, or until the user hits the play button. If this is not included, the first frame of the video will be used instead.
The poster
attribute can be used on the following element:
Elements | Attribute |
---|---|
<video> | poster |
The poster
attribute has the following browser support.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The video poster attribute</h1>
<video width="320" height="240" poster="https://horje.com/avatar.png" controls>
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_30mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_30mb.mp4" type="video/ogg">
Your browser does not support the video tag.
</video>
</body>
</html>
The preload
attribute specifies if and how the author thinks that the media file should be loaded when the page loads.
The preload
attribute allows the author to provide a hint to the browser about what he/she thinks will lead to the best user experience. This attribute may be ignored in some instances.
Note: The preload
attribute is ignored if autoplay is present.
The preload
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<audio> | preload |
<video> | preload |
The preload
attribute has the following browser support for each element.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The video preload attribute</h1>
<video width="320" height="240" controls preload="none">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_30mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_30mb.mp4" type="video/ogg">
Your browser does not support the video tag.
</video>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The audio preload attribute</h1>
<p>Click on the play button to play a sound:</p>
<audio controls preload="none">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/ogg">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</body>
</html>
The readonly
attribute is a boolean attribute.
When present, it specifies that an input field or textarea is read-only.
A read-only field cannot be modified (however, a user can tab to it, highlight it, and copy the text from it).
The readonly
attribute can be set to keep a user from changing the value until some other conditions have been met (like selecting a checkbox, etc.). Then, a JavaScript can remove the readonly value, and make the input field editable.
The readonly
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<input> | readonly |
<textarea> | readonly |
The readonly
attribute has the following browser support for each element.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The input readonly attribute</h1>
<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="country">Country:</label>
<input type="text" id="country" name="country" value="Norway" readonly><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The textarea readonly attribute</h1>
<textarea rows="4" cols="50" readonly>
At Horje.com you will learn how to make a website. We offer free tutorials in all web development technologies.
</textarea>
</body>
</html>
The rel
attribute specifies the relationship between the current document and the linked document/resource.
The rel
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<a> | rel |
<area> | rel |
<link> | rel |
<form> | rel |
The rel
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The a rel attribute</h1>
<p><a rel="nofollow" href="https://horje.com/">Horje.com</a></p>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The area rel attribute</h1>
<p>Click on the sun to watch it closer:</p>
<img src="https://horje.com/avatar.png" width="145" height="126" alt="Planets" usemap="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.htm" rel="alternate">
</map>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Hello World!</h1>
<h2>I am formatted with a linked style sheet.</h2>
<p>Me too!</p>
</body>
</html>
The required
attribute is a boolean attribute.
When present, it specifies that the element must be filled out before submitting the form.
The required
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<input> | required |
<select> | required |
<textarea> | required |
The required
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The input required attribute</h1>
<form action="/action_page.php">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<input type="submit">
</form>
</body>
</html>
Example:
HTML
<form action="/action_page.php">
<label for="cars">Choose a car:</label>
<select name="cars" id="cars" required>
<option value="">None</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<br><br>
<input type="submit" value="Submit">
</form>
Example:
HTML
<form action="/action_page.php">
<textarea rows="4" cols="50" name="comment" required>
</textarea>
<input type="submit">
</form>
The reversed
attribute is a boolean attribute.
When present, it specifies that the list order should be descending (9,8,7...), instead of ascending (1, 2, 3...).
The reversed
attribute can be used on the following element:
Element | Attribute |
---|---|
<ol> | reversed |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<ol reversed>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
The rows
attribute specifies the visible height of a text area, in lines.
Note: The size of a textarea can also be specified by the CSS height and width properties.
The rows
attribute can be used on the following element:
Element | Attribute |
---|---|
<textarea> | rows |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The textarea rows and cols attributes</h1>
<textarea rows="4" cols="50">
At Horje.com you will learn how to make a website. We offer free tutorials in all web development technologies.
</textarea>
<p>This textarea has 4 visible rows.</p>
<p>You can change that by changing the value of the "rows" attribute.</p>
</body>
</html>
The rowspan
attribute specifies the number of rows a cell should span.
The rowspan
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<td> | rowspan |
<th> | rowspan |
The rowspan
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<h1>The td rowspan attribute</h1>
<table>
<tr>
<th>Month</th>
<th>Savings</th>
<th>Savings for holiday!</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
<td rowspan="2">$50</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</table>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<h1>The th rowspan attribute</h1>
<table>
<tr>
<th>Month</th>
<th>Savings</th>
<th rowspan="3">Savings for holiday!</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</table>
</body>
</html
The sandbox
attribute enables an extra set of restrictions for the content in an iframe.
When the sandbox
attribute is present, and it will:
The value of the sandbox
attribute can either be just sandbox (then all restrictions are applied), or a space-separated list of pre-defined values that will REMOVE the particular restrictions.
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The iframe sandbox attribute</h1>
<iframe src="demo_iframe_sandbox.htm" sandbox>
<p>Your browser does not support iframes.</p>
</iframe>
<p>The "Get date and time" button will run a script in the inline frame.</p>
<p>Since the sandbox attribute is set, the content of the inline frame is not allowed to run scripts.</p>
<p>You can add "allow-scripts" to the sandbox attribute, to allow the JavaScript to run.</p>
</body>
</html>
The scope
attribute specifies whether a header cell is a header for a column, row, or group of columns or rows.
The scope
attribute has no visual effect in ordinary web browsers, but can be used by screen readers.
The scope
attribute can be used on the following element:
Element | Attribute |
---|---|
<th> | scope |
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<h1>The th scope attribute</h1>
<table>
<tr>
<th></th>
<th scope="col">Month</th>
<th scope="col">Savings</th>
</tr>
<tr>
<td>1</td>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>2</td>
<td>February</td>
<td>$80</td>
</tr>
</table>
</body>
</html>
The selected
attribute is a boolean attribute.
When present, it specifies that an option should be pre-selected when the page loads.
The pre-selected option will be displayed first in the drop-down list.
Tip: The selected
attribute can also be set after the page loads, with a JavaScript.
The selected
attribute can be used on the following element:
Element | Attribute |
---|---|
<option> | selected |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The option selected attribute</h1>
<label for="cars">Choose a car:</label>
<select id="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="vw">VW</option>
<option value="audi" selected>Audi</option>
</select>
</body>
</html>
The shape
attribute specifies the shape of an area.
The shape
attribute is used together with the coords
attribute to specify the size, shape, and placement of an area.
The shape
attribute can be used on the following element:
Element | Attribute |
---|---|
<area> | shape |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The map and area elements</h1>
<p>Click on the computer, the phone, or the cup of coffee to go to a new page and read more about the topic:</p>
<img src="https://horje.com/avatar.png" alt="Workplace" usemap="#workmap" width="400" height="379">
<map name="workmap">
<area shape="rect" coords="34,44,270,350" alt="Computer" href="computer.htm">
<area shape="rect" coords="290,172,333,250" alt="Phone" href="phone.htm">
<area shape="circle" coords="337,300,44" alt="Cup of coffee" href="coffee.htm">
</map>
</body>
</html>
For input elements, the size
attribute specifies the visible width, in characters, of an <input>
element.
For select elements, the size
attribute specifies the number of visible options in a drop-down list.
The size
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<input> | size |
<select> | size |
The size
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The input size attribute</h1>
<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname" size="50"><br><br>
<label for="pin">PIN:</label>
<input type="text" id="pin" name="pin" maxlength="4" size="4"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The select size attribute</h1>
<p>The size attribute specifies the number of visible options in a drop-down list:</p>
<form action="/action_page.php">
<label for="cars">Choose a car:</label>
<select id="cars" name="cars" size="3">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
The sizes
attribute specifies the sizes of icons for visual media.
This attribute is only used if rel="icon"
.
The sizes
attribute can be used on the following element:
Element | Attribute |
---|---|
<link> | sizes |
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="https://horje.com/avatar.png" type="image/png" sizes="16x16">
</head>
<body>
<h2>Hello world!</h2>
<p>Open this page in a <a href="https://horje.com" target="_blank">new window</a> to see the favicon.</p>
<p><b>Note:</b> The sizes attribute is not currently supported in any of the major browsers.</p>
</body>
</html>
The span
attribute defines the number of columns a <col>
or <colgroup>
element should span.
The span
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<col> | span |
<colgroup> | span |
The span
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<h1>The col element</h1>
<table>
<colgroup>
<col span="2" style="background-color:red">
<col style="background-color:yellow">
</colgroup>
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Price</th>
</tr>
<tr>
<td>3476896</td>
<td>My first HTML</td>
<td>$53</td>
</tr>
<tr>
<td>5869207</td>
<td>My first CSS</td>
<td>$49</td>
</tr>
</table>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<h1>The colgroup span attribute</h1>
<table>
<colgroup span="2" style="background:red"></colgroup>
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Price</th>
</tr>
<tr>
<td>3476896</td>
<td>My first HTML</td>
<td>$53</td>
</tr>
<tr>
<td>5869207</td>
<td>My first CSS</td>
<td>$49</td>
</tr>
</table>
</body>
</html>
The spellcheck
attribute specifies whether the element is to have its spelling and grammar checked or not.
The following can be spellchecked:
The spellcheck
attribute is part of the Global Attributes, and can be used on any HTML element.
Element | Attribute |
---|---|
All HTML elements | spellcheck |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<p contenteditable="true" spellcheck="true">This is a paragraph.</p>
The src
attribute specifies the location (URL) of the external resource.
The src
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<audio> | src |
<embed> | src |
<iframe> | src |
<img> | src |
<input> | src |
<script> | src |
<source> | src |
<track> | src |
<video> | src |
The src
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The audio src attribute</h1>
<p>Click on the play button to play a sound:</p>
<audio src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" controls>
Your browser does not support the audio element.
</audio>
<p><b>Note:</b> The .ogg fileformat is not supported in IE or Safari.</p>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The embed src attribute</h1>
<embed src="https://horje.com/avatar.png">
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The iframe src attribute</h1>
<iframe src="https://horje.com">
<p>Your browser does not support iframes.</p>
</iframe>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The img element</h1>
<img src="https://horje.com/avatar.png" alt="Girl in a jacket" width="500" height="600">
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The input src attribute</h1>
<p>Click on the image, and the input will be sent to a page on the server called "/action_page.php".</p>
<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<input type="image" src="https://horje.com/avatar.png" alt="Submit" width="48" height="48">
</form>
<p><b>Note:</b> The image input type sends the X and Y coordinates of the click that activated the image button as default.</p>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The script src attribute</h1>
<script src="demo_script_src.js">
</script>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The source element</h1>
<p>Click on the play button to play a sound:</p>
<audio controls>
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/ogg">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</body>
</html>
Example:
HTML
<video width="320" height="240" controls>
<source src="https://www.sample-videos.com/video321/mp4/360/big_buck_bunny_360p_10mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/360/big_buck_bunny_360p_10mb.mp4" type="video/ogg">
<track src="subtitles_en.vtt" kind="subtitles" srclang="en" label="English">
<track src="subtitles_no.vtt" kind="subtitles" srclang="no" label="Norwegian">
</video>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The video src attribute</h1>
<video width="320" height="240" controls src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_30mb.mp4">
Your browser does not support the video tag.
</video>
<p><b>Note:</b> The .ogg fileformat is not supported in old IE and Safari.</p>
</body>
</html>
The srcdoc
attribute specifies the HTML content of the page to show in the inline frame.
Tip: This attribute is expected to be used together with the sandbox
and seamless
attributes.
If a browser supports the srcdoc
attribute, it will override the content specified in the src
attribute (if present).
If a browser does NOT support the srcdoc
attribute, it will show the file specified in the src
attribute instead (if present).
The srcdoc
attribute can be used on the following element:
Element | Attribute |
---|---|
<iframe> | srcdoc |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The iframe srcdoc attribute</h1>
<iframe srcdoc="<p>Hello world!</p>" src="https://horje.com">
<p>Your browser does not support iframes.</p>
</iframe>
</body>
</html>
The srclang
attribute specifies the language of the track text data.
This attribute is required if kind="subtitles"
.
Tip: To view all available language codes, go to our Language code reference.
The srclang
attribute can be used on the following element:
Element | Attribute |
---|---|
<track> | srclang |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<video width="320" height="240" controls>
<source src="forrest_gump.mp4" type="video/mp4">
<source src="forrest_gump.ogg" type="video/ogg">
<track src="subtitles_en.vtt" kind="subtitles" srclang="en" label="English">
<track src="subtitles_no.vtt" kind="subtitles" srclang="no" label="Norwegian">
</video>
The srcset
attribute specifies the URL of the image to use in different situations.
This attribute is required when <source>
is used in <picture>
.
The numbers in the table specify the first browser version that fully supports the attribute.
<source srcset="URL">
Value | Description |
---|---|
URL | Specifies the URL of the image.
Possible values:
|
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>The picture element</h1>
<p>Resize the browser window to load different images.</p>
<picture>
<source media="(min-width:650px)" srcset="https://horje.com/avatar.png">
<source media="(min-width:465px)" srcset="https://horje.com/avatar.png">
<img src="https://horje.com/avatar.png" alt="Flowers" style="width:auto;">
</picture>
</body>
</html>
The start
attribute specifies the start value of the first list item in an ordered list.
The start
attribute can be used on the following element:
Element | Attribute |
---|---|
<ol> | start |
Example:
HTML
<ol start="50">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
The step
attribute specifies the legal number intervals for an <input>
element.
Example: if step="3"
, legal numbers could be -3, 0, 3, 6, etc.
Tip: The step
attribute can be used together with the max
and min
attributes to create a range of legal values.
Note: The step
attribute works with the following input types: number, range, date, datetime, datetime-local, month, time and week.
The step
attribute can be used on the following element:
Element | Attribute |
---|---|
<input> | step |
The numbers in the table specify the first browser version that fully supports the attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The input step attribute</h1>
<form action="/action_page.php">
<label for="points">Points:</label>
<input type="number" id="points" name="points" step="3">
<input type="submit">
</form>
</body>
</html>
The style
attribute specifies an inline style for an element.
The style
attribute will override any style set globally, e.g. styles specified in the <style>
tag or in an external style sheet.
The style
attribute is part of the Global Attributes, and can be used on any HTML element.
Element | Attribute |
---|---|
All HTML elements | style |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1 style="color:blue;text-align:center;">This is a header</h1>
<p style="color:green;">This is a paragraph.</p>
</body>
</html>
The tabindex
attribute specifies the tab order of an element (when the "tab" button is used for navigating).
The tabindex
attribute is part of the Global Attributes, and can be used on any HTML element.
Element | Attribute |
---|---|
All HTML elements | tabindex |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<div tabindex="1">Horje</div><br>
<div tabindex="3">Google</div><br>
<div tabindex="2">Microsoft</div>
<script>
// At start, set focus on the first div
document.getElementsByTagName('div')[0].focus();
</script>
<p tabindex="4"><b>Note:</b> Try navigating the elements by using the "Tab" button on your keyboard.</p>
</body>
</html>
For <a>
and <area>
elements, the target
attribute specifies where to open the linked document.
For <base>
elements, the target
attribute specifies the default target for all hyperlinks and forms in the page.
For <form>
elements, the target
attribute specifies a name or a keyword that indicates where to display the response that is received after submitting the form.
The target
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<a> | target |
<area> | target |
<base> | target |
<form> | target |
The target
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The a target attribute</h1>
<p>Open link in a new window or tab: <a href="https://horje.com" target="_blank">Visit Horje!</a></p>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The area target attribute</h1>
<p>Click on the sun or on one of the planets to watch it closer:</p>
<img src="https://horje.com/avatar.png" width="145" height="126" alt="Planets" usemap="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.htm" target="_blank">
<area shape="circle" coords="90,58,3" alt="Mercury" href="mercur.htm">
<area shape="circle" coords="124,58,8" alt="Venus" href="venus.htm">
</map>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<base target="_blank">
</head>
<body>
<h1>The base target attribute</h1>
<p><a href="https://horje.com">Horje</a> - Notice that the link opens in a new window, even if it has no target="_blank" attribute. This is because the target attribute of the base element is set to "_blank".</p>
</body>
</html>
Example:
HTML
<form action="/action_page.php" method="get" target="_blank">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit">
</form>
The title
attribute specifies extra information about an element.
The information is most often shown as a tooltip text when the mouse moves over the element.
The title
attribute is part of the Global Attributes, and can be used on any HTML element.
Element | Attribute |
---|---|
All HTML elements | title |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p><abbr title="World Health Organization">WHO</abbr> was founded in 2011.</p>
<p title="Free Web tutorials">Horje.com</p>
</body>
</html>
The translate
attribute specifies whether the content of an element should be translated or not.
Test: Use the Google translate box (at the top of the page) to change to another language, and look what happens to the word "ice cream" below:
Here we use translate="no": ice cream.
Here we use class="notranslate": ice cream.
Tip: Use class="notranslate" instead.
The translate
attribute is part of the Global Attributes, and can be used on any HTML element.
Element | Attribute |
---|---|
All HTML elements | translate |
Example:
HTML
<p translate="no">Don't translate this!</p>
<p>This can be translated to any language.</p>
For <button>
elements, the type
attribute specifies the type of button.
For <input>
elements, the type
attribute specifies the type of <input> element to display.
For <embed>
, <link>
, <object>
, <script>
, <source>
, and <style>
elements, the type
attribute specifies the Internet media type (formerly known as MIME type).
The type
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<a> | type |
<button> | type |
<embed> | type |
<input> | type |
<link> | type |
<menu> | type |
<object> | type |
<script> | type |
<source> | type |
<style> | type |
The type
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The button type attribute</h1>
<form action="/action_page.php" method="get">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<button type="submit" value="Submit">Submit</button>
<button type="reset" value="Reset">Reset</button>
</form>
</body>
</html>
Embed Example.
Example:
HTML
<embed type="image/jpg" src="https://horje.com/avatar.png">
Input Example.
Example:
HTML
<form action="/action_page.php">
<label for="username">Username: </label>
<input type="text" id="username" name="username"><br>
<input type="submit" value="Submit">
</form>
Link Example.
Example:
HTML
<head>
<link rel="stylesheet" type="text/css" href="theme.css">
</head>
The object type attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The object type attribute</h1>
<object data="https://horje.com/avatar.png" type="image/jpg" width="500" height="300">
</object>
</body>
</html>
The script type attribute.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The script type attribute</h1>
<p id="demo"></p>
<script type="text/javascript">
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
</body>
</html>
Source Example.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The source type attribute</h1>
<audio controls>
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_5MG.mp3" type="audio/ogg">
<source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_5MG.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</body>
</html>
Style of This is a heading This is a paragraph.
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<style>
h1 {color:red;}
p {color:blue;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
The usemap
attribute specifies an image (or an object) as an image map (an image map is an image with clickable areas).
The usemap
attribute is associated with a <map>
element's name or id
attribute, and creates a relationship between the <img>
and the <map>
.
Note: The usemap
attribute cannot be used if the <img>
element is a descendant of an <a>
or <button>
element.
The usemap
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<img> | usemap |
<object> | usemap |
The usemap
attribute has the following browser support for each element:
Example:
HTML
<img src="planets.gif" width="145" height="126" alt="Planets" usemap="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun">
<area shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury">
<area shape="circle" coords="124,58,8" href="venus.htm" alt="Venus">
</map>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The object usemap attribute</h1>
<object data="https://horje.com/avatar.png" width="145" height="126" usemap="#planetmap"></object>
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.htm">
<area shape="circle" coords="90,58,3" alt="Mercury" href="mercur.htm">
<area shape="circle" coords="124,58,8" alt="Venus" href="venus.htm">
</map>
<p><b>Note:</b> The usemap attribute of the object element is not supported in Chrome,
Edge, Safari, and Opera.</p>
</body>
</html>
For <button>
, <input>
and <option>
elements, the value
attribute specifies the initial value of the element.
For <li>
elements, the value
attribute sets the value of the list item (for ordered lists). The next list items will increment from that value.
For <meter>
elements, the value
attribute specifies the current value of the gauge.
For <progress>
elements, the value
attribute specifies how much of the task has been completed.
For <param>
elements, the value
attribute specifies the value of the parameter.
The value
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<button> | value |
<input> | value |
<meter> | value |
<li> | value |
<option> | value |
<progress> | value |
<param> | value |
The value
attribute has the following browser support for each element:
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The button value attribute</h1>
<form action="/action_page.php" method="get">
Choose your favorite subject:
<button name="subject" type="submit" value="fav_HTML">HTML</button>
<button name="subject" type="submit" value="fav_CSS">CSS</button>
</form>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The input value attribute</h1>
<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname" value="John"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The input value attribute</h1>
<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname" value="John"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Example:
HTML
<ol>
<li value="100">Coffee</li>
<li>Tea</li>
<li>Milk</li>
<li>Water</li>
<li>Juice</li>
<li>Beer</li>
</ol>
Example:
HTML
<meter min="0" low="40" high="90" max="100" value="95"></meter>
Example:
HTML
<form action="/action_page.php">
<select name="cars">
<option value="volvo">Volvo XC90</option>
<option value="saab">Saab 95</option>
<option value="mercedes">Mercedes SLK</option>
<option value="audi">Audi TT</option>
</select>
<input type="submit" value="Submit">
</form>
Example:
HTML
<progress value="22" max="100"></progress>
Example:
HTML
<object data="horse.wav">
<param name="autoplay" value="true">
</object>
The width
attribute specifies the width of the element, in pixels.
Note: For input elements, the width
attribute is used only with <input type="image">
.
The width
attribute can be used on the following elements:
Elements | Attribute |
---|---|
<canvas> | width |
<embed> | width |
<iframe> | width |
<img> | width |
<input> | width |
<object> | width |
<video> | width |
The width
attribute has the following browser support for each element:
Example:
HTML
<canvas id="myCanvas" width="200" height="200" style="border:1px solid">
Example:
HTML
<embed src="helloworld.swf" width="200" height="200">
Example:
HTML
<iframe src="https://horje.com" width="200" height="200">
<p>Your browser does not support iframes.</p>
</iframe>
Example:
HTML
<img src="https://horje.com/avatar.png" alt="Girl in a jacket" width="500" height="600">
Example:
HTML
<form action="/action_page.php">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="image" src="img_submit.gif" alt="Submit" width="48" height="48">
</form>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The object element</h1>
<object data="https://horje.com/avatar.png" width="300" height="200"></object>
</body>
</html>
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The video width and height attributes</h1>
<video width="320" height="240" controls>
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_20mb.mp4" type="video/mp4">
<source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_20mb.mp4" type="video/ogg">
Your browser does not support the video tag.
</video>
</body>
</html>
The wrap
attribute specifies how the text in a text area is to be wrapped when submitted in a form.
The wrap
attribute can be used on the following element:
Element | Attribute |
---|---|
<textarea> | wrap |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<h1>The textarea wrap attribute</h1>
<form action="/action_page.php">
<textarea rows="2" cols="20" name="usrtxt" wrap="hard">
At Horje you will find free Web-building tutorials.
</textarea>
<input type="submit">
</form>
</body>
</html>